How to make Weapon (Item) changing attack type (melee to ranged)?

Status
Not open for further replies.
Level 9
Joined
Mar 28, 2008
Messages
476
Making an RPG-style map with different weapon types. I'm wanting the weapons to alter the hero's attack type. Like equipping a sword item will give it a melee attack, and giving it a bow will give it a ranged attack. How would I do this?

Also is it possible to use different attack animations for each weapon/attack type (if the model has different attack animations)?
 
Level 12
Joined
May 29, 2008
Messages
149
If you want to change the attack range of a unit, you can use the native BlzSetUnitWeaponRealField(UNIT_WEAPON_RF_ATTACK_RANGE). This allows you to set the weapon range to any value. In general, most characteristics of a unit's attack can be modified with the set unit weapon field natives.

Some issues I've found with the set real field native on attack range though:
  • It actually doesn't set the range, instead it adds to the range. You'll need to get the current range of the unit (using BlzGetUnitWeaponRealField) and find the difference between the current range and the desired range, passing it to the set call.
  • You also need to set the unit's acquire range to be >= the new attack range.
 
Level 25
Joined
Mar 29, 2020
Messages
1,466
If you want to change the attack range of a unit, you can use the native BlzSetUnitWeaponRealField(UNIT_WEAPON_RF_ATTACK_RANGE). This allows you to set the weapon range to any value. In general, most characteristics of a unit's attack can be modified with the set unit weapon field natives.

Some issues I've found with the set real field native on attack range though:
  • It actually doesn't set the range, instead it adds to the range. You'll need to get the current range of the unit (using BlzGetUnitWeaponRealField) and find the difference between the current range and the desired range, passing it to the set call.
  • You also need to set the unit's acquire range to be >= the new attack range.
is there a way to switch from direct attack to a missile attack with these natives?
 
Level 9
Joined
Mar 28, 2008
Messages
476
You can use the BlzSetUnitWeaponIntegerField(UNIT_WEAPON_IF_ATTACK_ATTACK_TYPE) to set the attack type. I think these are available in GUI as well, with similar names for units.
I'm still a bit of a noob with the editor. Is this a variable or something? I'm not sure how to use this info.
 
Level 9
Joined
Mar 28, 2008
Messages
476
In GUI, it would look something like this for attack range
  • Unit - Set Unit: (Triggering unit)'s Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: 600.00
Thank you.
As for animation, for example if I have a bow animation and a rifle animation on the same model, what's the best way for switching between these animations? I only want these animations while specific items are equipped.
 
Thank you.
As for animation, for example if I have a bow animation and a rifle animation on the same model, what's the best way for switching between these animations? I only want these animations while specific items are equipped.
If they come from the same model and have unique tag for all animation set, you can change the animation tag.
 
Status
Not open for further replies.
Top