GetLatentEventHandles: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Remove obsolete Requirements section)
 
(6 intermediate revisions by 4 users not shown)
Line 21: Line 21:
Returns a table of handles or false if invalid arguments were passed.
Returns a table of handles or false if invalid arguments were passed.


==Example==
==Example==  
<section name="Example 1 - 1/2" class="client" show="true">
This command is triggering an latent-event to server, and if you write the command again and the trigger still didn't end then you have to wait.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- 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
-- CLIENT SIDE:
local handles = getLatentEventHandles() -- Returns a table.


local handle = handles[#handles] -- Get the latest handle.
local lastTriggerd = false


if cancelLatentEvent(handle) then -- Cancel it!
addCommandHandler("trigger",function()
outputChatBox("Successfully cancelled!",0,200,0)
local triggers = getLatentEventHandles() -- get all latent events
end
if triggers[lastTriggerd] then -- you can use (getLatentEventStatus) too!
outputChatBox("Wait until the trigger ("..lastTriggerd..") ends!",255,0,0)
return
end  
triggerLatentServerEvent("LatentEventsCheck",20000,resourceRoot,localPlayer)
lastTriggerd = #getLatentEventHandles() -- set the lastTriggerd with the id for last event triggerd
end)
end)
</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>


-- SERVER SIDE:


<section name="Example 2" class="server" show="true">
addEvent("LatentEventsCheck",true)
<syntaxhighlight lang="lua">
addEventHandler("LatentEventsCheck",root,function (thePlayer)
-- Cancel all my triggerLatentClientEvent's.
outputChatBox("Latent trigger done from: " .. getPlayerName(thePlayer), root,math.random(255),0,0)  
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)
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>
</syntaxhighlight>
</section>
==Requirements==
{{Requirements|1.3.0-9.03772|1.3.0-9.03772|}}


==See Also==
==See Also==
{{Event functions}}
{{Event functions}}

Latest revision as of 15:45, 7 November 2024

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

This command is triggering an latent-event to server, and if you write the command again and the trigger still didn't end then you have to wait.


-- CLIENT SIDE:

local lastTriggerd = false 

addCommandHandler("trigger",function()
	local triggers = getLatentEventHandles() -- get all latent events
	if triggers[lastTriggerd] then -- you can use (getLatentEventStatus) too!
		outputChatBox("Wait until the trigger ("..lastTriggerd..") ends!",255,0,0)
		return 
	end 
	triggerLatentServerEvent("LatentEventsCheck",20000,resourceRoot,localPlayer)
	lastTriggerd = #getLatentEventHandles() -- set the lastTriggerd with the id for last event triggerd
end)

-- SERVER SIDE:

addEvent("LatentEventsCheck",true)
addEventHandler("LatentEventsCheck",root,function (thePlayer)
	outputChatBox("Latent trigger done from: " .. getPlayerName(thePlayer), root,math.random(255),0,0) 
end)

See Also