SetPlayerMuted: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 14: Line 14:


==Example==
==Example==
This adds a /mute command that can be used to mute a player.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
someguy = getPlayerFromNick ( "someGuy" )
-- create the function
if ( not isPlayerMuted ( someguy ) ) then
function mutePlayer(player,command,victimName)
  setPlayerMuted ( someguy, true )
-- if the player has specified a victim name to mute
  outputChatBox ( "You just got muted.", someguy )
if victimName then
-- get the victim player element from their name
local victim = getPlayerFromNick(victimName)
-- if the player exists
if victim then
-- if they arent already muted
if ( not isPlayerMuted(victim) ) then
-- mute them and output a message to the chat
setPlayerMuted(victim, true)
outputChatBox("You have been muted.",victim)
end
else
outputChatBox("Could not find player with name: "..tostring(victimName),player)
end
else
outputChatBox("Usage: /mute <player name>",player)
end
end
end
-- add the /mute command
addCommandHandler("mute",mutePlayer)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 22:08, 3 January 2010

Use this function to mute or unmute the player.

Syntax

bool setPlayerMuted ( player thePlayer, bool state )

Required Arguments

  • thePlayer: The player you are muting or unmuting.
  • state: Use true to mute and false to unmute the player.

Returns

Returns true if the player was successfully muted or unmuted, false otherwise.

Example

This adds a /mute command that can be used to mute a player.

-- create the function
function mutePlayer(player,command,victimName)
	-- if the player has specified a victim name to mute
	if victimName then
		-- get the victim player element from their name
		local victim = getPlayerFromNick(victimName)
		-- if the player exists
		if victim then
			-- if they arent already muted
			if ( not isPlayerMuted(victim) ) then
				-- mute them and output a message to the chat
				setPlayerMuted(victim, true)
				outputChatBox("You have been muted.",victim)
			end
		else
			outputChatBox("Could not find player with name: "..tostring(victimName),player)
		end
	else
		outputChatBox("Usage: /mute <player name>",player)
	end
end
-- add the /mute command
addCommandHandler("mute",mutePlayer)

See Also