FindClosestUnitMatching
not ratedThis function will find the unit that is next to the given location and matches the condition. The condition should be a filterfunc.
//============================================================================================================
//
// For more JASS scripts, visit us at http://www.wc3JASS.com
//
//============================================================================================================
function FindClosestUnitMatching takes location whichLoc, boolexpr matchingCondition returns unit
local group G = CreateGroup()
local real Dist = 1000000
local unit Closest
local unit U
call GroupEnumUnitsInRect(G,GetEntireMapRect(),matchingCondition)
loop
set U = FirstOfGroup(G)
exitwhen U == null
if DistanceBetweenPoints(GetUnitLoc(U),whichLoc) < Dist then
set Closest = U
set Dist = DistanceBetweenPoints(GetUnitLoc(U),whichLoc)
endif
call GroupRemoveUnit(G,U)
endloop
call DestroyGroup(G)
return Closest
endfunctionNo comments.