Warcraft III resources & community, 2003–2006 · archived

FindClosestCorpse

not rated
Submitted by AltSubmitterFunctions0 downloads
Takes a group defined by user so that the user can pass whatever group he wants. Also takes the the unit to whom the closest corpse will be found, then returns closest corpse.

Source

function FindClosestCorpse takes group pool, unit who returns unit
    local location temploc = GetUnitLoc(who)
    local real distance = 9999999.0
    local location temploc01 = null
    local unit u = null
    local unit closestcorpse = null
    local real distance01 = 0
    local group pool01 = CreateGroup()
    if (FirstOfGroup(pool) == null) then
        return null
    endif
    call GroupAddGroup(pool,pool01)
    loop
        set u = FirstOfGroup(pool01)
        exitwhen u == null
        set temploc01 = GetUnitLoc(u)
        call GroupRemoveUnitSimple(u, pool01)
        set distance01 = DistanceBetweenPoints(temploc01,temploc)
        if (distance01 < distance) and (IsUnitAliveBJ(u) == false) then
            set distance = distance01
            set closestcorpse = u
        endif
        call RemoveLocation(temploc01)
        set temploc01 = null
    endloop
    set u = null
    call DestroyGroup(pool01)
    call RemoveLocation(temploc)
    set temploc = null
    set pool01 = null
    return closestcorpse
endfunction

Comments

0

No comments.