Skip to content

Commit 81a80f5

Browse files
committed
Fixes for last commit (Event functions)
1 parent ca4e851 commit 81a80f5

14 files changed

+105
-118
lines changed

functions/Event/addEventHandler.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ shared:
1616
be called when the event it is attached to is triggered for this element, or
1717
one of its children. Often, this can be the root element (meaning the handler
1818
will be called when the event is triggered for *any* element).
19-
- name: handlerFunction
19+
- name: handlerFunction()
2020
type: function
2121
description: The handler function you wish to call when the event is triggered.
2222
This function will be passed all of the event's parameters as arguments, but
@@ -53,8 +53,8 @@ shared:
5353
- See [Event Source Element](/reference/Event_Source_Element "Event Source Element") for a descriptive visualization of the event
5454
system handling an event trigger.
5555
- Due to the additional set of global variables, the event-trigger specific
56-
variables it is NOT a good idea to use the same function locally as well as
57-
directly as an event handler . Event handlers often make use of the source element
56+
variables it is **NOT** a good idea to use the same function locally as well as
57+
directly as an event handler. Event handlers often make use of the source element
5858
variable which would often find no use in generic functions. Inside of server-side
5959
remote event handlers it is important to add protections against exploits due
6060
to unexpected client event triggers or network-based load situations while generic
@@ -64,8 +64,8 @@ shared:
6464
from remote logic.
6565
- type: important
6666
content: |
67-
- See [Script security](/Script_security "Script security") for how-to prevent cheaters from abusing [event system](/reference/Event_System "Event system").
67+
- See [Script security](/articles/script-security "Script security") for how-to prevent cheaters from abusing [event system](/reference/Event_System "Event system").
6868
- Anything bound to a specific element will be run before other handlers
69-
that are bound to something higher in the element tree (like root) This means
70-
that "high+10" bound to root **won't** trigger before "normal" bound directly to
69+
that are bound to something higher in the element tree (like [[root]]) This means
70+
that `high+10` bound to root **won't** trigger before `normal` bound directly to
7171
an element.

functions/Event/cancelEvent.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
shared:
1+
shared: &shared
22
name: cancelEvent
33
description: This function is used to stop the automatic internal handling of events
44
event.
@@ -8,14 +8,19 @@ shared:
88
- type: bool
99
name: result
1010
description: Always returns **true**.
11+
notes:
12+
- type: info
13+
content: Not every event can be cancelled, so make sure the event is cancellable according to the documentation.
1114

1215
client:
16+
<<: *shared
1317
examples:
1418
- path: examples/cancelEvent-2.lua
1519
description: This example prevents any damage to a player clientside by making **cancelEvent** an
1620
event handler for the [[onClientPlayerDamage]] event.
1721

1822
server:
23+
<<: *shared
1924
parameters:
2025
- name: cancel
2126
type: bool
@@ -27,9 +32,4 @@ server:
2732
default: '""'
2833
examples:
2934
- path: examples/cancelEvent-1.lua
30-
description: This example stops the player from entering a vehicle.
31-
returns:
32-
values:
33-
- type: bool
34-
name: result
35-
description: Returns **true**, otherwise **false** if parameters are invalid.
35+
description: This example stops the player from entering a vehicle.
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
1-
shared:
1+
shared: &shared
22
name: cancelLatentEvent
3-
description: Stops a latent event from completing
4-
parameters:
5-
- name: handle
6-
type: int
7-
description: A handle previous got from [[getLatentEventHandles]].
8-
examples:
9-
- path: examples/cancelLatentEvent-1.lua
10-
description: ''
11-
returns:
12-
values:
13-
- type: bool
14-
name: result
15-
description: Returns a **true** if the latent event was successfully cancelled, otherwise **false**.
16-
17-
server:
3+
description: Stops a latent event from completing.
184
parameters:
195
- name: thePlayer
206
type: player
217
description: The player who is receiving the event.
228
- name: handle
239
type: int
2410
description: A handle previous got from [[getLatentEventHandles]].
25-
examples:
26-
- path: examples/cancelLatentEvent-3.lua
27-
description: "Cancel all my triggerLatentClientEvent's"
2811
returns:
2912
values:
3013
- type: bool
3114
name: result
3215
description: Returns a **true** if the latent event was successfully cancelled, otherwise **false**.
3316

34-
client:
17+
server:
18+
<<: *shared
3519
examples:
3620
- path: examples/cancelLatentEvent-2.lua
37-
description: "Cancel all my triggerLatentServerEvent's"
21+
description: "Cancel all my triggerLatentClientEvent's."
22+
23+
client:
24+
<<: *shared
25+
ignore_parameters:
26+
- thePlayer
27+
examples:
28+
- path: examples/cancelLatentEvent-1.lua
29+
description: ''
30+
- path: examples/cancelLatentEvent-3.lua
31+
description: "Cancel all my triggerLatentServerEvent's."

functions/Event/getCancelReason.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ server:
99
values:
1010
- type: string
1111
name: result
12-
description: Returns the reason that was given with [[cancelEvent]]
12+
description: Returns the reason that was given with [[cancelEvent]].

functions/Event/getEventHandlers.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
shared:
1+
shared: &shared
22
name: getEventHandlers
33
description: This function gets the attached functions from the event and attached
44
element from current lua script.
@@ -14,12 +14,18 @@ shared:
1414
- type: table
1515
name: result
1616
description: Returns [[table]] with attached functions, otherwise empty [[table]].
17+
notes:
18+
- type: important
19+
content: This function only checks the current script.
1720

1821
server:
22+
<<: *shared
1923
examples:
2024
- path: examples/getEventHandlers-1.lua
2125
description: ''
26+
2227
client:
28+
<<: *shared
2329
examples:
2430
- path: examples/getEventHandlers-2.lua
2531
description: This example removes all [[onClientMarkerHit]] event.
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
shared:
1+
shared: &shared
22
name: getLatentEventHandles
3-
description: Gets the currently queued latent events. The last one in the table
3+
description: Gets the currently queued latent events. The last one in the [[table]]
44
is always the latest event queued.
55
parameters: []
6-
examples:
7-
- path: examples/getLatentEventHandles-1.lua
8-
description: This command is triggering an latent-event to server, and if you
9-
write the command again and the trigger still didn't end then you have to wait.
106
returns:
117
values:
128
- type: table
139
name: result
1410
description: Returns a [[table]] of handles, otherwise **false** if invalid arguments were passed.
1511

1612
server:
17-
name: getLatentEventHandles
18-
description: Gets the currently queued latent events. The last one in the table
19-
is always the latest event queued. Each returned handle can be used with [getLatentEventStatus](/wiki/GetLatentEventStatus
20-
"GetLatentEventStatus") or [cancelLatentEvent](/wiki/CancelLatentEvent "CancelLatentEvent")
13+
<<: *shared
2114
parameters:
2215
- name: thePlayer
2316
type: player
@@ -27,3 +20,12 @@ server:
2720
- type: table
2821
name: result
2922
description: Returns a [[table]] of handles, otherwise **false** if invalid arguments were passed.
23+
24+
client:
25+
<<: *shared
26+
ignore_parameters:
27+
- thePlayer
28+
examples:
29+
- path: examples/getLatentEventHandles-1.lua
30+
description: This command is triggering an latent-event to server, and if you
31+
write the command again and the trigger still didn't end then you have to wait.
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
shared:
2-
name: getLatentEventStatus
3-
description: Gets the status of one queued latent event.
4-
parameters:
5-
- name: handle
6-
type: int
7-
description: A handle previous got from [[getLatentEventHandles]].
8-
returns:
9-
values:
10-
- type: table
11-
name: result
12-
description: 'Returns a [[table]] with the following info, otherwise **false** if invalid arguments
13-
were passed:'
14-
15-
server:
1+
shared: &shared
162
name: getLatentEventStatus
173
description: Gets the status of one queued latent event.
184
parameters:
@@ -22,15 +8,18 @@ server:
228
- name: handle
239
type: int
2410
description: A handle previous got from [[getLatentEventHandles]].
25-
examples: []
2611
returns:
2712
values:
2813
- type: table
2914
name: result
30-
description: 'Returns a [[table]] with the following info, otherwise **false** if invalid arguments were passed:'
31-
15+
description: 'Returns a [[table]] with the following info, otherwise **false** if invalid arguments
16+
were passed.'
17+
3218
client:
19+
<<: *shared
20+
ignore_parameters:
21+
- thePlayer
3322
examples:
3423
- path: examples/getLatentEventStatus-1.lua
3524
description: The example starts a latent event and outputs the status of the transfer
36-
to the client console
25+
to the client console.

functions/Event/removeEventHandler.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
shared:
1+
shared: &shared
22
name: removeEventHandler
33
description: This functions removes a handler function from an [event](/reference/Event_System
44
"Event"), so that the function is not called anymore when the event is triggered.
@@ -11,7 +11,7 @@ shared:
1111
- name: attachedTo
1212
type: element
1313
description: The [[element]] the handler was attached to.
14-
- name: functionVar
14+
- name: functionVar()
1515
type: function
1616
description: The handler function that was attached.
1717
returns:
@@ -23,6 +23,7 @@ shared:
2323
were passed.
2424

2525
client:
26+
<<: *shared
2627
examples:
2728
- path: examples/removeEventHandler-1.lua
2829
description: This example shows how to toggle a message on/off a screen with a

functions/Event/triggerClientEvent.yaml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@ server:
33
description: |
44
This function triggers an event previously registered on a client.
55
This is the primary means of passing information between the server and the client.
6-
Clients have a similar [triggerServerEvent](/reference/triggerServerEvent "TriggerServerEvent")
7-
function that can do the reverse. You can treat this function as if it was an
8-
asynchronous function call, using [triggerServerEvent](/reference/triggerServerEvent
9-
"TriggerServerEvent") to pass back any returned information if necessary.
10-
11-
Almost any data types can be passed as expected, including [elements](/reference/Element "Element") and complex nested [tables](/reference/table "Table"). Non-element MTA data types like [xmlNodes](/reference/xmlnode "XML Node") or resource pointers will not be able to be passed as they do not necessarily have a valid representation on the client.
12-
13-
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.
14-
15-
Keep in mind the bandwidth issues when using events - don't pass a large list of arguments unless you really need to. It is marginally more efficient to pass one large event than two smaller ones.
6+
Clients have a similar [[triggerServerEvent]] function that can do the reverse. You can treat this function as if it was an
7+
asynchronous function call, using [[triggerServerEvent]] to pass back any returned information if necessary.
168
parameters:
179
- name: sendTo
1810
type: 'table/element'
1911
description: The event will be sent to all [players](/reference/player "Player") that are children of the specified element. By default this is the [root](/reference/root "Root") element, and hence the event is sent to all players. If you specify a single player it will just be sent to that player. This argument can also be a table of player elements.
20-
default: getRootElement(
12+
default: getRootElement()
2113
- name: name
2214
type: string
2315
description: 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]].
@@ -44,17 +36,20 @@ server:
4436
arguments were specified.
4537
notes:
4638
- type: info
47-
content: It is marginally more efficient to pass one large event than two smaller
48-
ones.
39+
content: |
40+
- Almost any data types can be passed as expected, including [elements](/reference/Element "Element") and complex nested [tables](/reference/table "Tables"). Non-element MTA data types like [xmlNodes](/reference/xmlnode "XML Node") or resource pointers will not be able to be passed as they do not necessarily have a valid representation on the client. **Elements of the [Vector](/reference/Vector "Vector") or [Matrix](/reference/Matrix "Matrix") classes cannot be passed!**
41+
- 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.
42+
- Keep in mind the bandwidth issues when using events - don't pass a large list of arguments unless you really need to. It is marginally more efficient to pass one large event than two smaller ones.
4943
- type: important
5044
content: |
51-
- Non-element MTA data types like [xmlNodes](/reference/xmlnode "XML Node") or resource pointers will not
52-
be able to be passed as they do not necessarily have a valid representation
53-
on the client.
54-
- To save client CPU, you should avoid setting theElement to the [root](/reference/root "Root") element
45+
To save client CPU, you should avoid setting theElement to the [root] element
5546
where possible - it should be used as a last resort (rather questionable thing
56-
to do, limited to very specific tasks, if any). Using target element ( [player](/reference/player "Player")
47+
to do, limited to very specific tasks, if any). Using target element [[player]]
5748
who should receive event, if expected to be delivered to particular one) is
58-
preferred and highly advisable. [resourceRoot](/reference/resourceRoot "ResourceRoot") can also be used as alternative
59-
choice, if [addEventHandler](/reference/addEventHandler "addEventHandler") is bound to [root](/reference/root "Root") element, or to [resourceRoot](/reference/resourceRoot "ResourceRoot") when
60-
there is need to restrict event to single certain resource.
49+
preferred and highly advisable. [[resourceRoot]] can also be used as alternative
50+
choice, if [[addEventHandler]] is bound to [[root]] element, or to [[resourceRoot]] when
51+
there is need to restrict event to single certain resource.
52+
meta:
53+
- changelog:
54+
- version: 1.3.0-9.04570
55+
description: Added option to use a list of player elements for the **sendTo** argument.

functions/Event/triggerEvent.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ shared:
44
a specific [[element]] in the [element tree](/reference/Element_tree
55
"Element tree"). See [event system](/reference/Event_System "Event System") for more
66
information on how the event system works.
7-
You can use the value returned from this function to determine if the event was cancelled by one of the event handlers. You should determine what your response (if any) to this should be based on the event's purpose. Generally, cancelling an event should prevent any further code being run that is dependent on whatever triggered that event. For example, if you have an onFlagCapture event, cancelling it would be expected to prevent the flag being able to be captured. Similarly, if you have onPlayerKill as an event you trigger, canceling it would either be expected to prevent the player being killed from dying or at least prevent the player from getting a score for it.
7+
8+
You can use the value returned from this function to determine if the event was cancelled by one of the event handlers. You should determine what your response (if any) to this should be based on the event's purpose. Generally, cancelling an event should prevent any further code being run that is dependent on whatever triggered that event. For example, if you have an `onFlagCapture` event, cancelling it would be expected to prevent the flag being able to be captured. Similarly, if you have `onPlayerKill` as an event you trigger, canceling it would either be expected to prevent the player being killed from dying or at least prevent the player from getting a score for it.
89
parameters:
910
- name: eventName
1011
type: string
11-
description: The name of the event you wish to trigger
12+
description: The name of the event you wish to trigger.
1213
- name: baseElement
1314
type: element
1415
description: The element you wish to trigger the event on. See [event system](/reference/Event_System "Event System") for

0 commit comments

Comments
 (0)