cleeezzz
The Undead Ranger.
- Reaction score
- 268
JASS:
globals
group GLOBAL_GROUP
unit ReturnHandle
endglobals
function GetClosestUnitInRange takes real x, real y, real radius, boolean closest, boolexpr filter returns unit
local group g = GLOBAL_GROUP
local unit curUnit = null
local unit loopUnit
local real curDist
local real dX
local real dY
local real loopDist
call GroupClear( g )
call GroupEnumUnitsInRange( g, x, y, radius, filter )
if closest then
set curDist = radius + 1
else
set curDist = 0
endif
loop
set loopUnit = FirstOfGroup( g )
exitwhen loopUnit == null
set dX = x - GetUnitX( loopUnit )
set dY = y - GetUnitY( loopUnit )
set loopDist = SquareRoot( dX * dX + dY * dY )
if loopDist < curDist == closest then
set curDist = loopDist
set curUnit = loopUnit
endif
call GroupRemoveUnit( g, loopUnit )
endloop
set ReturnHandle = curUnit
set filter = null
set loopUnit = null
set curUnit = null
return ReturnHandle
endfunction
to make it syntax, i had to make the global unit and group, but it loaded fine