GetPlayerName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(→‎Syntax: OOP syntax added)
m (Improved examples)
 
(8 intermediate revisions by 6 users not shown)
Line 9: Line 9:
{{OOP||[[player]]:getName|name|setPlayerName}}
{{OOP||[[player]]:getName|name|setPlayerName}}
===Required Arguments===
===Required Arguments===
* '''thePlayer:''' the Player that you want to get his name
* '''thePlayer:''' the [[player]] you want to get the name of


===Returns===
===Returns===
Line 16: Line 16:
===Limits===
===Limits===
* Player name can consist of ASCII characters between 33 and 126 are allowed (basic latin):   
* Player name can consist of ASCII characters between 33 and 126 are allowed (basic latin):   
    <nowiki>!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</nowiki>
<nowiki>!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</nowiki>
* Minimal player name length is 1 character.  
* Minimal player name length is 1 character.  
* Maximum player name length is 22 characters.
* Maximum player name length is 22 characters.
Line 24: Line 24:
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler("myname",
addCommandHandler("myname", function(ply)
  function(playerSource)
     outputChatBox("Your name: "..getPlayerName(ply), ply)
     outputChatBox("Your name: "..getPlayerName(playerSource), playerSource)
end)
  end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 35: Line 33:
This example outputs the local player name to the chatbox.
This example outputs the local player name to the chatbox.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler("myname",
addCommandHandler("myname", function()
  function()
    -- output local player's name to the chatbox
  local localPlayerName = getPlayerName(getLocalPlayer())
    outputChatBox(getPlayerName(localPlayer))
  --and we output it to the chatbox
end)
  outputChatBox(localPlayerName)
  end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>
Line 47: Line 42:
==See Also==
==See Also==
{{Client player functions}}
{{Client player functions}}
[[es:getPlayerName]]
[[pt-br:getPlayerName]]

Latest revision as of 22:01, 15 January 2024

This function returns a string containing the name of the specified player.

Syntax

string getPlayerName ( player thePlayer )

OOP Syntax Help! I don't understand this!

Method: player:getName(...)
Variable: .name
Counterpart: setPlayerName


Required Arguments

  • thePlayer: the player you want to get the name of

Returns

Returns a string containing the requested player's name, or false if the player passed to the function is invalid.

Limits

  • Player name can consist of ASCII characters between 33 and 126 are allowed (basic latin):
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  • Minimal player name length is 1 character.
  • Maximum player name length is 22 characters.
  • Player names are case-insensitive. It is not possible to have two clients with same name but different character case.

Example

Click to collapse [-]
Server
addCommandHandler("myname", function(ply)
    outputChatBox("Your name: "..getPlayerName(ply), ply)
end)
Click to collapse [-]
Client

This example outputs the local player name to the chatbox.

addCommandHandler("myname", function()
    -- output local player's name to the chatbox
    outputChatBox(getPlayerName(localPlayer))
end)

See Also