Difference between revisions of "GetPlayerIdFromPlayerIndex"

From Nomad DB
m
Line 9: Line 9:
  
 
== Example ==
 
== Example ==
The example below checks whether the [[EntityId|Entity ID]] of the local player is valid or not.
+
The example below checks whether the [[EntityId|entity ID]] of the local player is valid or not.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
local playerCount = GetNumberOfPlayers()
 
local playerCount = GetNumberOfPlayers()

Revision as of 19:20, 14 April 2020

Retrieves the ID of the player with the specified index.

Syntax

GetPlayerIdFromPlayerIndex(playerIndex)
  • playerIndex (number): index of the target player
  • Returns (number): ID of the specified player

Example

The example below checks whether the entity ID of the local player is valid or not.

local playerCount = GetNumberOfPlayers()
for i = 0, playerCount - 1 do
    local playerId = GetPlayerIdFromPlayerIndex(i)
    local playerNameDebug = GetPlayerNameDebug(playerId)
    if playerNameDebug == "2XTheTap" then
        -- do stuff
    end
end

Related Pages