TriggerClientEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function triggers an event on clients. 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.
This fake function is for use with blah & blah and does blahblahblabhalbhl
 
The key limitation of this is you ''cannot'' pass tables of information using this. Any other data types should work as expected, including [[elements]]. Special data types like xmlNodes will not be able to be passed as they do not necessarily have a valid representation on the client.
 
Events are sent reliably, so clients will receive them, but there may be (but shouldn't be) a significant delay before they are received. You should take this into account when using them.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool triggerClientEvent ( [element triggerFor=getRootElement()], string name, element theElement, [arguments...] )
bool triggerClientEvent ( [element triggerFor=getRootElement()], string name, element theElement, [arguments...] )
Line 10: Line 12:


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''name:''' The name of the event to trigger client side. You should register this event with [[addEvent]] and add at least one event handler using [[addEventHandler]].
*'''argumentName:''' description
*'''theElement:''' The element that is the ''source'' of the event. This could be another player, or if this isn't relevant, use the root element.


<!-- Only include this section below if there are optional arguments -->
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
*'''argumentName2:''' description
*'''triggerFor:''' The event will be triggered on all [[players]] that are children of the specified element. By default this is the root element, and hence the event is triggered on all elements. If you specify a single player it will just be triggered for that player.
*'''argumentName3:''' description
*'''arguments...:''' A list of arguments to trigger with the event. You cannot pass [[tables]] or any MTA special data types except [[elements]].


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns ''true'' if the event trigger has been sent, ''false'' if invalid arguments were specified.
Returns ''true'' if blah, ''false'' otherwise.


==Example==  
==Example==  
Line 35: Line 36:


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Event_functions}}
{{FunctionArea_functions}}
[[Category:Incomplete]] -- leave this unless you complete the function
[[Category:Incomplete]] -- leave this unless you complete the function

Revision as of 13:16, 11 June 2007

This function triggers an event on clients. 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.

The key limitation of this is you cannot pass tables of information using this. Any other data types should work as expected, including elements. Special data types like xmlNodes will not be able to be passed as they do not necessarily have a valid representation on the client.

Events are sent reliably, so clients will receive them, but there may be (but shouldn't be) a significant delay before they are received. You should take this into account when using them.

Syntax

bool triggerClientEvent ( [element triggerFor=getRootElement()], string name, element theElement, [arguments...] )

Required Arguments

  • name: The name of the event to trigger client side. You should register this event with addEvent and add at least one event handler using addEventHandler.
  • theElement: The element that is the source of the event. This could be another player, or if this isn't relevant, use the root element.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • triggerFor: The event will be triggered on all players that are children of the specified element. By default this is the root element, and hence the event is triggered on all elements. If you specify a single player it will just be triggered for that player.
  • arguments...: A list of arguments to trigger with the event. You cannot pass tables or any MTA special data types except elements.

Returns

Returns true if the event trigger has been sent, false if invalid arguments were specified.

Example

This example does...

--This line does...
blabhalbalhb --abababa
--This line does this...
mooo

See Also

-- leave this unless you complete the function