#meS Posted September 13, 2015 Share Posted September 13, 2015 Hello I'm trying to kill the timer but doesn't work client side function setTimerOnWasted() setTimer( function() guiSetVisible(deathWin,true) end ,30000,0) end addEventHandler("onPlayerWasted",getLocalPlayer(),setTimerOnWasted) --- the place i kill the timer with killTimer(setTimerOnWasted) And yeah I want to ask when player dies will the timer be set for the dead player? Thanks Link to comment
Dimos7 Posted September 13, 2015 Share Posted September 13, 2015 try this: function setTimerOnWasted() timer = setTimer( function() guiSetVisible(deathWin, true) end ,30000,0) end addEventHandler("onClientPlayerWasted", getLocalPlayer(), setTimerOnWasted) killTimer(timer) Link to comment
Rob Posted September 13, 2015 Share Posted September 13, 2015 This is working 100% local timers = {} function setTimerOnWasted() if isTimer(timers) then killTime(timers) end timers = setTimer( function() guiSetVisible(deathWin, true) for k,v in ipairs(timers) do if isTimer(v) then killTimer(v) end end end ,30000,1) end addEventHandler("onClientPlayerWasted", getLocalPlayer(), setTimerOnWasted) Link to comment
#meS Posted September 13, 2015 Author Share Posted September 13, 2015 @rob no no I know it will kill the timer but I want to remove the timer when player clicks button @dimos nope Link to comment
Dimos7 Posted September 13, 2015 Share Posted September 13, 2015 function setTimerOnWasted() timer = setTimer(function() guiSetVisible(deathWin, true) end, 30000, 0) end addEventHandler("onClientPlayerWasted", getLocalPlayer(), setTimerOnWasted) killTimer(timer) Link to comment
Moderators IIYAMA Posted September 13, 2015 Moderators Share Posted September 13, 2015 @#meS Line 11, a timer isn't the same as a function. @Rob A table isn't the same as a timer and a typo on line 3. Only Dimos7 code might work if you(#meS) add the event onClientGUIClick + killTimer part. Which you still haven't posted yet, it is stupid to say that it isn't working when you are not showing everything that is required to finish the code. Link to comment
#meS Posted September 14, 2015 Author Share Posted September 14, 2015 @#meS Line 11, a timer isn't the same as a function. @Rob A table isn't the same as a timer and a typo on line 3. Only Dimos7 code might work if you(#meS) add the event onClientGUIClick + killTimer part. Which you still haven't posted yet, it is stupid to say that it isn't working when you are not showing everything that is required to finish the code. yeah sorry it worked but i want to ask it will be removed for the clicked element? function revPlayer() local playerHealthC = getElementHealth ( clickedElement ) if source == CLP.label[3] then if playerHealthC == 0 then outputChatBox("You Revived "..getPlayerName(clickedElement).." !",255,0,0) triggerServerEvent("ClientSpawnPlayer",clickedElement) killTimer(deathTimer) end end end addEventHandler("onClientGUIClick",root,revPlayer) ( not the full code don't say clicked element is not defined it's already definded ) Link to comment
Moderators IIYAMA Posted September 14, 2015 Moderators Share Posted September 14, 2015 The element(timer) will be destroyed. But the variable will still contain the userdata of the element(timer), which is invalid and can't be considered as a reference to an element. For example: (execute these lines in your code) -- We start a timer: local timer = setTimer(function()end,1000,1) -- We check the timer: outputChatBox("The userdata of the timer: " .. tostring(timer) .. ", is the timer an element: " .. (isTimer(timer) and "yes" or "no") .. "." ) -- Now we destroy it: killTimer(timer) -- And now we check the timer again: outputChatBox("The userdata of the timer: " .. tostring(timer) .. ", is the timer an element: " .. (isTimer(timer) and "yes" or "no") .. "." ) Link to comment
obuhhh Posted September 14, 2015 Share Posted September 14, 2015 ... -- go step by step function setTimerOnWasted() -- the [u][b]function[/b][/u] is named [b]setTimerOnWasted[/b] setTimer( -- creating a timer without variable function() guiSetVisible(deathWin,true) end, 30000, 0) end addEventHandler("onPlayerWasted", getLocalPlayer(), setTimerOnWasted) -- Timer is created [u][b]when a player wasted[/b][/u] killTimer(setTimerOnWasted) -- Timer, destroyed at the start of resources - immediately. -- But timer created when the player wasted. -- Moreover, you try not to destroy the timer. -- You try to destroy the function. -- Generally, you need immediately after wasted the player to open the window. -- And after 30 seconds to close. -- Below is the corrected version of your script. -- But do not think that's what you need. timer_Varible = nil function setTimerOnWasted() -- When a player wasted execute the function. guiSetVisible(deathWin, true) -- Open the window immediately. if timer_Varible then killTimer(timer_Varible) timer_Varible = nil end timer_Varible = setTimer( -- Create a timer that closes in 30 seconds. function() guiSetVisible(deathWin, false) timer_Varible = nil end, 30000, 1) -- After 30,000 milliseconds performed close the window 1 times. If 0, then the eternally every 30,000 milliseconds. end addEventHandler("onPlayerWasted", getLocalPlayer(), setTimerOnWasted) Sorry for my English. It's all Google translator. Link to comment
TAPL Posted September 15, 2015 Share Posted September 15, 2015 onPlayerWasted is server side.. Link to comment
obuhhh Posted September 15, 2015 Share Posted September 15, 2015 onPlayerWasted is server side.. Ohhh... Realy. Then... onClientPlayerWasted timer_Varible = nil function setTimerOnWasted() guiSetVisible(deathWin, true) if timer_Varible then killTimer(timer_Varible) timer_Varible = nil end timer_Varible = setTimer( function() guiSetVisible(deathWin, false) timer_Varible = nil end, 30000, 1) end addEventHandler("on[b]Client[/b]PlayerWasted", getLocalPlayer(), setTimerOnWasted) 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