GetAlivePlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 19: Line 19:
     alivePlayersList = "none"
     alivePlayersList = "none"
     -- Loop through the table
     -- Loop through the table
     for playerKey, playerValue in pairs(alivePlayers) do
     for playerKey, playerValue in ipairs(alivePlayers) do
         -- add their name to the list
         -- add their name to the list
         if ( alivePlayersList == "none" ) then
         if ( alivePlayersList == "none" ) then

Revision as of 11:44, 24 October 2007

This function returns a table of all the alive players on the server. Opposite function of getDeadPlayers.

Syntax

table getAlivePlayers ( )

Returns

Returns a table of all the alive players.

Example

This example prints a list of all alive players in a "name, name2, name3" format. If no players are alive then it outputs "none".

-- Print a list of all the alive players
alivePlayers = getAlivePlayers ()
if ( alivePlayers ) then -- if we got the table
    alivePlayersList = "none"
    -- Loop through the table
    for playerKey, playerValue in ipairs(alivePlayers) do
        -- add their name to the list
        if ( alivePlayersList == "none" ) then
            alivePlayersList = getClientName ( playerValue )
        else
            alivePlayersList = alivePlayersList .. ", " .. getClientName ( playerValue )
        end
    end
    outputChatBox ( "Alive Players: " .. alivePlayersList )    
end

See Also