GetPlayerByIndex

Category: Player
Since engine version: 1.0 OC

Description

Returns the indicated player number. This function guarantees that for values from 0 to GetPlayerCount()-1 a valid player number will be returned (notice that there may be "gaps" between player numbers in case some players have left the game). This makes it easier to process all players in a loop.

Syntax

int GetPlayerByIndex(int index, int player_type);

Parameters

index:
Index in the player table.
player_type:
[opt] If specified, the indicated player of the specified type is returned. This can be used e.g. to walk only through the list of human players or only through the list of script players. For a list of all player types see GetPlayerType.

Examples

for(var i = 0; i < GetPlayerCount(); i++)
  Log("Moin, %s", GetPlayerName(GetPlayerByIndex(i)));
Welcomes all players in the log file.
for(var i = 0; i < GetPlayerCount(C4PT_User); i++)
  EliminatePlayer(GetPlayerByIndex(i, C4PT_User));
Eliminates all human players but excludes script players.
See also: GetPlayerByName, GetPlayerCount, GetPlayerName, GetPlayerType
Sven2, 2007-12