Skip to content

GetPlayerId

The player a command names - a pid, a name or a fragment of one - or nil.

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 - the exact name wins, else a fragment ("hen" for Henry) when exactly one connected name contains it. nil when nobody matches or two do, so a command can answer “no player called …” and never guess between two. sscanf’s u letter is this function.

GetPlayerId(name)
Parameter Type
name string | number a pid, a name, or a fragment of a name

number | nil - the pid

elseif cmd == "goto" then
local target = GetPlayerId(args)
if not target then
SendClientMessage(pid, COLOUR_RED, "no player called " .. args)
else
local x, y, z = GetPlayerPos(target)
SetPlayerPos(pid, x + 1, y, z)
end
return true

GetPlayerName · sscanf · GetPlayers · IsPlayerConnected · the Players group of the index