Skip to content

Commit 756ab8a

Browse files
committed
Event functions
1 parent 59ba757 commit 756ab8a

35 files changed

+352
-312
lines changed

functions/Event/addEvent.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Scraped from: https://wiki.multitheftauto.com/wiki/AddEvent
22
shared:
33
name: addEvent
4-
description: This function allows you to register a custom [event](/wiki/Event "Event").
5-
Custom events function exactly like the built\-in events. See [event system](/wiki/Event_system
4+
description: This function allows you to register a custom [event](/reference/Event_System "Event").
5+
Custom events function exactly like the built\-in events. See [event system](/reference/Event_System
66
"Event system") for more information on the event system.
77
parameters:
88
- name: eventName
@@ -11,19 +11,14 @@ shared:
1111
- name: allowRemoteTrigger
1212
type: bool
1313
description: A boolean specifying whether this event can be called remotely using
14-
triggerClientEvent / triggerServerEvent or not.
14+
[triggerClientEvent](/reference/triggerClientEvent "TriggerClientEvent") / [triggerServerEvent](/reference/triggerServerEvent "TriggerServerEvent") or not.
1515
default: 'false'
1616
examples:
1717
- path: examples/addEvent-1.lua
1818
description: This example will define a new event calledonSpecialEvent.
19-
side: server
20-
- path: examples/addEvent-2.lua
21-
description: 'You can then trigger this event later on using:'
22-
side: server
2319
returns:
2420
values:
2521
- type: bool
2622
name: value
2723
description: Returns true if the event was added successfully, false if the event
2824
was already added.
29-
requires_review: true

functions/Event/addEventHandler.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Scraped from: https://wiki.multitheftauto.com/wiki/AddEventHandler
22
shared:
33
name: addEventHandler
4-
description: This function will add an [event](/wiki/Event "Event") handler. An
4+
description: This function will add an [event](/reference/Event_System "Event System") handler. An
55
event handler is a function that will be called when the event it's attached to
6-
is triggered. See [event system](/wiki/Event_system "Event system") for more information
6+
is triggered. See [event system](/reference/Event_System "Event System") for more information
77
on how the event system works.
88
parameters:
99
- name: eventName
1010
type: string
11-
description: 'The name of the event you want to attach the handler function to.
12-
Note: The maximum allowed length is 100 ASCII characters (that is, English letters
13-
and numerals)'
11+
description: 'The name of the [event](/reference/Event_System "Event System") you want to attach the handler function to.
12+
**Note: The maximum allowed length is 100 ASCII characters (that is, English letters
13+
and numerals)**'
1414
- name: attachedTo
1515
type: element
16-
description: The element you wish to attach the handler to. The handler will only
16+
description: The [element](/reference/Element "Element") you wish to attach the handler to. The handler will only
1717
be called when the event it is attached to is triggered for this element, or
1818
one of its children. Often, this can be the root element (meaning the handler
19-
will be called when the event is triggered for any element).
19+
will be called when the event is triggered for *any* element).
2020
- name: handlerFunction
2121
type: function
2222
description: The handler function you wish to call when the event is triggered.
@@ -25,14 +25,19 @@ shared:
2525
- name: propagate
2626
type: bool
2727
description: A boolean representing whether the handler will be triggered if the
28-
event was propagated down or up the element tree (starting from the source),
28+
event was propagated down or up the [element tree](/reference/Element_tree "Element tree") (starting from the source),
2929
and not triggered directly on attachedTo (that is, handlers attached with this
3030
argument set to false will only be triggered if source == this ). In GUI events
3131
you will probably want to set this to false .
3232
default: 'true'
3333
- name: priority
3434
type: string
35-
description: MISSING_PARAM_DESC
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"
3641
default: '"normal"'
3742
examples:
3843
- path: examples/addEventHandler-1.lua
@@ -52,15 +57,15 @@ shared:
5257
On the same note, for multiple reasons, it isn't a good idea to export the same
5358
functions that you use locally as remote event handlers.
5459
- type: info
55-
content: See Event Source Element for a descriptive visualization of the event
60+
content: See [Event Source Element](/reference/Event_Source_Element "Event Source Element") for a descriptive visualization of the event
5661
system handling an event trigger.
5762
- type: important
58-
content: See Script security for how-to prevent cheaters from abusing event system
59-
and element data .
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").
6065
- type: important
6166
content: Anything bound to a specific element will be run before other handlers
6267
that are bound to something higher in the element tree (like root) This means
63-
that "high+10" bound to root won't trigger before "normal" bound directly to
68+
that "high+10" bound to root **won't** trigger before "normal" bound directly to
6469
an element.
6570
- type: info
6671
content: Due to the additional set of global variables, the event-trigger specific
@@ -73,4 +78,3 @@ shared:
7378
the same issues. It is recommended to adapt a good-natured distancing principle
7479
between code meant to run from local logic in separation to code meant to run
7580
from remote logic.
76-
requires_review: true

functions/Event/cancelEvent.yaml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# Scraped from: https://wiki.multitheftauto.com/wiki/CancelEvent
2-
client:
2+
shared:
33
name: cancelEvent
44
description: This function is used to stop the automatic internal handling of events,
55
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](/wiki/OnPickupUse "OnPickupUse")
6+
walk over a pickup, by canceling the [onPickupUse](/reference/onPickupUse "OnPickupUse")
77
event.
88
parameters: []
9-
examples:
10-
- path: examples/cancelEvent-2.lua
11-
description: This example prevents any damage to a player clientside by makingcancelEventan
12-
event handler for theonClientPlayerDamageevent.
13-
side: client
149
returns:
1510
values:
1611
- type: bool
1712
name: value
1813
description: Always returns true .
19-
requires_review: true
14+
15+
client:
16+
examples:
17+
- path: examples/cancelEvent-2.lua
18+
description: This example prevents any damage to a player clientside by making **cancelEvent** an
19+
event handler for the [onClientPlayerDamage](/reference/onClientPlayerDamage "OnClientPlayerDamage") event.
20+
2021
server:
2122
name: cancelEvent
2223
description: This function is used to stop the automatic internal handling of events,
@@ -26,19 +27,17 @@ server:
2627
parameters:
2728
- name: cancel
2829
type: bool
29-
description: MISSING_PARAM_DESC
30+
description: True to cancel, false to uncancel.
3031
default: 'true'
3132
- name: reason
3233
type: string
33-
description: MISSING_PARAM_DESC
34+
description: The reason for cancelling the event.
3435
default: '""'
3536
examples:
3637
- path: examples/cancelEvent-1.lua
3738
description: This example stops the player from entering a vehicle.
38-
side: server
3939
returns:
4040
values:
4141
- type: bool
4242
name: value
4343
description: Always returns true .
44-
requires_review: true

functions/Event/cancelLatentEvent.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Scraped from: https://wiki.multitheftauto.com/wiki/CancelLatentEvent
2-
client:
2+
shared:
33
name: cancelLatentEvent
44
description: Stops a latent event from completing
55
parameters:
66
- name: handle
77
type: int
8-
description: A handle previous got from getLatentEventHandles .
8+
description: A handle previous got from [getLatentEventHandles](/reference/getLatentEventHandles "GetLatentEventHandles").
99
examples:
1010
- path: examples/cancelLatentEvent-1.lua
1111
description: ''
@@ -19,7 +19,7 @@ client:
1919
name: value
2020
description: Returns a true if the latent event was successfully cancelled, or
2121
false if it was not
22-
requires_review: true
22+
2323
server:
2424
name: cancelLatentEvent
2525
description: Stops a latent event from completing
@@ -29,7 +29,7 @@ server:
2929
description: The player who is receiving the event.
3030
- name: handle
3131
type: int
32-
description: A handle previous got from getLatentEventHandles .
32+
description: A handle previous got from [getLatentEventHandles](/reference/getLatentEventHandles "GetLatentEventHandles").
3333
examples:
3434
- path: examples/cancelLatentEvent-2.lua
3535
description: ''
@@ -43,4 +43,3 @@ server:
4343
name: value
4444
description: Returns a true if the latent event was successfully cancelled, or
4545
false if it was not
46-
requires_review: true

functions/Event/examples/addEvent-1.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ function specialEventHandler ( text )
77
end
88

99
-- Add it as a handler for our event
10-
addEventHandler ( "onSpecialEvent", root, specialEventHandler )
10+
addEventHandler ( "onSpecialEvent", root, specialEventHandler )
11+
12+
-- You can then trigger this event later on using:
13+
triggerEvent ( "onSpecialEvent", root, "test" )
14+
-- This will cause the handler to be triggered, so "test" will be output to the chatbox.

functions/Event/examples/addEvent-2.lua

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
function onVehicleStartEnter()
2-
cancelEvent()
2+
cancelEvent()
33
end
44
addEventHandler("onVehicleStartEnter", root, onVehicleStartEnter)

functions/Event/examples/getLatentEventHandles-1.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- CLIENT SIDE:
2-
1+
-- *****************************************************************************
2+
-- CLIENT CODE
33
local lastTriggerd = false
44

55
addCommandHandler("trigger",function()
@@ -12,8 +12,8 @@ addCommandHandler("trigger",function()
1212
lastTriggerd = #getLatentEventHandles() -- set the lastTriggerd with the id for last event triggerd
1313
end)
1414

15-
-- SERVER SIDE:
16-
15+
-- *****************************************************************************
16+
-- SERVER CODE
1717
addEvent("LatentEventsCheck",true)
1818
addEventHandler("LatentEventsCheck",root,function (thePlayer)
1919
outputChatBox("Latent trigger done from: " .. getPlayerName(thePlayer), root,math.random(255),0,0)

functions/Event/examples/triggerClientEvent-1.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
-- *****************************************************************************
2+
-- SERVER CODE
3+
greetingCommand ( playerSource, commandName )
4+
triggerClientEvent ( playerSource, "onGreeting", playerSource, "Hello World!" )
5+
end
6+
addCommandHandler ( "greet", greetingCommand )
7+
8+
-- *****************************************************************************
9+
-- CLIENT CODE
110
function greetingHandler ( message )
211
outputChatBox ( "The server says: " .. message )
312
end
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
function greetingCommand ( playerSource, commandName )
2-
triggerClientEvent ( playerSource, "onGreeting", playerSource, "Hello World!" )
1+
-- *****************************************************************************
2+
-- SERVER CODE
3+
function greetingCommandOne ( playerSource, commandName, playerName )
4+
if playerName then
5+
local thePlayer = getPlayerFromName ( playerName )
6+
if thePlayer then
7+
triggerClientEvent ( thePlayer, "onGreeting", thePlayer, "Hello World!" )
8+
else
9+
-- invalid player name specified
10+
end
11+
else
12+
-- No player name specified
13+
end
314
end
4-
addCommandHandler ( "greet", greetingCommand )
15+
addCommandHandler ( "greet_one", greetingCommandOne )
16+
17+
-- *****************************************************************************
18+
-- CLIENT CODE
19+
function greetingHandler ( message )
20+
outputChatBox ( "The server says: " .. message )
21+
end
22+
addEvent( "onGreeting", true )
23+
addEventHandler( "onGreeting", localPlayer, greetingHandler )

0 commit comments

Comments
 (0)