Timer save
#1

So basicly the tittle says everything. I wanted to know how i could create timer saves for these 2 timers.

PHP код:
 g_var[playerid] = 1;
            
SetTimerEx("CountDown",1200*1000false"d"playerid); 
PHP код:
    if(Fished[playerid] >= 5)
    {
        
Fished[playerid] = 0;
        
FishTime[playerid] = 60*5;
        
SetTimerEx("FishingTime"1000false"i"playerid);
    } 
Thanks in advance.
Reply
#2

Just create two variables on top of your script and use them to store the ID of your timers.
Reply
#3

Oh i wrote wrongfully i am sorry the thing is that the timers are working but when player exits the game and rejoins few seconds later the timer is set to 0 so i want to find a way how to freeze the timer on player leaving and unfreeze the timer on reconnect.
Reply
#4

Store the total time in a variable and run your timer every second or so.
Instead of creating a timer that has a delay of 1200*1000, store that value in the variable.
Everytime the timer runs, check if the value is higher than 1, and if it is, substract 1 from the value in the variable.

When he logs out, you can just save the current value stored in that variable.
When he logs back in, load the value from file/MySQL/whatever and store it in the variable again.
If it's higher than 1, run the timer again every second.

Whenever the value reaches 0, the total time has passed after which you can do whatever you want with it.
Just be careful with this.
If you always check if your timer-variable is at 0 to do something, don't do it that way.
Otherwise your condition will always be true, as value 0 would be the lowest value stored in that variable.

Just do whatever you wanna do once the timer reached 1 and goes to 0 during that iteration of the timer.



In my own scripts, I have several global timers running, including a jail-timer, and those timers run for all players all the time.
That one runs every second, and when a player's jailed, I set the jailtime value to 60 for that player.
Every second, his jailtime is also stored in the database in case he logs out or gets kicked or whatever.
After logging back in, the saved value is stored in the jailtime variable again and the timer automatically sees it.

I even have code in there that puts the player back in jail if he managed to get out somehow.
So the longest his efforts go to escape jail, he's being put inside jail again in less than a second.

This way, you have total control of your timer if you want to.
I also have code in there that checks if the player is in class-selection, and if he is, the jailtime variable isn't decreased every second.
As soon as he spawns again, the timer automatically checks if his jailtime hasn't passed yet and puts him back in jail.
Only when the player is in jail, the jailtime variable is decreased every second and updated in the database.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)