This function returns all the alive players by a client side, so you can store them into a Gridlist or something like that, faster.

Syntax

table getAlivePlayers()

Code

Click to collapse [-]

Function source

function getAlivePlayers()
local alivePlayers = { }
for i,p in ipairs (getElementsByType("player")) do
if getElementHealth(p) > 0 then
table.insert(alivePlayers,p)
end
end
return alivePlayers
end

Example

Click to collapse [-]

Example

We want to get the alive players and place them into a gridlist.

local playerGrid = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) --Creates the gridlist.
local column = guiGridListAddColumn( playerGrid, "Player", 0.85 ) --Creates a player column in the list.
if column then --If the column suscessfully set...
local players = getAlivePlayers()
for id, player in ipairs(players) do
local row = guiGridListAddRow ( playerGrid ) --Creates a row for each player.
guiGridListSetItemText ( playerGrid, row, column, getPlayerName ( player ), false, false ) --Fills the row with the name of the player.
end
end

Original function by The Kid.

See Also

Table functions

isValueInTable» This function returns true if the value exists in the table, false if the value does not exist in the table.

setTableToSql» This function is used to save the table in the database (sql).