UserFunction; Universe_SortTeams - HWRM/KarosGraveyard GitHub Wiki

Description

Sorts the list of players into teams, and stores the result in a table.
Note that two global variables must be declared before calling this function: a table named "aTeam", and an integer named "nTeam".

function Universe_SortTeams()
    -- reset the team array
    aTeam = {}
    -- for every player...
    for playerIndex = 0, (Universe_PlayerCount() - 1) do
        local iTeam2 = 0
        local bAlly = 0
        -- sort players into teams
        for i = 1, getn(aTeam) do
            for j = 1, getn(aTeam[i]) do
                if (AreAllied(aTeam[i][j], playerIndex) == 1) then
                    tinsert(aTeam[i], playerIndex)
                    iTeam2 = i
                    bAlly = 1
                    break
                end
            end
        end
        if (bAlly == 0) then
            tinsert(aTeam, {playerIndex,})
            iTeam2 = getn(aTeam)
        end
    end
    -- count the number of teams
    nTeam = getn(aTeam)
end

Comments

Page Status

Updated Formatting? Initial
Updated for HWRM? Initial