Fabioxps Posted August 10, 2014 Share Posted August 10, 2014 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
Moderators IIYAMA Posted August 10, 2014 Moderators Share Posted August 10, 2014 cancelLatentEvent( player thePlayer, int handle ) check the syntax for serverside Link to comment
Fabioxps Posted August 10, 2014 Author Share Posted August 10, 2014 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
Et-win Posted August 10, 2014 Share Posted August 10, 2014 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
Fabioxps Posted August 10, 2014 Author Share Posted August 10, 2014 (edited) this will cancel the event? Edited August 10, 2014 by Guest Link to comment
Et-win Posted August 10, 2014 Share Posted August 10, 2014 Test it? I have really no idea how this codes work, just defining the variables here. Link to comment
Fabioxps Posted August 10, 2014 Author Share Posted August 10, 2014 is possible to cancel a specific event? Link to comment
Moderators IIYAMA Posted August 10, 2014 Moderators Share Posted August 10, 2014 Client + cancelLatentEvent = no defining player I was thinking you were using it severside. Link to comment
Fabioxps Posted August 10, 2014 Author Share Posted August 10, 2014 Client + cancelLatentEvent = no defining playerI was thinking you were using it severside. yes is serve-side Link to comment
Moderators IIYAMA Posted August 10, 2014 Moderators Share Posted August 10, 2014 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
Fabioxps Posted August 11, 2014 Author Share Posted August 11, 2014 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 IIYAMA Posted August 11, 2014 Moderators Share Posted August 11, 2014 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
Fabioxps Posted August 19, 2014 Author Share Posted August 19, 2014 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 IIYAMA Posted August 20, 2014 Moderators Share Posted August 20, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now