GetClientName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function returns a string containing the name of the client.
{{Server function}}
{{Deprecated|getPlayerName|}}
 
This function gets a [[client]]'s name (a client can either be a [[player]] or an admin).


==Syntax==
==Syntax==
Line 8: Line 11:


===Required Arguments===
===Required Arguments===
* '''theClient:''' The client [[element]] (player or admin) you want to get the name of.
* '''theClient:''' the [[client]] element (player or admin) you want to get the name of.


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


==Example==
==Example==
This example finds a player with an ID of ''1'' and if the player exists, they are killed.
This example adds a tag before a player's nick.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Find the player with ID 1.
function tagPlayer( thePlayer, tag )
myPlayer = getPlayerFromID ( 1 )
--we check thePlayer is a player, otherwise this function could be used with admins
-- If there is a player with an ID of 1 then...
if getElementType(thePlayer) == "player" then
if ( myPlayer ~= false ) then
--we store the player's current name,
-- Try to kill the player, if it is successful then
local oldName = getClientName( thePlayer )
if ( killPlayer ( myPlayer ) ) then
--append the tag passed to this function before it,
-- Tell everyone about it!
local taggedName = tag .. oldName
outputServerChatBox ( "He shouldn't have had that ID. ", getClientName ( myPlayer ) , " has bitten the dust." )
--then set it as his new name
setClientName( thePlayer, taggedName )
end
end
end
end

Latest revision as of 16:17, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use getPlayerName instead.


This function gets a client's name (a client can either be a player or an admin).

Syntax

string getClientName ( client theClient )

Required Arguments

  • theClient: the client element (player or admin) you want to get the name of.

Returns

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

Example

This example adds a tag before a player's nick.

function tagPlayer( thePlayer, tag )
	--we check thePlayer is a player, otherwise this function could be used with admins
	if getElementType(thePlayer) == "player" then
		--we store the player's current name,
		local oldName = getClientName( thePlayer )
		--append the tag passed to this function before it,
		local taggedName = tag .. oldName
		--then set it as his new name
		setClientName( thePlayer, taggedName )
	end
end

See Also

BEFORE VERSION 1.0 :