GetAlivePlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Section using)
Line 12: Line 12:


==Example==
==Example==
<section show="true" name="Server" class="server">
This example prints a list of all alive players in a "name, name2, name3" format.  If no players are alive then it outputs "none".
This example prints a list of all alive players in a "name, name2, name3" format.  If no players are alive then it outputs "none".
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 30: Line 31:
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 22:24, 14 November 2011

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

Click to collapse [-]
Server

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 = getPlayerName ( playerValue )
        else
            alivePlayersList = alivePlayersList .. ", " .. getPlayerName ( playerValue )
        end
    end
    outputChatBox ( "Alive Players: " .. alivePlayersList )    
end

See Also