• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Ranged Melee Spear item

Status
Not open for further replies.
Level 4
Joined
May 24, 2017
Messages
93
I want to make a Spear item that allows a melee unit to attack over a Barricade. The Barricade has 16 collision and the 2x2 pathing map so it takes 1 block up. When the hero builds the Barricade, I then want hit to be able to attack the units that are attacking the Barricade, from the safe side of it.

I was thinking of making the spear based off orb ability and activating 2 attack for hero with more range. Would this work best or is there a better idea?

I tested the 127 attack range and It allows my unit to attack units over the Barricade.

How does the orb enable attack 2 and disable attack 1? Is this possible?
 
Last edited:
Level 21
Joined
Dec 4, 2007
Messages
1,478
I haven't tried this thoroughly myself, but i think you can swap attacks easily with the orb items (like orb of fire).

1. Your base unit should have both attacks disabled.
2. create 2-3 orb abilities - where a) only attack 1 enabled b) only attack 2 enabled c) enable both attacks

Then interchange those abilities via triggers how you see fit.
 
Level 4
Joined
May 24, 2017
Messages
93
Thank you, I figured that out after some research and testing. The spear item enabled the second attack and trigger's enabled/disabled the first attack.

I did have one questions though, Is there a way to show which attack is enabled? When I use my system, It attacks but it does not show the damage panel in the command card. Is this something to do with orbs and deabling attack?
 
Level 5
Joined
Jul 31, 2020
Messages
103
I personally would not bother with annoying orb abilities, and would just change the unit's attack range if you tested how much it has to be in order for it to have the effect you're seeking. Now, this is going to sound extremely weird, but bear with me as the reason I have this information is because I actually tested this already. Contrary to popular belief, you can change the attack range of a unit without any orb shenanigans, using the new natives from 1.31. The weird part comes now because it doesn't work the way it should whatsoever.

This one adds 100 to the attack range of attack index 1 in the object editor of the unit:
vJASS:
call BlzSetUnitWeaponRealField(unit, ConvertUnitWeaponRealField('ua1r'), 1, 100.0)
That's right, it adds this value to the attack range. It does not set anything explicitly. If the unit had 600 attack range to begin with, now it has 700. And yes, the indexing is 1-based. Attack index 1 in the object editor is attack index 1 for this native.

Similarly, this one subtracts 100 at attack index 1:
vJASS:
call BlzSetUnitWeaponRealField(unit, ConvertUnitWeaponRealField('ua1r'), 1, -100.0)

Using this, you can set the attack range to whatever you wish it to be, without messing around with whoever knows how many different janky orb abilities. You just have to know what is the value you want to add, and then subtract from the unit's attack range.

And, of course, how do you get this value back? Now, this is no longer 1-indexed, this goes back to 0-based indexing again, so attack index 1 in the object editor is index 0 here:
vJASS:
call DisplayTextToPlayer(GetLocalPlayer(), 0.00, 0.00, R2S(BlzGetUnitWeaponRealField(unit, ConvertUnitWeaponRealField('ua1r'), 0)))
This will print the unit's current attack range.
 
Level 4
Joined
May 24, 2017
Messages
93
Ok, this is great. I personally don't use Jass so I am going to post my triggers. The only issue I can see right now is that I don't know how to reference the unit that gets and losses the item. Please redo my triggers to they work and I will be very happy that this exists.

  • Spear get
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Spear
    • Actions
      • Unit - Remove Attack 1 from (Triggering unit)
  • Spear remove
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Spear
    • Actions
      • Unit - Add Attack 1 to (Triggering unit)
I would have to replace the add and remove ability actions and replace them with your codes. Can you write the codes to target the unit which drops the item and picks it up? Thank you. I understand where the attack index and range change is.
 
Level 5
Joined
Jul 31, 2020
Messages
103
  • Spear get
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Spear
    • Actions
      • Custom script: call BlzSetUnitWeaponRealField(GetTriggerUnit(), ConvertUnitWeaponRealField('ua1r'), 1, 1234.0)
  • Spear remove
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Spear
    • Actions
      • Custom script: call BlzSetUnitWeaponRealField(GetTriggerUnit(), ConvertUnitWeaponRealField('ua1r'), 1, -1234.0)
 
Status
Not open for further replies.
Top