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

How do you find the range between units?

Status
Not open for further replies.
Level 2
Joined
Apr 12, 2009
Messages
16
Okay so, my question is How do you find the range between units? When you look at a units attack it usually says some range, a rifleman's range is 550 or something like that. what is it measuring? how far is 100? Could someone tell me how to measure this out or how far it is?
 
Level 9
Joined
Oct 7, 2007
Messages
599
I THINK (though you should correct me if I'm wrong) that it's pixels or something of that variety. I go by screenlengths as a measurement; it becomes more intuitive over time. 500 is almost a third of a screen across, so 550 is a bit more than that. It really also depends on the resolution you're using.
 
Level 13
Joined
Mar 4, 2009
Messages
1,156
Okay so, my question is How do you find the range between units? When you look at a units attack it usually says some range, a rifleman's range is 550 or something like that. what is it measuring? how far is 100? Could someone tell me how to measure this out or how far it is?
you can see it if you use spell (for example silence) put its area effect to some range and in warcraft you will see how much that range is when you will want to cast silence
 
Level 16
Joined
Jul 21, 2008
Messages
1,121
You can try it with this triggers. If you use GUI you will like this:

  • -------- For this you will need 2 point variables --------
  • -------- You will need them to avoid leaks --------
  • -------- Set positions of your 2 units in those variables like this: --------
  • Set p1 = (Position of <YourUnit1>)
  • Set p2 = (Position of <YourUnit2>)
  • -------- To calculate the distance we use this simple function --------
  • -------- You can also store it in some real variable --------
  • Set r = (Distance between p1 and p2)
  • -------- Function used above is Math - Distance between points --------
  • -------- It is time to remove leaks caused by point variable --------
  • Custom script: call RemoveLocation(udg_p1)
  • Custom script: call RemoveLocation(udg_p2)
If you like JASS, try this:
JASS:
function GetDistance takes unit u1, unit u2 returns real
// This is a simple function which returns distance between 2 units
// You can even call it from GUI if you copy it into your map's custom script
    local real x1 = GetUnitX(u1)
    local real y1 = GetUnitY(u1)
    local real x2 = GetUnitX(u2)
    local real y2 = GetUnitY(u2)
    local real r = SquareRoot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
    return r            
endfunction

function Call takes nothing returns nothing
// Here is the example of JASS call
// It can be a trigger action
    local unit u1 = <SomeUnit1>
    local unit u2 = <SomeUnit2> 
    local real distance
// ...    
    set distance = GetDistance(u1, u2)
// Function below writes distance to the screen
    call BJDebugMsg(R2S(distance))
// Removing Pointer Leaks     
    set u1 = null
    set u2 = null
endfunction

The above function can also be called from GUI:
  • -------- This stores distance in variable r --------
  • Custom script: set udg_r = GetDistance(<YourUnit1>, <YourUnit2>)


This will be useful if you want to get feeling how much is eg. 100 distance, 300 distance...
 
Last edited:
Status
Not open for further replies.
Top