Skip to content

Commit 54850c3

Browse files
committed
Improvements
1 parent f4ef6e2 commit 54850c3

24 files changed

+96
-152
lines changed

functions/Event/addEvent.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/AddEvent
21
shared:
32
name: addEvent
43
description: This function allows you to register a custom [event](/reference/Event_System "Event").
@@ -11,14 +10,13 @@ shared:
1110
- name: allowRemoteTrigger
1211
type: bool
1312
description: A boolean specifying whether this event can be called remotely using
14-
[triggerClientEvent](/reference/triggerClientEvent "TriggerClientEvent") / [triggerServerEvent](/reference/triggerServerEvent "TriggerServerEvent") or not.
13+
[[triggerClientEvent]] / [[triggerServerEvent]] or not.
1514
default: 'false'
1615
examples:
1716
- path: examples/addEvent-1.lua
18-
description: This example will define a new event calledonSpecialEvent.
17+
description: This example will define a new event.
1918
returns:
2019
values:
2120
- type: bool
22-
name: value
23-
description: Returns true if the event was added successfully, false if the event
24-
was already added.
21+
name: result
22+
description: Returns **true** if the event was added successfully, otherwise **false** if the event already exists **built-in game events** or if it fails for any other reason.

functions/Event/addEventHandler.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/AddEventHandler
21
shared:
32
name: addEventHandler
43
description: This function will add an [event](/reference/Event_System "Event System") handler. An
@@ -32,24 +31,18 @@ shared:
3231
default: 'true'
3332
- name: priority
3433
type: string
35-
description: |
36-
A string representing the trigger order priority relative to other event handlers of the same name. Possible values are:
37-
38-
"high"
39-
"normal"
40-
"low"
34+
description: 'A string representing the trigger order priority relative to other event handlers of the same name. Possible values are:'
35+
templateList: 'event-priority'
4136
default: '"normal"'
4237
examples:
4338
- path: examples/addEventHandler-1.lua
4439
description: This serverside example sends a message to everyone in the server
4540
when a player spawns.
46-
side: server
4741
returns:
4842
values:
4943
- type: bool
50-
name: value
51-
description: Returns true if the event handler was attached successfully. Returns
52-
false if the specified event could not be found or any parameters were invalid.
44+
name: result
45+
description: Returns **true** if the event handler was attached successfully. otherwise **false** if the specified event could not be found or any parameters were invalid.
5346
notes:
5447
- type: info
5548
content: You shouldn't re-use the same name for your handler function as the event
@@ -60,8 +53,7 @@ shared:
6053
content: See [Event Source Element](/reference/Event_Source_Element "Event Source Element") for a descriptive visualization of the event
6154
system handling an event trigger.
6255
- type: important
63-
content: See [Script security](/Script_security "Script security") for how-to prevent cheaters from abusing [event system](/reference/Event_System "Event system")
64-
and [element data](/reference/Element_data "Element data").
56+
content: See [Script security](/Script_security "Script security") for how-to prevent cheaters from abusing [event system](/reference/Event_System "Event system").
6557
- type: important
6658
content: Anything bound to a specific element will be run before other handlers
6759
that are bound to something higher in the element tree (like root) This means

functions/Event/cancelEvent.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/CancelEvent
21
shared:
32
name: cancelEvent
4-
description: This function is used to stop the automatic internal handling of events,
5-
for example this can be used to prevent an item being given to a player when they
6-
walk over a pickup, by canceling the [onPickupUse](/reference/onPickupUse "OnPickupUse")
3+
description: This function is used to stop the automatic internal handling of events
74
event.
85
parameters: []
96
returns:
107
values:
118
- type: bool
129
name: value
13-
description: Always returns true .
10+
description: Always returns **true**.
1411

1512
client:
1613
examples:
1714
- path: examples/cancelEvent-2.lua
1815
description: This example prevents any damage to a player clientside by making **cancelEvent** an
19-
event handler for the [onClientPlayerDamage](/reference/onClientPlayerDamage "OnClientPlayerDamage") event.
16+
event handler for the [[onClientPlayerDamage]] event.
2017

2118
server:
22-
name: cancelEvent
23-
description: This function is used to stop the automatic internal handling of events,
24-
for example this can be used to prevent an item being given to a player when they
25-
walk over a pickup, by canceling the [onPickupUse](/wiki/OnPickupUse "OnPickupUse")
26-
event.
2719
parameters:
2820
- name: cancel
2921
type: bool
@@ -39,5 +31,5 @@ server:
3931
returns:
4032
values:
4133
- type: bool
42-
name: value
43-
description: Always returns true .
34+
name: result
35+
description: Returns **true**, otherwise **false** if parameters are invalid.
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
1-
# Scraped from: https://wiki.multitheftauto.com/wiki/CancelLatentEvent
21
shared:
32
name: cancelLatentEvent
43
description: Stops a latent event from completing
54
parameters:
65
- name: handle
76
type: int
8-
description: A handle previous got from [getLatentEventHandles](/reference/getLatentEventHandles "GetLatentEventHandles").
7+
description: A handle previous got from [[getLatentEventHandles]].
98
examples:
109
- path: examples/cancelLatentEvent-1.lua
1110
description: ''
12-
side: client
13-
- path: examples/cancelLatentEvent-4.lua
14-
description: ''
15-
side: client
1611
returns:
1712
values:
1813
- type: bool
19-
name: value
20-
description: Returns a true if the latent event was successfully cancelled, or
21-
false if it was not
14+
name: result
15+
description: Returns a **true** if the latent event was successfully cancelled, otherwise **false**.
2216

2317
server:
24-
name: cancelLatentEvent
25-
description: Stops a latent event from completing
2618
parameters:
2719
- name: thePlayer
2820
type: player
2921
description: The player who is receiving the event.
3022
- name: handle
3123
type: int
32-
description: A handle previous got from [getLatentEventHandles](/reference/getLatentEventHandles "GetLatentEventHandles").
24+
description: A handle previous got from [[getLatentEventHandles]].
3325
examples:
34-
- path: examples/cancelLatentEvent-2.lua
35-
description: ''
36-
side: server
3726
- path: examples/cancelLatentEvent-3.lua
38-
description: ''
39-
side: server
27+
description: "Cancel all my triggerLatentClientEvent's"
4028
returns:
4129
values:
4230
- type: bool
43-
name: value
44-
description: Returns a true if the latent event was successfully cancelled, or
45-
false if it was not
31+
name: result
32+
description: Returns a **true** if the latent event was successfully cancelled, otherwise **false**.
33+
34+
client:
35+
examples:
36+
- path: examples/cancelLatentEvent-2.lua
37+
description: "Cancel all my triggerLatentServerEvent's"
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
-- Add a new event called onSpecialEvent
22
addEvent ( "onSpecialEvent", true )
3-
43
-- Define our handler function, that takes a "text" parameter and outputs it to the chatbox
54
function specialEventHandler ( text )
65
outputChatBox ( text )
76
end
8-
97
-- Add it as a handler for our event
108
addEventHandler ( "onSpecialEvent", root, specialEventHandler )
11-
129
-- You can then trigger this event later on using:
1310
triggerEvent ( "onSpecialEvent", root, "test" )
1411
-- This will cause the handler to be triggered, so "test" will be output to the chatbox.

functions/Event/examples/addEventHandler-1.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ function onPlayerSpawnHandler ( )
55
-- output in the chat box that they've spawned
66
outputChatBox ( playerName .. " has spawned!" )
77
end
8-
98
addEventHandler( "onPlayerSpawn", root, onPlayerSpawnHandler ) -- root is a predefined global variable for getRootElement()
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
-- Cancel triggerLatentServerEvent directly after execution.
1+
-- *****************************************************************************
2+
-- CLIENT CODE
23
addCommandHandler("cancelLatentEvent",
34
function ()
45
triggerLatentServerEvent("exampleEvent",3000,false,localPlayer)
5-
6-
-- Get all your active handles, when you executed the command: /cancelLatentEvent
76
local handles = getLatentEventHandles() -- Returns a table.
8-
97
local handle = handles[#handles] -- Get the latest handle.
108

119
if cancelLatentEvent(handle) then -- Cancel it!
1210
outputChatBox("Successfully cancelled!",0,200,0)
1311
end
12+
end)
13+
14+
-- *****************************************************************************
15+
-- SERVER CODE
16+
addEvent("exampleEvent",true)
17+
addEventHandler("exampleEvent",root,
18+
function ()
19+
outputChatBox("Warning! The triggerLatentServerEvent wasn't cancelled!",client,255,0,0) -- warn the user.
1420
end)
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
addEvent("exampleEvent",true)
2-
addEventHandler("exampleEvent",root,
3-
function ()
4-
outputChatBox("Warning! The triggerLatentServerEvent wasn't cancelled!",client,255,0,0) -- warn the user.
1+
addCommandHandler("cancelLatentEvents",
2+
function (player)
3+
local handles = getLatentEventHandles (player) -- Returns a table.
4+
5+
for index=1,#handles do -- Loop through the table.
6+
local handle = handles[index]
7+
cancelLatentEvent(player,handle) -- Cancel it!
8+
end
59
end)
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
-- Cancel all my triggerLatentClientEvent's.
21
addCommandHandler("cancelLatentEvents",
3-
function (player)
4-
5-
-- Get all active handles from the player that executed the command: /cancelLatentEvents
6-
local handles = getLatentEventHandles (player) -- Returns a table.
2+
function ()
3+
local handles = getLatentEventHandles () -- Returns a table.
74

85
for index=1,#handles do -- Loop through the table.
9-
local handle = handles[index]
10-
cancelLatentEvent(player,handle) -- Cancel it!
6+
local handle = handles[index]
7+
cancelLatentEvent(handle) -- Cancel it!
118
end
129
end)

functions/Event/examples/cancelLatentEvent-4.lua

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)