SetClientName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Visual improvement)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server function}}
{{Deprecated|setPlayerName}}
__NOTOC__
 
This function changes the specified [[client]]'s name.
This function changes the specified [[client]]'s name.


Line 15: Line 18:


==Example==
==Example==
This example adds a tag before a player's nick.
<section name="Server" class="server" show="true">
This example adds a tag before a player's nickname via a /changetag command
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function tagPlayer( command, thePlayer, tag )
 
--we check thePlayer is a player, otherwise this function could be used with admins
--Define the function for this command (/changetag, as defined below)
if getElementType( thePlayer ) == "player" then
--Source = the player that triggered this command
--we store the player's current name,
--Command = The command passed into the function (changetag)
local oldName = getClientName( thePlayer )
--thePlayer = The player argument that you wish to add a tag too
--append the tag passed to this function before it,
--tag = The tag to add to the players nickname
local taggedName = tag .. oldName
function tagPlayer( source, command, thePlayer, tag )
--then set it as his new name
--Attempt to grab the elemennt id for the player from the parsed name.
setClientName( thePlayer, taggedName )
local sPlayerElement = getPlayerFromNick(thePlayer)
--Check to see if the player were changing the tag for exists.
if (sPlayerElement) then
--make sure that the element type of thePlayer is acctually pointing to a player element
if getElementType( sPlayerElement ) == "player" then
--we store the player's current name,
local oldName = getClientName( sPlayerElement )
--append the tag passed to this function before it
local taggedName = tag .. oldName
--then set it as his new name
setClientName( sPlayerElement, taggedName )
--Tell the player who triggerd the command that the tag has been applied
outputChatBox ( "Player " .. thePlayer .. "'s tag changed to " .. taggedName, source )
end
else
--Tell the player who triggerd the command that the player could not be found
outputChatBox ( "Unable to change player tag: Player " .. thePlayer .. " not found", source )
end
end
end
end
--Add a command handler for either the console or / chat commands
--Example: /changetag <playername> <tag>
addCommandHandler ( "changetag", tagPlayer )
addCommandHandler ( "changetag", tagPlayer )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Client_functions}}
{{Client_functions}}

Latest revision as of 12:31, 26 June 2014

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 setPlayerName instead.


This function changes the specified client's name.

Syntax

bool setClientName ( client theClient, string newName )

Required Arguments

  • theClient: the client that will have its name set.
  • newName: the new name to set for the client.

Returns

Returns true if the client's name was changed succesfully, false if invalid arguments are specified.

Example

Click to collapse [-]
Server

This example adds a tag before a player's nickname via a /changetag command


--Define the function for this command (/changetag, as defined below)
--Source = the player that triggered this command
--Command = The command passed into the function (changetag)
--thePlayer = The player argument that you wish to add a tag too
--tag = The tag to add to the players nickname
function tagPlayer( source, command, thePlayer, tag )
	--Attempt to grab the elemennt id for the player from the parsed name.
	local sPlayerElement = getPlayerFromNick(thePlayer)
	--Check to see if the player were changing the tag for exists.
	if (sPlayerElement) then
		--make sure that the element type of thePlayer is acctually pointing to a player element
		if getElementType( sPlayerElement ) == "player" then
			--we store the player's current name,
			local oldName = getClientName( sPlayerElement )
			--append the tag passed to this function before it
			local taggedName = tag .. oldName
			--then set it as his new name
			setClientName( sPlayerElement, taggedName )
			--Tell the player who triggerd the command that the tag has been applied
			outputChatBox ( "Player " .. thePlayer .. "'s tag changed to " .. taggedName, source )
		end
	else
		--Tell the player who triggerd the command that the player could not be found
		outputChatBox ( "Unable to change player tag: Player " .. thePlayer .. " not found", source )
	end
end
--Add a command handler for either the console or / chat commands
--Example: /changetag <playername> <tag>
addCommandHandler ( "changetag", tagPlayer )

See Also

BEFORE VERSION 1.0 :