SA-MP Forums Archive
Time updating again and again - 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: Time updating again and again (/showthread.php?tid=306994)



Time updating again and again - Bogdan1992 - 28.12.2011

Hello, i have on my server an save times on players, everything works ok until i leave the game and i join back, it executes the function again and starts to count again and it counts from 2 sec to 4 , etc.

I've try with TimeKill but didn't work.

Код:
OnPlayerSpawn(playerid)
{
SetTimerEx("GameTime",1000,1,"i",playerid);
return 1;
}
forward GameTime(playerid);
public GameTime(playerid) {
    PlayerInfo[playerid][pSeconds]++; // When GameTime is being called, seconds are updated +1
    if(PlayerInfo[playerid][pSeconds] == 60) { // If the total seconds = 60
        PlayerInfo[playerid][pMinutes]++; // + 1 minute
        PlayerInfo[playerid][pSeconds] = 0; // reset seconds to 0
    }
    if(PlayerInfo[playerid][pMinutes] == 60) { // If the total minutes = 60
        PlayerInfo[playerid][pHours]++; // + 1 hour
        PlayerInfo[playerid][pMinutes] = 0; // reset minutes to 0
        PlayerInfo[playerid][pSeconds] = 0; // reset minutes to 0
    }
    return 1;
}



Re: Time updating again and again - Seven_of_Nine - 28.12.2011

pawn Код:
//updated
new pTimer[MAX_PLAYERS];

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(pTimer[playerid]);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new GameTimer;
    pTimer[playerid] = SetTimerEx("GameTime",1000,1,"i",playerid);
    return 1;
}
Try this.

I'd do it with PVars, then save it to an .ini file on disconnect. ; )

EDIT: Whoops. You should define a timer for every single player. Updated.


Re: Time updating again and again - Bogdan1992 - 28.12.2011

Thank you, problem solved.