Save a timer on disconnnect. help.
#1

Hi guys , i want make a file with player stats using YSI\y_ini , i know how to do that(i know how to save score ,health ,and others) but how to save timers? for example " if someone go in jail for 60000 seconds , i use a timer, but if he disconnect while the timer running how do i save the remaining time? so when he connect again then the timer starts from the remaining time! someone help me , its very important for my script.

thanks for your time
Reply
#2

use gettime or gettickcount functions to save the time they got jailed in some variable when you jail them, when they leave if it's been less than 60 (or 60000 for the tickcount) save current (gettime-your_variable) , that much is remaining from their jail time.
Reply
#3

Why do you want to use timers anyway? Use Timestamps, 100% better and efficiant.

PHP код:
new MyTime[MAX_PLAYERS];
CMD:heal(playerid,params[]) {
    new 
currenttime gettime();
    if(
currenttime < (MyTime[playerid] + 60)) //if 60 seconds havent passed yet
        
return SendClientMessage(playerid,COLOR_RED,"60 seconds havent passed yet");
        
    
SetPlayerHealth(playerid100);
    return 
true;
}
//Playtime
new TimePLayed[MAX_PLAYERS];
public 
OnPlayerConnect(playerid) {
    
TimePlayed[playerid];
    return 
true;
}
public 
OnPlayerDisconnect(playerid) {
    new 
totaltime gettime() - TimePlayed[playerid];
    
//save totaltime and you will have how many seconds they have played
    
return true;

or jail system
PHP код:
new MyJailTime[MAX_PLAYERS], JailTime[MAX_PLAYERS];
CMD:jail(playerid,params[]) {
    
//your variables to check for jail
    
MyJailTime[someplayer] = gettime(); //save the time when they have entered the jail
    
JailTime[someplayer] = 60000//saving 600000 seconds they shoudld spend in jail
    
return true;
}
CMD:exitjail(playerid,params[]) {
    new 
string[128];
    
format(string,sizeof(string),"You can exit jail in %i seconds",((MyJailTime[playerid] + JailTime[playerid]) - gettime()));
    if(
gettime() < (MyJailTime[playerid] + JailTime[playerid])) return SendClientMessage(playerid,COLOR_RED,"You cannot exit the jail yet");
    return 
true;

Reply
#4

I would save the current-time (using gettime()) and add the jailtime (60 seconds) to it and save it in a variable.
Suppose gettime() returns 500000, then save 500060 to that variable.

I would also run a permanent timer that checks every second if they're jailed (gettime() < jailtime).
And also check if they somehow left jail (exited the interior or moved further away than a certain radius) and spawns them again inside the jail to keep them there.

You can save that jailtime as well and check if they're still jailed upon connecting.
When they spawn after connecting and their jailtime hasn't ran out yet, spawn them inside the jail again.

It would be hard to cheat and stay out of jail when they're meant to be jailed that way.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)