Warcraft III resources & community, 2003–2006 · archived

FindClosestUnitMatching

not rated
Submitted by PitzerMikeVariable Change0 downloads
This function will find the unit that is next to the given location and matches the condition. The condition should be a filterfunc.

Source

//============================================================================================================ 
//
// 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
endfunction

Comments

0

No comments.