Saving a timer
#1

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
Reply
#2

[/pawn]
new pTimer[MAX_PLAYERS];

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

Mmm Would this work for my rent weapon system?

Thanks for the response btw.
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)