Jump to content

Timer doesn't get killed


BriGhtx3

Recommended Posts

drugtimerrest = {} 
  
function timerAnzeigen() -- when I click the OK btn 
    guiSetVisible(Drugs_Window,false) 
    guiSetVisible(Create_Window,true) 
    restminuten = 20 
    guiSetText(Create_LBL_Timer, tonumber(restminuten).." Minuten") 
    drugtimerrest[getLocalPlayer()] = setTimer(updateTimerZeit,1000,0,getLocalPlayer()) 
end 
  
  
function updateTimerZeit(player) 
    restminuten = restminuten - 1 
    if restminuten <= 0 then 
        killTimer(drugtimerrest[player]) 
        drugtimerrest[player] = nil 
        guiSetVisible(Create_Window,false) 
    else 
        guiSetText(Create_LBL_Timer, tonumber(restminuten).." Minuten") 
    end 
end 
  
function abbrDr() -- when I click the cancel btn 
    killTimer(drugtimerrest[source]) 
    drugtimerrest[source] = nil 
end 
addEventHandler("onClientPlayerQuit",getRootElement(),abbrDr) 

My problem is that when I click the cancel btn, the gui gets invisible, but the timer seems not to get stopped.

When I click the OK Btn again, the timer gets even faster, and when I repeat it, the timer counts three times faster than normal...

The error after the "real" timer is finished is:

[b]Bad argument at killTimer [Expected lua-timer at argument 1, got nil][/b] 

This is the line :

killTimer(drugtimerrest[player]) 

Link to comment
local tDrugTimer = { } 
  
function timerAnzeigen ( ) 
    guiSetVisible ( Drugs_Window, false ) 
    guiSetVisible ( Create_Window, true ) 
    time = 20 
    guiSetText ( Create_LBL_Timer, tonumber ( time ) .. ' Minuten' ) 
    tDrugTimer [ localPlayer ] = setTimer ( updateTimerZeit, 1000, 0, localPlayer ) 
end 
  
function updateTimerZeit ( player ) 
    time = time - 1 
    if ( time <= 0 ) then 
        killTimer ( tDrugTimer [ player ] ) 
        guiSetVisible ( Create_Window, false ) 
    else 
        guiSetText ( Create_LBL_Timer, tonumber ( time ) .. ' Minuten' ) 
    end 
end 
  
addEventHandler ( 'onClientPlayerQuit', root, 
    function ( ) 
        if ( isTimer ( tDrugTimer [ source ] ) ) then 
            tDrugTimer [ source ] = nil 
        end 
    end 
) 

Edited by Guest
Link to comment
drugtimerrest[getLocalPlayer()] 

function abbrDr() -- when I click the cancel btn 
    killTimer(drugtimerrest[localPlayer]) 
    drugtimerrest[localPlayer] = nil 
end 
addEventHandler("onClientPlayerQuit",getRootElement(),abbrDr) 

:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o:o

Edited by Guest
Link to comment
@Draken its still the same

@Tapl that isn't the error, because I tried both.

dude look at your code

function abbrDr() -- when I click the cancel btn 
    killTimer(drugtimerrest[localPlayer]) 
    drugtimerrest[localPlayer] = nil 
end 
addEventHandler("onClientPlayerQuit",getRootElement(),abbrDr) 

it's realy mess

it's client side! why you need to store local player element in table?

and killTimer when the localPlayer left? LOL!

Link to comment

somethings like this maybe

local drugtimerrest 
  
function timerAnzeigen() -- when I click the OK btn 
    guiSetVisible(Drugs_Window,false) 
    guiSetVisible(Create_Window,true) 
    restminuten = 20 
    guiSetText(Create_LBL_Timer, tonumber(restminuten).." Minuten") 
    if isTimer(drugtimerrest) then killTimer(drugtimerrest) end 
    drugtimerrest = setTimer(updateTimerZeit,1000,0) 
end 
  
function updateTimerZeit() 
    restminuten = restminuten - 1 
    if restminuten <= 0 then 
        if isTimer(drugtimerrest) then killTimer(drugtimerrest) end 
        guiSetVisible(Create_Window,false) 
    else 
        guiSetText(Create_LBL_Timer, tonumber(restminuten).." Minuten") 
    end 
end 

if you tell us what you trying to make we will be able to help you better

Link to comment

Not necessarily create table in client side for control timers. But if you create infinite timers in server side you should use tables and index for ex player or what you want for remove timer. So for example you create timer check something ( time playing, .. ). Example 10 players joined to server then created 10 timers . So you should clean timer if player quit ( in this case ) if you not create it your server ( will lag, because timers not killed ).

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