GetPlayerName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(server/client side)
No edit summary
Line 15: Line 15:


==Example==
==Example==
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
addCommandHandler("myname",
  function(playerSource)
    outputChatBox("Your name: "..getPlayerName(playerSource), playerSource)
  end
)
</syntaxhighlight>
</section>
<section name="Client" class="client" show="true">
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">
--we get the local player
addCommandHandler("myname",
local localPlayer = getLocalPlayer()
  function()
--then we get his name
  local localPlayerName = getPlayerName(getLocalPlayer())
local localPlayerName = getPlayerName(localPlayer)
  --and we output it to the chatbox
--and we output it to the chatbox
  outputChatBox(localPlayerName)
outputChatBox(localPlayerName)
  end
)
</syntaxhighlight>
</syntaxhighlight>
<section>


==See Also==
==See Also==
{{Client player functions}}
{{Client player functions}}

Revision as of 14:04, 26 April 2009

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

Syntax

string getPlayerName ( player thePlayer )

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.

Example

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

<section name="Client" class="client" show="true"> This example outputs the local player name to the chatbox.

addCommandHandler("myname",
  function()
   local localPlayerName = getPlayerName(getLocalPlayer())
   --and we output it to the chatbox
   outputChatBox(localPlayerName)
  end
)

<section>

See Also