AddEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Fixed spelling mistake/typo: remotely instead of remotly)
mNo edit summary
Line 12: Line 12:


===Optional Arguments===
===Optional Arguments===
*'''allowRemoteTrigger:''' A boolean specifying whether this event can be called remotely using [[triggerClientEvent]]/[[triggerServerEvent]] or not.
*'''allowRemoteTrigger:''' A boolean specifying whether this event can be called remotely using [[triggerClientEvent]] / [[triggerServerEvent]] or not.


===Returns===
===Returns===

Revision as of 11:30, 12 May 2010

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

Returns

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

Example

This example will define a new event called onSpecialEvent.

-- Add a new event called onSpecialEvent
addEvent ( "onSpecialEvent" )

-- 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", getRootElement(), specialEventHandler )

You can then trigger this event later on using:

	triggerEvent ( "onSpecialEvent", getRootElement(), "test" )

This will cause the handler to be triggered, so "test" will be output to the chatbox.

See Also