Difference between revisions of "GetPlayerIdFromPlayerIndex"

From Nomad DB
Line 1: Line 1:
Returns the [[Player ID]] based on the given [[Player Index]].
+
Retrieves the [[PlayerId|Player ID]] of the player with the specified [[Player Index|index]].
  
 
== Syntax ==
 
== Syntax ==
<pre>
+
<syntaxhighlight lang="lua">
 
GetPlayerIdFromPlayerIndex(playerIndex)
 
GetPlayerIdFromPlayerIndex(playerIndex)
</pre>
+
</syntaxhighlight>
* '''playerIndex''' (number) Player index
+
* '''playerIndex''' (number): Player index of the target player
* '''Returns: [[Player ID]]'''
+
* '''Returns''' (number): [[Player ID]]
  
 
== 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.
<pre>
+
<syntaxhighlight lang="lua">
 
local playerCount = GetNumberOfPlayers()
 
local playerCount = GetNumberOfPlayers()
 
for i = 0, playerCount - 1 do
 
for i = 0, playerCount - 1 do
Line 19: Line 19:
 
     end
 
     end
 
end
 
end
</pre>
+
</syntaxhighlight>
  
 
== Related Pages ==
 
== Related Pages ==

Revision as of 19:12, 14 April 2020

Retrieves the Player ID of the player with the specified index.

Syntax

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

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