Timer running after logout
#1

So alright Ive set up a small timer that repeats itself every 5 minutes, the problem is the timer doesnt actualy stop when you logout

PHP код:
SetTimerEx("SavePlayerAccountTimer",300000,true,"i",playerid);
forward SavePlayerAccountTimer(playerid);
public 
SavePlayerAccountTimer(playerid) {
    
SavePlayerAccount(playerid);
    
Msg(playerid,COLOR_RED,"Your account has been automaticly saved");
    print(
"hi");
    return 
true;

How do I know its a timer? Ive set up a small print there, its being called every 5 minutes no matter if you logged off or not

Now there are no problems with SavePlayerAccount which I use all the time, but the timer itself tends to run eventho you arent online

I know simple resolution would be to check if he is online or not and the if false to kill the timer, or just kill in under OnPlayerDisconnect, but why does it happen?


EDIT: Just to add up, of course it starts when you login and then just works no matter if you are there or not
Reply
#2

new Timer;
Timer = SetTimerEx("SavePlayerAccountTimer",300000,true,"i ",playerid);
Kill(Timer);
Reply
#3

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
new Timer;
Timer = SetTimerEx("SavePlayerAccountTimer",300000,true,"i ",playerid);
Kill(Timer);
Read before you post. I know how to stop It, im asking why is this even happening.
Reply
#4

because its sets to 'true' so never stops
Reply
#5

Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
Read before you post. I know how to stop It, im asking why is this even happening.
Its happening coz you are not stopping it..
Playerid 0 logs in and timer starts saving for id 0 forever coz you dont kill the timer.
When next player gets id 0, there will be 2 timers doing this.
Reply
#6

Alright, I am willing to give one full(Hopefully) answer. The timer is set to repeat = true which makes the timer repeating untill killed. You are not saving the timer ID upon starting it , therefore the timer id is not possible to be discovered because once used a timer ID it won't be used again. The right way is to create this timer using a PVar or new SomeVar[MAX_PLAYERS] and you should start it like SomeVar[playerid] = SetTimerEx("func", _, _,.....); or with the PVar however I prefer using SomeVar[playerid] type. If you make it to check if the player id is online it wouldn't work again because every time a player disconnect and someone else take this ID he will have two timers working for him therefore taking every doubled or if he do it again tripled etc. etc. and he can get up to 100 timers and more just on his ID. That's why you should save the timer ID upon starting it and kill it once it is not needed.
Reply
#7

Aha I think I get it, altho I thought the timer would get turned off same time as the player goes offline. Thanks for the help
Reply
#8

Timer isn't bound to the player even tho you pass the playerid parameter, it's simply an integer for the timer, so it should be killed manually.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)