SetPlayerName: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|Sets a players name which will appear on the nametag. Overrides the Steam nickname.}}
{{FuncDescription|Sets a players name which will appear on the nametag. Overrides the Steam nickname. This is not synchronized by the server and you need to sync it yourself.}}


{{FuncSyntax|SetPlayerName(player, name)}}
{{FuncSyntax|SetPlayerName(player, name)}}
Line 13: Line 13:
== Example ==
== Example ==
<syntaxhighlight lang="Lua>
<syntaxhighlight lang="Lua>
Name = {}
AddCommand("superman", function(playerid)
AddCommand("superman", function(playerid)
     SetPlayerName(playerid, "Superman")
     SetPlayerNameEx(playerid, "Superman")
     AddPlayerChat(playerid, "Your name is now Superman.")
     AddPlayerChat(playerid, "Your name is now Superman.")
end)
local function SetPlayerNameEx(playerid, name)
    Name[playerid] = name
end
AddEvent("OnPlayerStreamIn", function(player, otherplayer)
    SetPlayerName(otherplayer, Name[otherplayer])
end)
end)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 17:46, 29 December 2019

SetPlayerName

Type: Function
Context: Server
Introduced: v1.0

Description

Sets a players name which will appear on the nametag. Overrides the Steam nickname. This is not synchronized by the server and you need to sync it yourself.

Syntax

SetPlayerName(player, name)

Parameters

  • player
    The player identifier.
  • name
    The new name to set for the player. Limited to 32 characters.

Return Value

  • This function returns nothing.

Example

Name = {}

AddCommand("superman", function(playerid)
    SetPlayerNameEx(playerid, "Superman")
    AddPlayerChat(playerid, "Your name is now Superman.")
end)

local function SetPlayerNameEx(playerid, name)
    Name[playerid] = name
end

AddEvent("OnPlayerStreamIn", function(player, otherplayer)
    SetPlayerName(otherplayer, Name[otherplayer])
end)

See also