addEvent | Multi Theft Auto: Wiki Skip to content

addEvent

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 allows you to register a custom event. Custom events function exactly like the built-in events. See event system for more information on the event system.

Syntax

bool addEvent ( string eventName, [ bool allowRemoteTrigger = false ] )
Required Arguments
  • eventName: The name of the event you wish to create.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • allowRemoteTrigger (default: false): A boolean specifying whether this event can be called remotely using triggerClientEvent / triggerServerEvent or not.

Returns

  • bool: value

Returns true if the event was added successfully, false if the event was already added.

Code Examples

shared

This example will define a new event calledonSpecialEvent.

-- Add a new event called onSpecialEvent
addEvent ( "onSpecialEvent", true )
-- Define our handler function, that takes a "text" parameter and outputs it to the chatbox
function specialEventHandler ( text )
outputChatBox ( text )
end
-- Add it as a handler for our event
addEventHandler ( "onSpecialEvent", root, specialEventHandler )