CancelLatentEvent: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Server client function}} Stops a latent event from completing ==Syntax== Server: <syntaxhighlight lang="lua"> table cancelLatentEvent( player thePlayer, int handle ) </syntaxhighlight> Client: ...") |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 4: | Line 4: | ||
==Syntax== | ==Syntax== | ||
Server | <section name="Server" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool cancelLatentEvent( player thePlayer, int handle ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Client | ===Required Arguments=== | ||
*'''thePlayer:''' The player who is receiving the event. | |||
*'''handle:''' A handle previous got from [[getLatentEventHandles]]. | |||
</section> | |||
<section name="Client" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool cancelLatentEvent( int handle ) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''handle:''' A handle previous got from [[getLatentEventHandles]]. | *'''handle:''' A handle previous got from [[getLatentEventHandles]]. | ||
</section> | |||
===Returns=== | ===Returns=== | ||
Line 21: | Line 25: | ||
==Example== | ==Example== | ||
<section name="Example 1 - 1/2" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | -- Cancel triggerLatentServerEvent directly after execution. | ||
addCommandHandler("cancelLatentEvent", | |||
function () | |||
triggerLatentServerEvent("exampleEvent",3000,false,localPlayer) | |||
-- Get all your active handles, when you executed the command: /cancelLatentEvent | |||
local handles = getLatentEventHandles() -- Returns a table. | |||
local handle = handles[#handles] -- Get the latest handle. | |||
if cancelLatentEvent(handle) then -- Cancel it! | |||
outputChatBox("Successfully cancelled!",0,200,0) | |||
end | |||
end) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
== | <section name="Example 1 - 2/2" class="server" show="true"> | ||
<syntaxhighlight lang="lua"> | |||
addEvent("exampleEvent",true) | |||
addEventHandler("exampleEvent",root, | |||
function () | |||
outputChatBox("Warning! The triggerLatentServerEvent wasn't cancelled!",client,255,0,0) -- warn the user. | |||
end) | |||
</syntaxhighlight> | |||
</section> | |||
<section name="Example 2" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
-- Cancel all my triggerLatentClientEvent's. | |||
addCommandHandler("cancelLatentEvents", | |||
function (player) | |||
-- Get all active handles from the player that executed the command: /cancelLatentEvents | |||
local handles = getLatentEventHandles (player) -- Returns a table. | |||
for index=1,#handles do -- Loop through the table. | |||
local handle = handles[index] | |||
cancelLatentEvent(player,handle) -- Cancel it! | |||
end | |||
end) | |||
</syntaxhighlight> | |||
</section> | |||
<section name="Example 3" class="client" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
-- Cancel all my triggerLatentServerEvent's. | |||
addCommandHandler("cancelLatentEvents", | |||
function () | |||
-- Get all your active handles, when you executed the command: /cancelLatentEvents | |||
local handles = getLatentEventHandles () -- Returns a table. | |||
for index=1,#handles do -- Loop through the table. | |||
local handle = handles[index] | |||
cancelLatentEvent(handle) -- Cancel it! | |||
end | |||
end) | |||
</syntaxhighlight> | |||
</section> | |||
==See Also== | ==See Also== | ||
{{Event functions}} | {{Event functions}} |
Latest revision as of 15:45, 7 November 2024
Stops a latent event from completing
Syntax
Click to collapse [-]
Serverbool cancelLatentEvent( player thePlayer, int handle )
Required Arguments
- thePlayer: The player who is receiving the event.
- handle: A handle previous got from getLatentEventHandles.
Click to collapse [-]
Clientbool cancelLatentEvent( int handle )
Required Arguments
- handle: A handle previous got from getLatentEventHandles.
Returns
Returns a true if the latent event was successfully cancelled, or false if it was not
Example
Click to collapse [-]
Example 1 - 1/2-- Cancel triggerLatentServerEvent directly after execution. addCommandHandler("cancelLatentEvent", function () triggerLatentServerEvent("exampleEvent",3000,false,localPlayer) -- Get all your active handles, when you executed the command: /cancelLatentEvent local handles = getLatentEventHandles() -- Returns a table. local handle = handles[#handles] -- Get the latest handle. if cancelLatentEvent(handle) then -- Cancel it! outputChatBox("Successfully cancelled!",0,200,0) end end)
Click to collapse [-]
Example 1 - 2/2addEvent("exampleEvent",true) addEventHandler("exampleEvent",root, function () outputChatBox("Warning! The triggerLatentServerEvent wasn't cancelled!",client,255,0,0) -- warn the user. end)
Click to collapse [-]
Example 2-- Cancel all my triggerLatentClientEvent's. addCommandHandler("cancelLatentEvents", function (player) -- Get all active handles from the player that executed the command: /cancelLatentEvents local handles = getLatentEventHandles (player) -- Returns a table. for index=1,#handles do -- Loop through the table. local handle = handles[index] cancelLatentEvent(player,handle) -- Cancel it! end end)
Click to collapse [-]
Example 3-- Cancel all my triggerLatentServerEvent's. addCommandHandler("cancelLatentEvents", function () -- Get all your active handles, when you executed the command: /cancelLatentEvents local handles = getLatentEventHandles () -- Returns a table. for index=1,#handles do -- Loop through the table. local handle = handles[index] cancelLatentEvent(handle) -- Cancel it! end end)
See Also
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled