GetPlayerID

Category: Player
Since engine version: 4.9.6.0 CR

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 iPlayerNumber);

Parameter

iPlayerNumber:
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 num_scores;
        
protected func RemovePlayer(int iPlr)
  {
  var idPlr = GetPlayerID(iPlr);
  Global(idPlr*2)   = GetPlayerName(iPlr);
  Global(idPlr*2+1) = GetScore(iPlr);
  ++num_scores;
  }
  
protected func OnGameOver()
  {
  var msg = "Scores:", i, plr_name;
  while (num_scores)
    if (plr_name = Global(i++*2))
      {
      msg = Format("%s|%s=%d", msg, plr_name, Global(i*2-1));
      --num_scores;
      }
  Message(msg);
  }
Saves the scores and names of all players in a list when they are eliminated. Once the round is over, this list is displayed as a message. 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, März 2006