[Help] Saving a timer
#1

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)