You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This page lists all <spanclass="side-client"><strong>client-side</strong></span> events available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
<p>This page lists all <spanclass="side-client"><strong>client-side</strong></span> functions available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
@@ -12,19 +13,19 @@ The event system is at the core of MTA scripting. Events work closely in conjunc
12
13
13
14
<h2id="event-handlers">Event handlers</h2>
14
15
<p>
15
-
To use the event system, you attach event handlers to elements in the element tree using <code>addEventHandler</code>. When you do this, your function will get triggered for all the events triggered on that element, its parents (and their parents, etc.) and its children (and their children). As such, an event handler attached to the <em>root</em> element will be triggered when an event occurs for any element. As a consequence you should generally use as specific a handler as you can. If you wish to just see when the player enters a specific marker, just attach the event handler to that marker.
16
+
To use the event system, you attach event handlers to elements in the element tree using <ahref="/reference/addEventHandler">addEventHandler</a>. When you do this, your function will get triggered for all the events triggered on that element, its parents (and their parents, etc.) and its children (and their children). As such, an event handler attached to the <em>root</em> element will be triggered when an event occurs for any element. As a consequence you should generally use as specific a handler as you can. If you wish to just see when the player enters a specific marker, just attach the event handler to that marker.
16
17
</p>
17
18
18
19
<p>Each event handler has three 'hidden' variables:</p>
19
20
<ul>
20
21
<li><strong>source</strong>: This is the element that the event originated from.</li>
21
-
<li><strong>this</strong>: This is the element that the handler is being triggered on (i.e. the one you attached it to with <code>addEventHandler</code>).</li>
22
-
<li><strong>eventName</strong>: This is the string of the name of the event that was called upon (i.e. the event name that was added with <code>addEventHandler</code>).</li>
22
+
<li><strong>this</strong>: This is the element that the handler is being triggered on (i.e. the one you attached it to with <ahref="/reference/addEventHandler">addEventHandler</a>).</li>
23
+
<li><strong>eventName</strong>: This is the string of the name of the event that was called upon (i.e. the event name that was added with <ahref="/reference/addEventHandler">addEventHandler</a>).</li>
23
24
</ul>
24
25
25
26
<p>Additionally, the server-side event system also has one more 'hidden' variable:</p>
26
27
<ul>
27
-
<li><strong>client</strong>: This is the client that triggered the event using <code>triggerServerEvent</code>. This is not set if the event was not triggered from a client.</li>
28
+
<li><strong>client</strong>: This is the client that triggered the event using <ahref="/reference/triggerServerEvent">triggerServerEvent</a>. This is not set if the event was not triggered from a client.</li>
28
29
</ul>
29
30
30
31
<p>
@@ -41,17 +42,17 @@ It is <strong>important</strong> to note that events follow the element hierarch
41
42
<li>You can attach an event handler to your resource's root element to get all the events triggered by elements your resource contains.</li>
42
43
<li>You can create 'dummy' elements to catch events from a group of child elements.</li>
43
44
<li>
44
-
You can use dummy elements specified in a .map file (e.g. <code><flag></code>) and create 'real' representations for them (e.g. objects) and make these real elements children of the dummy element. Event handlers can then be attached to the dummy element and it will receive all the events of the real elements.
45
+
You can use dummy elements specified in a .map file (e.g. "flag") and create 'real' representations for them (e.g. objects) and make these real elements children of the dummy element. Event handlers can then be attached to the dummy element and it will receive all the events of the real elements.
45
46
This is useful for when one resource manages the representation of the element (creating the objects, for example), while another wants to handle special events. This could be a map resource that wants to handle a flag being captured in a specific way - the map resource would (generally) not be aware of the way the flag is represented.
46
47
This doesn't matter as it can just attach handlers to its dummy flag element while the other gamemode resource can handle the representation.
47
48
</li>
48
49
</ul>
49
50
50
51
<p>
51
-
The function you attached to an event gets called and passed a bunch of arguments. These arguments are event-specific. Each event has specific parameters, for instance <code>onClientGUIClick</code> has 4 parameters, which are:
52
+
The function you attached to an event gets called and passed a bunch of arguments. These arguments are event-specific. Each event has specific parameters, for instance <ahref="/reference/onClientGUIClick">onClientGUIClick</a> has 4 parameters, which are:
52
53
</p>
53
54
54
-
<pre><codeclass="language-lua">string button, string state, int absoluteX, int absoluteY</code></pre>
55
+
<Codecode="string button, string state, int absoluteX, int absoluteY"lang="lua" />
55
56
56
57
<p>
57
58
The function you attached to this event will be passed these parameters as arguments. You must remember that each event has different parameters.
@@ -64,16 +65,16 @@ MTA has a number of built in events. These are listed on the pages <a href="/ref
64
65
65
66
<h2id="custom-events">Custom events</h2>
66
67
<p>
67
-
You can create your own events that can be triggered across all resources. This is an important way to communicate with other resources and allow them to hook into your code. To add your own custom event, just call the <code>addEvent</code> function. You can then use the <code>triggerEvent</code> function to trigger that event any time you want - either using a timer, or based on a more general event.
68
+
You can create your own events that can be triggered across all resources. This is an important way to communicate with other resources and allow them to hook into your code. To add your own custom event, just call the <ahref="/reference/addEvent">addEvent</a> function. You can then use the <ahref="/reference/triggerEvent">triggerEvent</a> function to trigger that event any time you want - either using a timer, or based on a more general event.
68
69
</p>
69
70
70
71
<p>
71
-
For example, you could be making a Capture the Flag game mode and want to trigger an event when a player captures the flag. You could do this by attaching a event handler to the standard MTA <code>onMarkerHit</code> event and checking that the player entering the marker has the flag. If they do, you can then trigger your more specific <em>onFlagCaptured</em> event and other resources could handle this as they please.
72
+
For example, you could be making a Capture the Flag game mode and want to trigger an event when a player captures the flag. You could do this by attaching a event handler to the standard MTA <ahref="/reference/onMarkerHit">onMarkerHit</a> event and checking that the player entering the marker has the flag. If they do, you can then trigger your more specific <em>onFlagCaptured</em> event and other resources could handle this as they please.
72
73
</p>
73
74
74
75
<h2id="canceling">Canceling</h2>
75
76
<p>
76
-
Events can be canceled with <code>cancelEvent</code>. This can have a variety of effects, but in general this means that the server will not perform whatever action it would usually do. For example, canceling <code>onPickupUse</code> would prevent a player being given what they tried to pick up, canceling <code>onVehicleStartEnter</code> would prevent the player entering the vehicle. You can check if the currently active event has been canceled using <code>wasEventCanceled</code>. It's important to note that canceling an event <strong>does not</strong> prevent other event handlers being triggered.
77
+
Events can be canceled with <ahref="/reference/cancelEvent">cancelEvent</a>. This can have a variety of effects, but in general this means that the server will not perform whatever action it would usually do. For example, canceling <ahref="/reference/onPickupUse">onPickupUse</a> would prevent a player being given what they tried to pick up, canceling <ahref="/reference/onVehicleStartEnter">onVehicleStartEnter</a> would prevent the player entering the vehicle. You can check if the currently active event has been canceled using <ahref="/reference/wasEventCancelled">wasEventCancelled</a>. It's important to note that canceling an event <strong>does not</strong> prevent other event handlers being triggered.
<p>This page lists all <spanclass="side-client"><strong>client-side</strong></span> and <spanclass="side-server"><strong>server-side</strong></span> events available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
<p>This page lists all <spanclass="side-client"><strong>client-side</strong></span>, <spanclass="side-server"><strong>server-side</strong></span> and <spanclass="side-shared"><strong>shared</strong></span> functions available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
<p>This page lists all <spanclass="side-server"><strong>server-side</strong></span> events available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
<p>This page lists all <spanclass="side-server"><strong>server-side</strong></span> functions available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
<p>This page lists all <spanclass="side-shared"><strong>shared</strong></span> functions available in the <ahref="/reference/Lua_API">Lua API</a> organized by category.</p>
0 commit comments