Jump to content

Kill timer


#meS

Recommended Posts

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

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
  • Moderators

@#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 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

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
...
  
-- 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
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

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...