GetPlayerId
The player a command names - a pid, a name or a fragment of one - or nil and why.
The reverse of GetPlayerName, for commands that take a player: "2" or 2 is the pid 2 (returned when that
player is connected); a name is matched case-insensitively, in any alphabet - the exact name when one player has it, else a
fragment ("hen" for Henry) when exactly one connected name contains it. nil when nobody matches or two do - names are not
unique, so two players called Henry make “Henry” name nobody and the reason asks for the pid - and a command never guesses
between two. The second value is the reason in words (“no player called …”, “more than one player is called … - use the
player’s id”), ready to send back. sscanf’s u letter is this function.
Syntax
Section titled “Syntax”GetPlayerId(name)| Parameter | Type | |
|---|---|---|
name |
string | number | a pid, a name, or a fragment of a name |
Returns
Section titled “Returns”number | nil, string? - the pid, or nil and why
Example
Section titled “Example”elseif cmd == "goto" then local target, why = GetPlayerId(args) if not target then SendClientMessage(pid, COLOR_RED, why) else local x, y, z = GetPlayerPos(target) SetPlayerPos(pid, x + 1, y, z) end return trueSee also
Section titled “See also”GetPlayerName · sscanf · GetPlayers · IsPlayerConnected · the Players group of the index
