Saving timer when player logs off ?
#1

Well... Let's say I wanna make a 10 minutes timer - And it will start counting , But I want it to stop once the player-logoff.

And when he logs in back , The timer starts counting again - How is that possible ? Thanks in advance.
Reply
#2

Hey.

Maybe you could do it in a differer way?
It all depends on what you want to do with this timer.
So.. What this timer would do?

Greetz,
LetsOWN
Reply
#3

I Wanna use it in different things - I just wanna know how to create something like that.

For example - Jail timer , Class timer , License timer - Things like that.
Reply
#4

I see.

Well, I do not want to advise you bad ideas, but I would do it this way:
pawn Код:
//GameModeInit
SetTimer("GlobalTimer", 1000, true);

//Somewhere
forward GlobalTimer();
public GlobalTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(Player[i][JailTime] >= 0)
                Player[i][JailTime]--;
               
            if(Player[i][JailTime] == 0)
                UnjailPlayer(i);
               
            ...
        }
    }
}
This timer runs every second and loops throught every connected player, so that you can easily count e.g. player playing time, time left in jail and all stuff.
All you wanna do is not to put much hard calculations, as it can cause lag (making big calculationswithin 1 second for every player is quite bad option..)

So, in conclusion: IMO, and as for me, it is the best way to do such 'little things'.

To moderators, whoever:
Don't gimme negative rep, but just remove this post. Okay? Thank you..

Greetz,
LetsOWN
Reply
#5

Okay,so firstly there must be a place you create your timer. Player spawn etc. Or connect.


You didn't tell if it's a global timer or not,so I assume it's a timer stored per player? If not,tell me.
What you must do is this:

pawn Код:
new StatSaverTimer[MAX_PLAYERS]; // MAX_PLAYERS must be defined.

Wherever your Timer starts,you must do this:

StatSaverTimer[playerid] = SetTimerEx(....); // so this is where your timer starts.
Then,you must put this under OnPlayerDisconnect.

pawn Код:
KillTimer(StatSaverTimer[playerid]); // kill the timer,so it will stop counting
Reply
#6

Quote:
Originally Posted by Tamer T
Посмотреть сообщение
Okay,so firstly there must be a place you create your timer. Player spawn etc. Or connect.


You didn't tell if it's a global timer or not,so I assume it's a timer stored per player? If not,tell me.
What you must do is this:

pawn Код:
new StatSaverTimer[MAX_PLAYERS]; // MAX_PLAYERS must be defined.

Wherever your Timer starts,you must do this:

StatSaverTimer[playerid] = SetTimerEx(....); // so this is where your timer starts.
Then,you must put this under OnPlayerDisconnect.

pawn Код:
KillTimer(StatSaverTimer[playerid]); // kill the timer,so it will stop counting
I believe that thread author wanted something like this:

Код:
Player connets to the server -> Start countdown (10 minutes) -> Player plays for example 3 minutes -> Player logs-off (disconnect??) -> Player connects to the server -> Start countdown (10 minutes - time already played - 3 mins -, so: 10-3=7) - > Player plays 7 minutes -> Countdown ends
And you just created player sided timer :P

Greetz,
LetsOWN
Reply
#7

Quote:

Player connets to the server -> Start countdown (10 minutes) -> Player plays for example 3 minutes -> Player logs-off (disconnect??) -> Player connects to the server -> Start countdown (10 minutes - time already played - 3 mins -, so: 10-3=7) - > Player plays 7 minutes -> Countdown ends

Indeed , I just wanna know how would something like that work.
Reply
#8

You may save the timer data on the player's info file,I don't know how to take timer data thought.
Reply
#9

Quote:
Originally Posted by Black Axe
Посмотреть сообщение
Indeed , I just wanna know how would something like that work.
As above, it's impossible to do the way you want to do, as there is no way (well, at least I do not know) how to get timer-left-time.

Greetz,
LetsOWN
Reply
#10

Quote:
Originally Posted by Black Axe
Посмотреть сообщение
Indeed , I just wanna know how would something like that work.
You would need to save a value called time left in the player's file. Then, as soon as the player connects, you would use a timer (which, as previously demonstrated would "tick" every second) and it would cause the value of that value to go down by one. OnPlayerDisconnect, you would save the player's time left like any other stat. If you want the timer to reset after 10 minutes, inside of the timer you would check if the player's time left was equal to zero, and then set their time left back to 10 minutes.

What I've explained above is pretty simple, but if you still need help I can post the code for you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)