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

How to get a unit's attack range

Status
Not open for further replies.
  • Cant Attack Above
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set TempPoint[1] = (Position of (Attacking unit))
      • Set TempPoint[2] = (Position of (Attacked unit))
      • Custom script: set udg_TempReal[1] = GetLocationZ(udg_TempPoint[1])
      • Custom script: set udg_TempReal[2] = GetLocationZ(udg_TempPoint[2])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Range of ((Attacking unit) Greater than ((Current flying height of (Attacking unit)) - (Current flying height of (Attacked unit)) + (TempReal[1]))
          • Or - Any (Conditions) are true
            • Conditions
              • TempReal[1] Greater than (TempReal[2] + (100.00 + (Current flying height of (Attacked unit))))
              • TempReal[2] Greater than (TempReal[1] + (100.00 + (Current flying height of (Attacking unit))))
              • TempReal[1] Less than (TempReal[2] + (-100.00 + (Current flying height of (Attacked unit))))
              • TempReal[2] Less than (TempReal[1] + (-100.00 + (Current flying height of (Attacking unit))))
        • Then - Actions
          • Unit - Order (Attacking unit) to Stop
        • Else - Actions
      • Custom script: call RemoveLocation(udg_TempPoint[1])
      • Custom script: call RemoveLocation(udg_TempPoint[2])
This is like how I'd want it to look, unfortunately there is no real way to find a unit's attack range.. Is there?
(Excluding setting a unit's attack range to a variable)
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
This is like how I'd want it to look, unfortunately there is no real way to find a unit's attack range.. Is there?

Well, there is one way ;o. You could put a copy of the unit at the edge of the map under the owner of the unit and make it attack a target x away. Keep moving it closer until the order returns true. It sucks, but it's the only way. Movement on the unit must be disabled for this to work.

You will have to continue to do this to ensure accurate readings as attack range can be changed by a multitude of things, and the target also matters (must be the same target as the current target you're checking for or w/e). Remember that different attacks are enabled for different things.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If you use the BonusMod library you could potentially keep track of all attack speed bonuses yourself. Then you could just use a table or something simple to maintain the attack speed of a unit. Then it would be as quick as an array reference.

For example, you know the Footman has an attack speed of say, 1.6, you can label that real in a table and increment it whenever you use BonusMod to increment attack speed. Then you'd have a variable reference to the unit's attack speed value. I did something similar to this with unit-sight to obtain values of unit sight.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I would first like to say that in my previous post I was talking about attack rate, but all of the logic applies to attack range as well.

but you'd have to hardcode a lot of stuff from tech upgrades to abilities to items to etc.

Yea you would have to control all of the attack-range modifying in the game and be sure to update values accordingly. It wouldn't really be that difficult it may take an hour or so to get working but that is a small price to pay for the functionality. It would be far more efficient than creating a unit in an "invisible zone" and slowly moving it towards another unit to test (inaccurately) for the unit's attack-range.
 
I was thinking about doing it the hard way... (Through upgrades and setting variables to the upgrade level and such) But now that I think of it, I think it seems too messy to have to have it apply to over 100 units. Thanks for all your time guys, but the invisible unit moving forward to find range might be the best thing for this situation here.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Yea you're going to run into a lot more complications by using a dummy "range tester" unit every time you want to determine the attack-range of a unit. Why not simply use a table that's maintained and kept up to date? It's not much work and it is far more resource-friendly.

I suppose if you needed any help implementing a table that maintains accurate attack-range values you could post back here with questions.
 
Last edited:
Status
Not open for further replies.
Top