Time updating again and again
#1

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;
}
Reply
#2

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

Thank you, problem solved.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)