GetPlayerName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Improved examples)
 
(17 intermediate revisions by 13 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Server client function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
This function returns a string containing the name of the specified player.


==Syntax==  
==Syntax==
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getPlayerName ( player )
string getPlayerName ( player thePlayer )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[player]]:getName|name|setPlayerName}}
===Required Arguments===
* '''thePlayer:''' the [[player]] you want to get the name of


===Required Arguments===  
===Returns===
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
Returns a string containing the requested player's name, or ''false'' if the player passed to the function is invalid.
*'''argumentName:''' description


<!-- Only include this section below if there are optional arguments -->
===Limits===
===Optional Arguments===  
* Player name can consist of ASCII characters between 33 and 126 are allowed (basic latin): 
{{OptionalArg}}  
<nowiki>!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</nowiki>
*'''argumentName2:''' description
* Minimal player name length is 1 character.
*'''argumentName3:''' description
* 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.


===Returns===
==Example==
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
<section name="Server" class="server" show="true">
Returns ''true'' if blah, ''false'' otherwise.
<syntaxhighlight lang="lua">
addCommandHandler("myname", function(ply)
    outputChatBox("Your name: "..getPlayerName(ply), ply)
end)
</syntaxhighlight>
</section>


==Example==  
<section name="Client" class="client" show="true">
<!-- Explain what the example is in a single sentance -->
This example outputs the local player name to the chatbox.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--This line does...
addCommandHandler("myname", function()
blabhalbalhb --abababa
    -- output local player's name to the chatbox
--This line does this...
    outputChatBox(getPlayerName(localPlayer))
mooo
end)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Client player functions}}
{{FunctionArea_functions}}
[[es:getPlayerName]]
[[Category:Need_Syntax]] -- leave this until syntax is available. Cannot document the function or event without syntax.
[[pt-br:getPlayerName]]
[[Category:Incomplete]] -- leave this unless you complete the function

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