AddEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 23: Line 23:
addEvent ( "onSpecialEvent" )
addEvent ( "onSpecialEvent" )


-- Add an event handler
addEventHandler ( "onSpecialEvent", rootElement, "specialEventHandler" )
-- Define our handler function
-- Define our handler function
function specialEventHandler ( text )
function specialEventHandler ( text )
outputChatBox ( text )
outputChatBox ( text )
end
end
-- Add an event handler
addEventHandler ( "onSpecialEvent", rootElement, specialEventHandler )


</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:40, 30 July 2007

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 )   

Required Arguments

  • eventName: The name of the event you wish to create
  • arguments: A string of comma seperated variable names indicating the arguments your event takes. These names are used for event handlers that are coded in the map structure. For example "message, playerName".

Returns

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

Example

This example will define a new event called onSpecialEvent.

-- Get the root map element
rootElement = getRootElement ()

-- Add a new event called onSpecialEvent that has one parameter 'text'
addEvent ( "onSpecialEvent" )

-- Define our handler function
function specialEventHandler ( text )
	outputChatBox ( text )
end
-- Add an event handler
addEventHandler ( "onSpecialEvent", rootElement, specialEventHandler )

You can then trigger this event later on using:

	triggerEvent ( "onSpecialEvent", rootElement, "test" )

See Also