IsPlayerNametagShowing: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:
==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
<!-- Explain what the example is in a single sentance -->
This example does...
This example toggles a player's nametag. If no playername is given, it toggles the nametag of the player who entered the command.
<!-- 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 -->
<!-- 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">
addCommandHandler ( "nametagstatus", "outputTagStatus" )
function toggleNametag(player,command,who)
function outputTagStatus ( player, commandName )
local tplayer = player -- define 'tplayer' as the player who called the command
tagstatus = isPlayerNametagShowing ( player )
if (who ~= nil) then -- if there was a nick entered in the command
--Asks if the commandhandler activator's tag is showing and stores
tplayer = getPlayerFromNick(who) -- search for the player
--it to tagstatus as true or false
if tagstatus == true then
outputChatBox ( "Your tag is visible" )
--output that name tag is showing because tagstatus is true
else
else
outputChatBox ( "Your tag is not visible" )
who = getClientName(player)
--output that name tag is not showing because tagstatus is false
end
if (tplayer ~= false) then -- if the player was found (or no playername was entered)
if (isPlayerNametagShowing(tplayer) == true) then -- if the nametag is shown
setPlayerNametagShowing(tplayer,false) -- hide it
outputChatBox("Nametag is now hidden for "..who,player) -- output a message to the player who entered the command
else -- if the nametag is not shown
setPlayerNametagShowing(tplayer,true) -- show it
outputChatBox("Nametag is now showing for "..who,player) -- output a message to the player who entered the command
end
else
outputChatBox("Player not found.",player)
end
end
end
end
addCommandHandler("toggleNametag",toggleNametag)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 18:36, 30 July 2007

This function will allow you to determine if a player's name tag is currently showing.

Syntax

bool isPlayerNametagShowing ( player thePlayer )

Required Arguments

  • thePlayer: The player whose current name tag condition you want to check

Returns

Returns true if successful, false otherwise.

Example

This example toggles a player's nametag. If no playername is given, it toggles the nametag of the player who entered the command.

function toggleNametag(player,command,who)
	local tplayer = player -- define 'tplayer' as the player who called the command
	if (who ~= nil) then -- if there was a nick entered in the command
		tplayer = getPlayerFromNick(who) -- search for the player
	else
		who = getClientName(player)
	end
	if (tplayer ~= false) then -- if the player was found (or no playername was entered)
		if (isPlayerNametagShowing(tplayer) == true) then -- if the nametag is shown
			setPlayerNametagShowing(tplayer,false) -- hide it
			outputChatBox("Nametag is now hidden for "..who,player) -- output a message to the player who entered the command
		else -- if the nametag is not shown
			setPlayerNametagShowing(tplayer,true) -- show it
			outputChatBox("Nametag is now showing for "..who,player) -- output a message to the player who entered the command
		end
	else
		outputChatBox("Player not found.",player)
	end
end
addCommandHandler("toggleNametag",toggleNametag)

See Also

Shared