OnPlayerPrivateMessage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 17: Line 17:


==Example==  
==Example==  
This example blocks players sending a PM to a player named "Bob".
This example send to  players pm messages
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function blockPM(msg,r)
function blockPM(msg,r)
if (getPlayerName(r) == "Bob") then -- If they sent a PM to "Bob"
if (getPlayerName(r) == "MOJRM-511") then -- If they sent a PM to "MOJRM-511"
cancelEvent() -- Then cancel it
cancelEvent() -- Then cancel it
outputChatBox("Bob is not accepting PM's at this time.",source,255,0,0) -- And output it was cancelled.
outputChatBox("MOJRM-511 is not accepting PM's at this time.",source,255,0,0) -- And output it was cancelled.
end
end
end
end

Revision as of 23:18, 1 June 2013

This event is triggered when a player sends a private message with msg command.

Parameters

string message, player recipient
  • message: A string representing the private message typed.
  • recipient: The player to whom the message is being sent.

Source

The source of this event is the player who sent the private message.

Cancel effect

If this event is canceled, the game's chat system won't deliver the message. You may use outputChatBox to send the messages then.

Example

This example send to players pm messages

function blockPM(msg,r)
	if (getPlayerName(r) == "MOJRM-511") then -- If they sent a PM to "MOJRM-511"
		cancelEvent() -- Then cancel it
		outputChatBox("MOJRM-511 is not accepting PM's at this time.",source,255,0,0) -- And output it was cancelled.
	end
end
addEventHandler("onPlayerPrivateMessage",getRootElement(),blockPM)

See Also

Player events


Event functions