IsPlayerNametagShowing: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 24: Line 24:
<!-- 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">
function toggleNametag(sourcePlayer, command, who)
function toggleNametag ( sourcePlayer, command, who )
local tplayer = sourcePlayer               -- by default, toggle the name tag of the player who issued the command
local tplayer = sourcePlayer                   -- by default, toggle the name tag of the player who issued the command
if ( who ) then                             -- if there was a nick entered in the command
if ( who ) then                               -- if there was a nick entered in the command
tplayer = getPlayerFromNick(who)    -- search for the player
tplayer = getPlayerFromName ( who )    -- search for the player
else
else
whoNick = getPlayerName(sourcePlayer)
whoNick = getPlayerName(sourcePlayer)
end
end
if (tplayer ~= false) then                               -- if the player was found (or no playername was entered)
if ( tplayer ~= false ) then                               -- if the player was found (or no playername was entered)
if isPlayerNametagShowing(tplayer) then          -- if the nametag is shown
if isPlayerNametagShowing ( tplayer ) then          -- if the nametag is shown
setPlayerNametagShowing(tplayer, false)  -- hide it
setPlayerNametagShowing ( tplayer, false )  -- hide it
outputChatBox(who .. "'s nametag is now hidden", sourcePlayer)  -- output a message to the player who entered the command
outputChatBox ( who .. "'s nametag is now hidden", sourcePlayer )  -- output a message to the player who entered the command
else                                            -- if the nametag is not shown
else                                            -- if the nametag is not shown
setPlayerNametagShowing(tplayer, true)  -- show it
setPlayerNametagShowing ( tplayer, true )  -- show it
outputChatBox(who .. "'s nametag is now showing", sourcePlayer) -- output a message to the player who entered the command
outputChatBox ( who .. "'s nametag is now showing", sourcePlayer ) -- output a message to the player who entered the command
end
end
else
else
outputChatBox("Player not found.", sourcePlayer)
outputChatBox ( "Player not found.", sourcePlayer )
end
end
end
end
addCommandHandler("toggleNametag", toggleNametag)
addCommandHandler ( "toggleNametag", toggleNametag )
</syntaxhighlight>
</syntaxhighlight>



Revision as of 16:19, 22 November 2011

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 the player's name tag is being shown, 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 ( sourcePlayer, command, who )
	local tplayer = sourcePlayer                   -- by default, toggle the name tag of the player who issued the command
	if ( who ) then                                -- if there was a nick entered in the command
		tplayer = getPlayerFromName ( who )    -- search for the player
	else
		whoNick = getPlayerName(sourcePlayer)
	end
	if ( tplayer ~= false ) then                                -- if the player was found (or no playername was entered)
		if isPlayerNametagShowing ( tplayer ) then          -- if the nametag is shown
			setPlayerNametagShowing ( tplayer, false )  -- hide it
			outputChatBox ( who .. "'s nametag is now hidden", sourcePlayer )  -- output a message to the player who entered the command
		else                                             -- if the nametag is not shown
			setPlayerNametagShowing ( tplayer, true )   -- show it
			outputChatBox ( who .. "'s nametag is now showing", sourcePlayer ) -- output a message to the player who entered the command
		end
	else
		outputChatBox ( "Player not found.", sourcePlayer )
	end
end
addCommandHandler ( "toggleNametag", toggleNametag )

See Also