GetPlayerID

Category: Player
Since engine version: 1.0 OC

Description

Returns the player-ID of a joined player. Player-IDs are being counted upwards starting at 1. Other than player numbers, they won't be used again after a player has been eliminated. Each newly joined player has a unique ID.

Syntax

int GetPlayerID(int player);

Parameter

player:
Player of which to retrieve the ID.

Remark

In network games, player IDs are being assigned in the lobby phase. Because lobby players might be removed before the game start (either manually or by disconnecting clients), you cannot assume that all player-IDs from 1 to GetPlayerCount() are set.

Example

static player_names, player_scores;

protected func Initialize()
{
	if(!player_names) player_names = CreateArray();
	if(!player_scores) player_scores = CreateArray();
}
				
protected func RemovePlayer(int player)
 {
  var player_id = GetPlayerID(player);
	player_names[player_id] = GetPlayerName(player);
	player_scores[player_id] = GetScore(player);
 }
  
protected func OnGameOver()
{
  Log("Scores of eliminated players:");
  for (var i = 0; i < GetLength(player_names); ++i)
    if (player_names[i])
      Log(Format("%s - %d", player_names[i], player_scores[i]));
}
Saves the scores and names of all players in a list when they are eliminated. Once the round is over, this list is displayed in the log. Using player-IDs instead of player numbers as list indices guarantuees that rejoining players will not overwrite scores of previous players.
See also: GetPlayerTeam
Sven2, 2006-03