SA-MP Forums Archive
Saving 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Saving a timer (/showthread.php?tid=270058)



Saving a timer - Vero - 18.07.2011

I know you can set the timer for a player, using SetTimerEx or SetTimer but when the player logs out and logs in the timer will reset. I was wondering how I could stop the timer when the player logs out, and when the player logs back in it continues.

Thanks in advance


Re: Saving a timer - DRIFT_HUNTER - 18.07.2011

[/pawn]
new pTimer[MAX_PLAYERS];

pTimer = SetTimerEx(.........) or SetTimer(....)
OnPlayerDisconnect(playerid, reason)
{
KillTimer(pTimer[playerid];
return 1;
}[/pawn]


Re: Saving a timer - Vero - 18.07.2011

Mmm Would this work for my rent weapon system?

Thanks for the response btw.


Re: Saving a timer - =WoR=Varth - 19.07.2011

Maybe this code can inspire you:
pawn Код:
//On top of your script
new Inspire[MAX_PLAYERS]
    Inspiring[MAX_PLAYERS];
forward Inspiration(playerid);

//Somewhere you want to start the timer
Inspiring[playerid] = 30;//It mean 30 minutes
Inspire[playerid] = SetTimerEx("Inspiration",60000,1,"d",playerid);

//Whereever you want
public Inspiration(playerid)
{
    if(Inspiring[playerid] == 0)
    {
        KillTimer(Inspiring[playerid]);
        //Your code here if the timer is ended/finished
        return 1;
    }
    return Inspiring[playerid] -= 1;
}
You have to save Inspiring[playerid] into file or database in OnPlayerDisconnect and load it in OnPlayerConnect if you want it to be like that.