• 🏆 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!

Increase attack range

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
See below - this is a cutout from the full trigger that is the same setup just for different trait bonuses.

The Ranger Bonus ability is added and everything so I know that bit works it's just the range that doesn't... The idea is that it should add 10% range per 3 Ranger units (up to 50%/15 Rangers)

  • Apply Trait Bonuses
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Trait: Ranger for TempUnit) Greater than or equal to 1
          • (Number of units in TraitGroup_Ranger[TempInt]) Greater than or equal to 3
        • Then - Actions
          • Unit - Add Ranger Bonus (atk spd) to TempUnit
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TraitGroup_Ranger[TempInt]) Less than 15
            • Then - Actions
              • Unit - Set level of Trait: Ranger for TempUnit to (1 + ((Number of units in TraitGroup_Ranger[TempInt]) / 3))
              • Unit - Set level of Ranger Bonus (atk spd) for TempUnit to ((Number of units in TraitGroup_Ranger[TempInt]) / 3)
              • Unit - Set Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: ((Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:1) x (1.00 + (0.10 x (Real(((Number of units in TraitGroup_Ranger[TempInt]) / 3))))))
            • Else - Actions
              • Unit - Set level of Trait: Ranger for TempUnit to 6
              • Unit - Set level of Ranger Bonus (atk spd) for TempUnit to 5
              • Unit - Set Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m')at Index:1 to Value: ((Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:1) x 1.50)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:1) Greater than (Current acquisition range of TempUnit)
            • Then - Actions
              • Unit - Set Unit: TempUnit's Real Field: Acquisition Range ('uacq') to Value: (Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:1)
            • Else - Actions
        • Else - Actions
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
Change the Index to 0. These new "Field" functions are all Indexed starting at 0.

So 0 = Weapon 1, 1 = Weapon 2.

And for ability levels: 0 = Level 1, 1 = Level 2, etc...

If it still doesn't working after fixing the Indexes then also try adjusting the unit's acquisition range.
 
Level 13
Joined
Oct 16, 2010
Messages
731
I did try Index at 0 first and that didn't work

Just tried again and still not working, I have added a TempReal to calculate the range and change the acquisition range before the range and that hasn't worked either

  • Apply Trait Bonuses
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Trait: Ranger for TempUnit) Greater than or equal to 1
          • (Number of units in TraitGroup_Ranger[TempInt]) Greater than or equal to 3
        • Then - Actions
          • Unit - Add Ranger Bonus (atk spd) to TempUnit
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in TraitGroup_Ranger[TempInt]) Less than 15
            • Then - Actions
              • Unit - Set level of Trait: Ranger for TempUnit to (1 + ((Number of units in TraitGroup_Ranger[TempInt]) / 3))
              • Unit - Set level of Ranger Bonus (atk spd) for TempUnit to ((Number of units in TraitGroup_Ranger[TempInt]) / 3)
              • Set VariableSet TempReal = ((Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:0) x (1.00 + (Real(((Number of units in TraitGroup_Ranger[TempInt]) / 3)))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempReal Greater than (Current acquisition range of TempUnit)
                • Then - Actions
                  • Unit - Set Unit: TempUnit's Real Field: Acquisition Range ('uacq') to Value: TempReal
                • Else - Actions
              • Unit - Set Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: TempReal
            • Else - Actions
              • Unit - Set level of Trait: Ranger for TempUnit to 6
              • Unit - Set level of Ranger Bonus (atk spd) for TempUnit to 5
              • Set VariableSet TempReal = ((Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m') at Index:0) x 1.50)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempReal Greater than (Current acquisition range of TempUnit)
                • Then - Actions
                  • Unit - Set Unit: TempUnit's Real Field: Acquisition Range ('uacq') to Value: TempReal
                • Else - Actions
              • Unit - Set Unit: TempUnit's Weapon Real Field: Attack Range ('ua1m')at Index:0 to Value: TempReal
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
Hmm, maybe something else is the issue? Can you confirm that these Actions are running?

I've done this in my map and it worked fine:
vJASS:
call SetUnitAcquireRange(unit, 2000)
call BlzSetUnitWeaponRealField(unit, UNIT_WEAPON_RF_ATTACK_RANGE, 0, 2000)
call BlzSetUnitWeaponRealField(unit, UNIT_WEAPON_RF_ATTACK_RANGE, 1, 2000)
Maybe you need to use Custom script?
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
They are receiving the attack speed buff so I believe it is all working?

What would the custom script need to be? with the unit being TempUnit and the new range being TempReal?
  • Custom script: call SetUnitAcquireRange(udg_TempUnit, 2000)
  • Custom script: call BlzSetUnitWeaponRealField(udg_TempUnit, UNIT_WEAPON_RF_ATTACK_RANGE, 0, udg_TempReal)
  • Custom script: call BlzSetUnitWeaponRealField(udg_TempUnit, UNIT_WEAPON_RF_ATTACK_RANGE, 1, udg_TempReal)
 
Level 13
Joined
Oct 16, 2010
Messages
731
OK no it doesn't quite work, TempReal is being calculated correctly but the ranges are being added together rather than replaced?

Example - unit with 500 range should be getting 10% bonus, 550 is being calculated (shown with test text) but the unit ends up with 1050 range? (500 + 550)

Any ideas?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
OK no it doesn't quite work, TempReal is being calculated correctly but the ranges are being added together rather than replaced?

Example - unit with 500 range should be getting 10% bonus, 550 is being calculated (shown with test text) but the unit ends up with 1050 range? (500 + 550)

Any ideas?
You can try to set it's attack range to 0 or something before applying TempReal.

Also, look at how you're calculating TempReal. You're taking the CURRENT attack range and multiplying it.

First time: 500 * 1.1 = 550
Second time: 550 * 1.1 = 605
Third time: 650 * 1.1 = 715
etc...

The CURRENT attack range shouldn't be used, instead use the Base attack range.

Also, for efficiency sake, I recommend storing the (Number of units in TraitGroup_Ranger) into an Integer variable at the start of the trigger and referencing that throughout.
 
Last edited:
Level 13
Joined
Oct 16, 2010
Messages
731
The fix I have done is that TempReal calculates the bonus not the total, this seems to have worked

As it's a round based game with duplicate units involved this shouldn't be recalculated at any time, but could be worth looking into anyway...what function would pick up the base attack range?

And yes you are correct I should definitely make a tempary count variable!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
The fix I have done is that TempReal calculates the bonus not the total, this seems to have worked

As it's a round based game with duplicate units involved this shouldn't be recalculated at any time, but could be worth looking into anyway...what function would pick up the base attack range?

And yes you are correct I should definitely make a tempary count variable!
I don't think there is a function. But you can always use a Variable/Hashtable to store this information if you can't get away with typing the exact value yourself.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
Ahh no worries I will go with how it is for now, may have to revisit if it doesn't work further down the line.

Thanks for all your help though :)
No problem. Do the TempUnit's have different attack ranges or something? What's stopping you from just doing this:
  • Set VariableSet TempReal = 500.00 x (1.00 + (Real(((Number of units in TraitGroup_Ranger[TempInt]) / 3)))))
 
Level 13
Joined
Oct 16, 2010
Messages
731
Yes I've only made two with the Ranger trait and they both have different ranges, so I wanted it to be universal

It's also possible that I will make it possible to give other units this trait too so yeah

It works for what I want so I'm happy!
 
Level 13
Joined
Oct 16, 2010
Messages
731
@Uncle

So for some reason this doesn't work on a unit with 800 range? It is setting them to have melee range? Any ideas?

I have tried deleting the line where it adjusts the aquisition range and that wasn't the problem... all the other units still work just this one!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,538
@Uncle

So for some reason this doesn't work on a unit with 800 range? It is setting them to have melee range? Any ideas?

I have tried deleting the line where it adjusts the aquisition range and that wasn't the problem... all the other units still work just this one!
No idea, Blizzard released these functions in 1.31 and then never touched them since. A lot are buggy/unfinished.
 
Level 13
Joined
Oct 16, 2010
Messages
731
So I don't know why this works, but the unit didn't work with was based on a mortar team. I have copied a rifleman and basically turned it into a mortar team... and that seems to have done the trick??

I guess something in the setup of a mortar team doesn't work with this? It's not the minimum attack range as I have added this back onto the new unit and it seems to work correctly still
 
Status
Not open for further replies.
Top