triggerClientEvent
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function triggers an event previously registered on a client. This is the primary means of passing information between the server and the client. Clients have a similar triggerServerEvent function that can do the reverse. You can treat this function as if it was an asynchronous function call, using triggerServerEvent to pass back any returned information if necessary.
It is marginally more efficient to pass one large event than two smaller ones.
Non-element MTA data types like xmlNodes or resource pointers will not be able to be passed as they do not necessarily have a valid representation on the client.
To save client CPU, you should avoid setting theElement to the root element where possible - it should be used as a last resort (rather questionable thing to do, limited to very specific tasks, if any). Using target element ( player who should receive event, if expected to be delivered to particular one) is preferred and highly advisable. resourceRoot can also be used as alternative choice, if addEventHandler is bound to root element, or to resourceRoot when there is need to restrict event to single certain resource.
Syntax
bool triggerClientEvent ( [ [ table/element sendTo = getRootElement( ] )Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- table/element sendTo (default: getRootElement(): MISSING_PARAM_DESC
Returns
- bool: value
Returns true if the event trigger has been sent, false if invalid arguments were specified.
Code Examples
function greetingHandler ( message ) outputChatBox ( "The server says: " .. message )endaddEvent( "onGreeting", true )addEventHandler( "onGreeting", localPlayer, greetingHandler )