16.05.2014, 08:09
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:
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.
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;
}
Search for UNIX timestamps tutorial, that would really help you out.