OnClientChatMessage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(PR isn't merged yet, my bad.)
(Replace to predefined variable.)
Line 27: Line 27:
end
end
end
end
addEventHandler("onClientChatMessage", getRootElement(), onClientChatMessageHandler)
addEventHandler("onClientChatMessage", root, onClientChatMessageHandler)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 15:43, 27 February 2021

This event is triggered when any text is output to chatbox, including MTA's hardcoded messages.

Parameters

string text, int r, int g, int b
  • text: The text that was output to chatbox
  • r: The amount of red in the color of the text.
  • g: The amount of green in the color of the text.
  • b: The amount of blue in the color of the text.

Source

The source of this event is either a player element or the root element.

Cancel effect

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

Example

This example doesn't output anything to chatbox if it consists only of numbers

function onClientChatMessageHandler(text)
	if string.match(text,"%d+") --[[string.match searches for pattern "%d+", means decimals]] == text then -- if string.match and text itself are the same
		cancelEvent() -- don't output it
	end
end
addEventHandler("onClientChatMessage", root, onClientChatMessageHandler)

See Also

Client other events


Client event functions