triggerEvent | Multi Theft Auto: Wiki Skip to content

triggerEvent

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function will trigger a named event on a specific element in the element tree. See event system for more information on how the event system works.

Note

You should avoid triggering events on the root element unless you really need to. Doing this triggers the event on every element in the element tree, which is potentially very CPU intensive. Use as specific (i.e. low down the tree) element as you can.

Note

See Event Source Element for a descriptive visualization of the event system handling an event trigger.

Syntax

bool triggerEvent ( string eventName, element baseElement, var argument1, unknown ... )
Required Arguments
  • eventName: The name of the event you wish to trigger
  • baseElement: The element you wish to trigger the event on. See event system for information on how this works.
  • argument1: The first argument that the event handler expects should be added after the baseElement variable. NOTE: This function can have more than one of these arguments specified, once for each argument the event handler is expecting.
  • ...: MISSING_PARAM_DESC

Returns

  • bool: value

If you define a new custom event as follows:

Code Examples

shared

If you define a new custom event as follows:

function onCustomEvent(chatMessage)
outputChatBox(chatMessage)
end
addEvent("onCustomEvent", false) -- set to false, so this event won't be called from counter side - important security measure
addEventHandler("onCustomEvent", root, onCustomEvent)