• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Editor Bad Math

Level 5
Joined
May 24, 2017
Messages
41
Ok, I'm doing the most basic hero ability. Increase attack range.
Here's my trigger, supper basic.

  • Unit - A unit Learns a skill
  • (Learned Hero Skill) Equal to Reinforced Crossbow
  • Unit - Set Unit: (Learning Hero)'s Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: (500.00 + (200.00 x (Real((Level of Reinforced Crossbow for (Learning Hero))))))
However, in game, it doesn't return the values 700 for lvl 1, 900 for lvl 2 and 1100 for level 3. Instead it's giving me 700 / 1100 / 1700. I don't understand, is something wrong with my math? 500+(200*(level))

Why is it behaving like level 2 is level 3 and level 3 is level 6?
 
Your math is correct. It is actually just a bug with that function when assigning an attack range for a unit where it will "add" the range minus the difference between the ranges at weapon indexes 1 and 2. Here is a thread that explains the quirks a bit:

To fix this, you need to sorta reverse the calculation. That's where this handy function comes into play:
JASS:
function SetUnitAttackRange takes unit u, real newRange returns nothing
    local real attackRange0 = BlzGetUnitWeaponRealField(u, UNIT_WEAPON_RF_ATTACK_RANGE, 0)
    local real attackRange1 = BlzGetUnitWeaponRealField(u, UNIT_WEAPON_RF_ATTACK_RANGE, 1)
    call BlzSetUnitWeaponRealFieldBJ(u, UNIT_WEAPON_RF_ATTACK_RANGE, 1, newRange - attackRange0 + attackRange1)
endfunction

You can copy and paste that script into your map header, which is accessible by selecting the map's name in the trigger editor:
1755762049112.png


Then in your trigger, you can use it like in the trigger below. I recommend using a variable (e.g. RC_Range) so that you can easily write the range in GUI and just reference that variable in the custom script:
  • Reinforced Crossbow Learn
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • (Learned Hero Skill) Equal to Reinforced Crossbow
    • Actions
      • Set VariableSet RC_Range = (500.00 + (200.00 x (Real((Level of Reinforced Crossbow for (Triggering unit))))))
      • Custom script: call SetUnitAttackRange(GetTriggerUnit(), udg_RC_Range)
 

Attachments

Back
Top