SA-MP Forums Archive
timer save. Help please - 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: timer save. Help please (/showthread.php?tid=216985)



timer save. Help please - bartje01 - 26.01.2011

Hey guys.
I know how to save things like variables.
But maybe a strange question:

How to save the time from a timer when it's not finished yet?
Like a jail timer.

My jail timer:

pawn Код:
SetTimerEx("outjail", GetPlayerWantedLevel(id)*60000*5, false, "i", id);
So when a player leaves. How can I save the time he has to do when he comes back online?

Thanks


Re: timer save. Help please - bartje01 - 27.01.2011

guys please


Re: timer save. Help please - coole210 - 27.01.2011

ok i can help, in the function it should be something like:

public outjail (playerid, jailtime, blah,blah,blah)

Make a global variable (variable at top of script Ex: new JailTime[MAX_PLAYERS]

and in the timer add

Код:
JailTime[playerid] = jailtime;
Done.


Re: timer save. Help please - bartje01 - 27.01.2011

Quote:
Originally Posted by coole210
Посмотреть сообщение
ok i can help, in the function it should be something like:

public outjail (playerid, jailtime, blah,blah,blah)

Make a global variable (variable at top of script Ex: new JailTime[MAX_PLAYERS]

and in the timer add

Код:
JailTime[playerid] = jailtime;
Done.
Thanks, but not really what I needed.
I want that the time that the player still has when he disconnects saves.

this is how I save money:

dini_IntSet(udb_encode(playername), "money", money[playerid]);

But how will I save the time when a player connects taht he still has to sit in jail.


Re: timer save. Help please - Grim_ - 27.01.2011

Create a variable to store the amount of time left for the player, and run the timer every 5 seconds. Each time the timer is called, decrease the variable by 5. The, when it's zero, release them. If they leave the server, and their variable is greater than 0, they left while in jail, so you can save the variable in the file like you would anything else.

Also, I suggest you use another system besides dini, as it's the slowest INI system around. Look up SII, Y-ini or djSon.


Re: timer save. Help please - bartje01 - 27.01.2011

So if i'm right

When someone gets arrested:
pawn Код:
SetTimerEx("outjail", GetPlayerWantedLevel(id)*60000*5, false, "i", id);
So I will also make a new variable: new jailtime[MAX_PLAYERS];

And then @ my arrest command:
jailtime[id] = GetPlayerWantedLevel(id)*60000*5;

Then I'll start a new timer that will repeat.

First:
forward jailtime(playerid);

public jailtime(playerid)
{
jailtime[playerid] -= 5000
return 1;
}


Like that?


Re: timer save. Help please - Grim_ - 27.01.2011

Yeah that will work. Just make sure to assign the timer to a variable, that way once the player is released from jail, you kill the timer. (Or you could alternatively have the timer call re-call the timer, but that's a mess sometimes)


Re: timer save. Help please - bartje01 - 27.01.2011

Grim_ From when I know you you're my hero.And I know who you are for a long time already :P

Thanks in advance