SA-MP Forums Archive
[Help] 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)
+--- Thread: [Help] Saving a timer (/showthread.php?tid=488830)



[Help] Saving a timer - BornHuman - 19.01.2014

I recently came up with a jail system but i am having a bit of a problem.

Whenever you jail someone the timer starts successfully but whenever they logout it keeps going. I want it to stop the timer, saving it in their file and when they reconnect start again. Is their anyway to do this?

Keep in mind I use DINI to save, and will provide the script if needed.


AW: [Help] Saving a timer - Nero_3D - 19.01.2014

In sa-mp there is no way to get the remaining time of a timer
You need to store the finish time of the timer separately in another variable

Than in OnPlayerDisconnect you need to kill the timer and calculate the remaining time and save it


Re: AW: [Help] Saving a timer - BornHuman - 19.01.2014

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
In sa-mp there is no way to get the remaining time of a timer
You need to store the finish time of the timer separately in another variable

Than in OnPlayerDisconnect you need to kill the timer and calculate the remaining time and save it
Anyway you could get me started? I think I may have an idea on how to do it but I have no idea where to start.


AW: [Help] Saving a timer - Nero_3D - 19.01.2014

That is only the saving part
pawn Код:
// global
new
    gJailTimer[MAX_PLAYERS],
    gJailFinishTime[MAX_PLAYERS]
;
pawn Код:
// When you jail someone - pseudo code
    new
        jailedid, // the id of the person who should get jailed
        time // the time he should be jailed in seconds
    ;
    gJailTimer[jailedid] = SetTimerEx("JailTimer", time * 1000, false, "i", jailedid);
    gJailFinishTime[joiledid] = gettime() + time;
pawn Код:
// OnPlayerDisconnect
    if(gJailFinishTime[playerid]) {
        KillTimer(gJailTimer[playerid]);

        new
            remainingtime = gJailFinishTime[playerid] - gettime()
        ;
        // save the time
        gJailFinishTime[playerid] = 0;
    }
pawn Код:
// In JailTimer - the public which gets called by the timer
    gJailFinishTime[playerid] = 0;
The loading part shouldn't be to compilcated