GetPlayerByIndex

Category: Player
Since engine version: 4.9.1.0 GWE (extended in 4.9.6.0 CR)

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 iIndex, int ePlayerType);

Parameters

iIndex:
Index in the player table
ePlayerType:
[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: GetPlayerCount, GetPlayerName, GetPlayerType
Sven2, Dezember 2007