User:Sybellex

From Multi Theft Auto: Wiki
Revision as of 15:38, 13 August 2024 by Sybellex (talk | contribs) (Created page with "==Syntax== <syntaxhighlight lang="lua"> bool addEvent ( string eventName [, bool allowRemoteTrigger = false ] ) </syntaxhighlight> ===Required Arguments=== *'''eventName:''' The name of the event you wish to create. ===Optional Arguments=== *'''allowRemoteTrigger:''' A boolean specifying whether this event can be called remotely using triggerClientEvent / triggerServerEvent or not. ===Returns=== Returns ''true'' if the event was added successfully, ''fal...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 if the event was already added.

Example

This example will define a new event called onSpecialEvent.

-- 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 )

You can then trigger this event later on using:

	triggerEvent ( "onSpecialEvent", root, "test" )

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