GetLatentEventHandles: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 28: Line 28:
function ()
function ()
triggerLatentServerEvent("exampleEvent",3000,false,localPlayer)
triggerLatentServerEvent("exampleEvent",3000,false,localPlayer)
local handles = getLatentEventHandles()
 
-- Get all active handles from you, when you executed the command: cancelLatentEvent
local handles = getLatentEventHandles() -- Returns a table.
 
local handle = handles[#handles] -- Get the latest handle.
local handle = handles[#handles] -- Get the latest handle.
if cancelLatentEvent(handle) then -- Cancel it!
if cancelLatentEvent(handle) then -- Cancel it!
outputChatBox("Successfully cancelled!",0,200,0)
outputChatBox("Successfully cancelled!",0,200,0)
Line 55: Line 59:


-- Get all active handles from the player that executed the command: cancelLatentEvents
-- Get all active handles from the player that executed the command: cancelLatentEvents
local handles = getLatentEventHandles (player)  
local handles = getLatentEventHandles (player) -- Returns a table.
for index=1,#handles do -- Loop through the table.
for index=1,#handles do -- Loop through the table.
Line 71: Line 75:


-- Get all active handles from you, when you executed the command: cancelLatentEvents
-- Get all active handles from you, when you executed the command: cancelLatentEvents
local handles = getLatentEventHandles ()  
local handles = getLatentEventHandles () -- Returns a table.
for index=1,#handles do -- Loop through the table.
for index=1,#handles do -- Loop through the table.

Revision as of 11:54, 30 October 2015

Gets the currently queued latent events. The last one in the table is always the latest event queued. Each returned handle can be used with getLatentEventStatus or cancelLatentEvent

Syntax

Click to collapse [-]
Server
table getLatentEventHandles ( player thePlayer )

Required Arguments

  • thePlayer: The player who is receiving the events.
Click to collapse [-]
Client
table getLatentEventHandles ( )

Returns

Returns a table of handles or false if invalid arguments were passed.

Example

Click to collapse [-]
Example 1 - 1/2
-- Cancel triggerLatentServerEvent directly after execution.
addCommandHandler("cancelLatentEvent",
function ()
	triggerLatentServerEvent("exampleEvent",3000,false,localPlayer)

	-- Get all active handles from you, 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/2
addEvent("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 active handles from you, 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)

Requirements

This template will be deleted.

See Also