saving timers - 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: saving timers (
/showthread.php?tid=513411)
saving timers -
AroseKhanNiazi - 16.05.2014
how can i make an timer that works for 24 mins and if player quits in that time the time get's saved and when player joins the timer continue form same place
example
a timer is set to 24 mins and after 24 mins it again starts for the player
the player played 22 mins and left the server then the 2 mins timer get's saved in his data and when he joins the timer start form the same place he left
i think we would need then eunms for saving time idk float or integer then will the timer work with enums ??
Re: saving timers -
Lordzy - 16.05.2014
Assign the timer ID in an array and run the timer according to your interval. Also, store the current time while the timer gets started. When the player gets disconnected, check if the timerID is in use and if so, calculate the current time with the time the timer was started. Here's a small example:
pawn Код:
new
p_Timer[MAX_PLAYERS] = {-1, ...}, //Timer Ids start from 0, so -1 could be assumed as an invalid one.
p_TimerStartTime[MAX_PLAYERS]; //The time when the timer was started.
//And at the location where the timer gets started
p_Timer[playerid] = SetTimerEx("PlayerTimer", 1000*60*24, false, "d", playerid); //A timer which would run up to 24 minutes.
p_TimerStartTime[playerid] = gettime(); //Get the time at which it's started.
public OnPlayerDisconnect(playerid)
{
//When player gets disconnected.
if(p_Timer[playerid] != -1) //If the timer is not invalid, which means there's a timer running.
{
KillTimer(p_Timer[playerid]); //Kill that running timer.
p_Timer[playerid] = -1; //Assign the array to -1 value.
new
remain_time = gettime() - p_TimerStartTime[playerid]; //Subtracting the current time with the previous start time.
new
next_time = 1000*60*24 - remain_time; //The remaining time to be continued to set it later.
}
return 1;
}
I haven't tested this example though. Save the remaining time anywhere (database or files) and then assign that value to the player variable/array when he/she logs in later.
Search for UNIX timestamps tutorial, that would really help you out.
Re: saving timers -
AroseKhanNiazi - 16.05.2014
thanks but i think i got another better idea ??