SA-MP Forums Archive
save the time left of a timer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: save the time left of a timer (/showthread.php?tid=361562)



save the time left of a timer - Jstylezzz - 21.07.2012

Hey eveyone,

Like the topic title says, I want to save the time the timer has left in my players mysql row.
I know how to save into the mysql, row, that is not the problem, the problem is, that i don't know how to get the time left of the timer.
It's about the payday, i want to save the time left on disconnect, and set the timer when he spawns, with the time in his account row.
I also want to show the time left in the players stats message...

is there anyone who can make a stock/public function, or someone who can give me a hint on how to get hold of the time left?

Thanks alot


Re: save the time left of a timer - Cjgogo - 21.07.2012

Here's an example,you need to code the timer like this:

pawn Code:
new countn[MAX_PLAYERS];//It will count down,or normally,as you choose..
forward TimerName(playerid);//This is the function that will define the timer
new timer[MAX_PLAYERS];//This is the name of the timer,but there's one particulary for every player,as if we want to destroy it,it won't destroy for everyone

COMMAND:starttimer(playerid,params[])
{
   countn[playerid]=10;//It will count for 10 seconds
   timer[playerid]=SetTimerEx("TimerName",countn,false,"i",playerid);//We set the timer for 10 seconds,as you can see
 return 1;
}

//We now define the timer,like this:

public TimerName(playerid)
{
   countn[playerid]--;//The timer decreases from 10 to 0
   if(countn[playerid]>=-1)
  {
     KillTimer(timer[playerid]);
     //code[What your timer actually does]
   }
 return 1;
}
And when the player disconnects,check:

pawn Code:
if(countn[playerid]!=0)//The timer is actually on
{
   //store countn[playerid] in your DataBase
}
And when it connects,load countn[playerid] into a variable[again also check the variable in database if IT'S NULE,meaning there's no reason for loading it then],and set the timer...THE COMMAND I used to set the timer,was an example,to prove how you work with this kind of timer,it's not mandatory for you to also script a command


Re: save the time left of a timer - Jstylezzz - 21.07.2012

hmm, there is one thing i don't understand..
you set the timer for, in this case, 10 seconds, but you only do -- when the function is called, after 10 seconds, so that means, that every 10 seconds it does 10-1, 9-1

sorry for this question, but i just don't understand :\

I will try this though, i see something that i might recognize as what you want to say xD
thanks anyways


Re: save the time left of a timer - Cjgogo - 22.07.2012

My bad,this is the way you set the timer correct:
pawn Code:
timer[playerid]=SetTimerEx("TimerName",1000,true,"i",playerid);
Sorry,really,I was in a hurry,but I once encountered the same problem as you,so I wanted to help.And the explanation now is that the timer repeats every second,but countn decreases,and when it's 0,the timer stops...