Jump to content

 cancelLatentEvent


Fabioxps

Recommended Posts

I want to cancel what is being sent.

  
local mycode = [ ..., code ] 
triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
  
  
addCommandHandler("cancel",function() 
local table = getLatentEventHandles ( player  ) 
local handler = table[#table] 
if handler then 
 cancelLatentEvent( handler ) 
 outputChatBox(tostring(getLatentEventStatus( handler)["percentComplete"])) 
end 
end) 
  

Link to comment
cancelLatentEvent( player thePlayer, int handle ) 

check the syntax for serverside

syntax is player is correct?

local mycode = [ ..., code ] 
triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
  
  
addCommandHandler("cancel",function() 
local table = getLatentEventHandles ( player  ) 
local handler = table[#table] 
if handler then 
 cancelLatentEvent( player, handler ) 
 outputChatBox(tostring(getLatentEventStatus( handler)["percentComplete"])) 
end 
end) 

Link to comment
local mycode = [ ..., code ] 
triggerLatentClientEvent (localPlayer,"enviarClient",10000,localPlayer,mycode) 
  
  
addCommandHandler("cancel",function() 
local table = getLatentEventHandles ( localPlayer) 
local handler = table[#table] 
if handler then 
 cancelLatentEvent( localPlayer, handler ) 
 outputChatBox(tostring(getLatentEventStatus( handler)["percentComplete"])) 
end 
end) 

'player' not defined. localPlayer = getLocalPlayer(), so used that.

Link to comment
  • Moderators
  
local mycode = "[ ..., code ]" 
  
addCommandHandler("send", 
function(player) 
    triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
 end) 
  
addCommandHandler("cancel", 
function(player) 
    local tableHandlers = getLatentEventHandles ( player  ) 
    if tableHandlers then 
        local handler = tableHandlers[#tableHandlers] 
        if handler then 
            outputChatBox(tostring(getLatentEventStatus(player, handler)["percentComplete"])) 
            cancelLatentEvent(player, handler ) 
             
        end 
    end 
end) 
  
  
  

Lets do it right.

Will cancel the last latency event. But keep in mind that this event can also be from another resource.

So I will recommend you to save those handlers inside a table.

As example:

local playerDataTable = {} 
addCommandHandler("send", 
function(player) 
    triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
    local tableHandlers = getLatentEventHandles ( player  ) 
    if tableHandlers then 
        local handler = tableHandlers[#tableHandlers] 
        if handler then 
            playerDataTable[player] = handler 
        elseif playerDataTable[player] then 
            playerDataTable[player]  = nil 
        end 
    end 
end) 
  
addEventHandler("onPlayerQuit",root, -- clean up the memory. 
function() 
    if playerDataTable[source] then 
        playerDataTable[source] = nil 
    end 
end) 

Link to comment

it cancels and for sending?

  
local mycode = "[ ..., code ]" 
  
[lua]local playerDataTable = {} 
addCommandHandler("send", 
function(player) 
    triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
    local tableHandlers = getLatentEventHandles ( player  ) 
    if tableHandlers then 
        local handler = tableHandlers[#tableHandlers] 
        if handler then 
            playerDataTable[player] = handler 
        elseif playerDataTable[player] then 
            playerDataTable[player]  = nil 
        end 
    end 
end) 
  
  
addCommandHandler("cancel",function() 
    if playerDataTable[source] then 
        playerDataTable[source] = nil 
    end 
end) 

Link to comment
  • Moderators

Keep in mind:

This kind of event can only be cancelled when the event isn't fully complete.

fully complete = fully send

  
  
local mycode = "[ ..., code ]" 
local playerDataTable = {} 
addCommandHandler("send", 
function(player) 
    triggerLatentClientEvent (player,"enviarClient",10000,player,mycode) 
    local tableHandlers = getLatentEventHandles ( player  ) 
    if tableHandlers then 
        local handler = tableHandlers[#tableHandlers] 
        if handler then 
            playerDataTable[player] = handler 
        elseif playerDataTable[player] then 
            playerDataTable[player]  = nil 
        end 
    end 
end) 
  
  
addCommandHandler("cancel", 
function(player) 
    local handler = playerDataTable[player] 
    if handler then 
        local percentComplete = getLatentEventStatus(player, handler)["percentComplete"] 
        if percentComplete and percentComplete ~= 100 then 
            outputChatBox((tonumber(percentComplete) or 0) .. "%",player) 
            cancelLatentEvent(player, handler ) 
        end 
        playerDataTable[player] = nil 
    end 
end) 
  
  
addEventHandler("onPlayerQuit",root, -- clean up the memory. 
function() 
    if playerDataTable[source] then 
        playerDataTable[source] = nil 
    end 
end) 

Link to comment

after canceling can no longer use the triggerEvent that was canceled?

exemple:

local playerDataTable = {} 
local function functionSend(responseData, errno, source, arg1) 
    if errno == 0 then 
        triggerLatentClientEvent(source,"onClientGotFile",150000,false,source,responseData,arg1); 
        end 
    local tableHandlers = getLatentEventHandles ( source  ) 
    if tableHandlers then 
        local handler = tableHandlers[#tableHandlers] 
        if handler then 
            playerDataTable[source] = handler 
        elseif playerDataTable[source] then 
            playerDataTable[source]  = nil 
        end 
    end 
  --  end 
end 
  
addEvent("onClientDownload",true) 
addEventHandler("onClientDownload",root, 
function(arg1) 
  
----- 
--- 
--- 
        finctionSend(data,0,source,arg1); 
    end 
end) 
  
  
function destoryLatentEventForClient(player) 
    local handler = playerDataTable[player] 
    if handler then 
        local percentComplete = getLatentEventStatus(player, handler)--["percentComplete"] 
        if percentComplete and percentComplete ~= 100 then 
            --outputChatBox((tonumber(percentComplete) or 0) .. "%",player) 
            cancelLatentEvent(player, handler ) 
        end 
        playerDataTable[player] = nil 
    end 
end 
addEvent("onClientWantDestroyEvents",true) 
addEventHandler("onClientWantDestroyEvents",getRootElement(),destoryLatentEventForClient) 
  
  
addEventHandler("onPlayerQuit",root, -- clean up the memory. 
function() 
    if playerDataTable[source] then 
        playerDataTable[source] = nil 
    end 
end) 

I want to use the event again

Link to comment
  • Moderators

Every time you trigger an triggerLatentClientEvent there will be a new handler. So you can still trigger another one.

If you cancel the handler, the data will stop reaching the client and the event on clientside won't get triggered for that handler.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...