ForEachPlayer
Calls a function for every connected player, in join order.
The loop of GetPlayers in one call. The list is taken before the first call, so the function may kick, hold or spawn
players as it goes; a player who left meanwhile is skipped. With inWorld true only the players standing in the world
are visited - the ones still loading or held by OnPlayerRequestSpawn are left out (IsPlayerInWorld). The function
returning false stops the loop.
Syntax
Section titled “Syntax”ForEachPlayer(fn [, inWorld])| Parameter | Type | |
|---|---|---|
fn |
function | function(pid) end; return false to stop |
inWorld |
boolean | true = the players in the world alone (false) (optional) |
Returns
Section titled “Returns”number - how many players the function saw
Example
Section titled “Example”-- everyone in the world reads the line; the loading ones get theirs from OnPlayerSpawnForEachPlayer(function(pid) ShowInfoText(pid, "The hunt begins", 3000)end, true)
-- the first admin onlinelocal adminForEachPlayer(function(pid) if IsPlayerAdmin(pid) then admin = pid return false endend)See also
Section titled “See also”GetPlayers · GetPlayerCount · IsPlayerInWorld · the Players group of the index
