OnClientChatMessage: Difference between revisions
Jump to navigation
Jump to search
Chris smith (talk | contribs) |
No edit summary |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
{{Client event}} | {{Client event}} | ||
__NOTOC__ | __NOTOC__ | ||
This event is triggered when any text is output to chatbox, including MTA's | This event is triggered when any text is output to chatbox, including MTA's internal messages. | ||
==Parameters== | ==Parameters== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string text, int r, int g, int b | string text, int r, int g, int b, int messageType | ||
</syntaxhighlight> | </syntaxhighlight> | ||
*'''text:''' The text that was output to chatbox | *'''text:''' The text that was output to chatbox. | ||
*'''r:''' The amount of red in the color of the text. | *'''r:''' The amount of red in the color of the text. | ||
*'''g:''' The amount of green 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. | *'''b:''' The amount of blue in the color of the text. | ||
{{Added feature/item|1.5.9|1.5.8|20912| | |||
*'''messageType:''' The type of message as a number. | |||
{{Message Types}} | |||
}} | |||
==Source== | ==Source== | ||
The [[event system#Event source|source]] of this event is the root element. | The [[event system#Event source|source]] of this event is either a [[player]] element or the [[root]] element. | ||
{{New items|3.0132|1.3.2| | |||
==Cancel effect== | ==Cancel effect== | ||
If this event is [[Event system#Canceling|canceled]], the game's chat system won't deliver the posts. You may use [[outputChatBox]] to send the messages then. | If this event is [[Event system#Canceling|canceled]], the game's chat system won't deliver the posts. You may use [[outputChatBox]] to send the messages then. | ||
}} | |||
==Example== | ==Example== | ||
This example doesn't output anything to chatbox if it consists only of numbers | This example doesn't output anything to chatbox if it consists only of numbers | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function onClientChatMessageHandler(text) | 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 | if string.match(text,"%d+") --[[string.match searches for pattern "%d+", means decimals]] == text then -- if string.match and text itself are the same | ||
Line 29: | Line 32: | ||
end | end | ||
end | end | ||
addEventHandler("onClientChatMessage", | addEventHandler("onClientChatMessage", root, onClientChatMessageHandler) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== |
Latest revision as of 14:44, 7 October 2021
This event is triggered when any text is output to chatbox, including MTA's internal messages.
Parameters
string text, int r, int g, int b, int messageType
- 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.
- messageType: The type of message as a number.
- 0: normal message
- 1: action message (/me)
- 2: team message
- 3: private message
- 4: internal message
Source
The source of this event is either a player element or the root element.
Cancel effect
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
- onClientChatMessage
- onClientConsole
- onClientDebugMessage
- onClientExplosion
- onClientFileDownloadComplete
- onClientHUDRender
- onClientMinimize
- onClientMTAFocusChange
- onClientPedsProcessed
- onClientPlayerNetworkStatus
- onClientPreRender
- onClientRender
- onClientRestore
- onClientTransferBoxProgressChange
- onClientTransferBoxVisibilityChange
- onClientWorldSound
Client event functions
- triggerLatentServerEvent
- triggerServerEvent
- Shared
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled