Total online time too fast
#1

when I type /stats to see the total online time it actually shows wrong
It changes too fast.
How to solve this?
Reply
#2

How in the world we can help you without even seeing the code?
Reply
#3

Post your timer format and code.
Reply
#4

pawn Код:
public OnPlayerSpawn(playerid)
{
    SetPlayerCheckpoint(playerid, BANK_X, BANK_Y, BANK_Z, 3.0);

    zoneupdates[playerid] = 1;

    player_zone[playerid] = -1;

    if(!zoneupdate) zoneupdate = SetTimer("update_zones",1000,4);

    SetTimerEx("GameTime",1000,1,"i",playerid); // Player Total Online Time
etc...etc..

and here is the /stats cmd

pawn Код:
CMD:stats(playerid, params[]) {
    new id;
    if(sscanf(params,"d",id)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /stats <ID>");
    if (!IsPlayerConnected(id)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected.");
    new ReturnName[MAX_PLAYER_NAME];
    GetPlayerName(id, ReturnName, sizeof(ReturnName));
    new Float:ratio=floatdiv(PlayerInfo[id][Kills], PlayerInfo[id][Deaths]);
    format(szString, 256, "%d %d %.2f", PlayerInfo[id][Kills], PlayerInfo[id][Deaths], ratio);
    format(szString, sizeof(szString), "* Player stats for %s (ID:%d)", ReturnName, id);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    format(szString, sizeof(szString), "* Admin Level > %d | VIP Level > %d | Kills > %d | Deaths > %d | (K/D): %.2f", PlayerInfo[id][AdminLevel], PlayerInfo[id][VIPLevel], PlayerInfo[id][Kills], PlayerInfo[id][Deaths], ratio);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    format(szString, sizeof(szString), "* Score > %d | Cookies > %d | Reaction Wins > %d", PlayerInfo[id][Score], PlayerInfo[id][Cookies], PlayerInfo[id][ReactionWins]);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    format(szString, sizeof(szString), "* Total Online Time: %i hours, %i minutes, and %i seconds", PlayerInfo[id][Hours], PlayerInfo[id][Minutes], PlayerInfo[id][Seconds]);
    SendClientMessage(playerid, COLOR_YELLOW, szString);
    return 1;
}
Reply
#5

Could I have a look at public GameTime?
Anyway, you could use GetTickCount() when the player connects and store it in a variable, and then GetTickCount() again to see how much has the variable increased (the connected time in miliseconds). That would use less CPU resources than a timer.
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=254915

Lovely thread.
Reply
#7

pawn Код:
public GameTime(playerid) {
    PlayerInfo[playerid][Seconds]++;
    if(PlayerInfo[playerid][Seconds] == 60) {
        PlayerInfo[playerid][Minutes]++;
        PlayerInfo[playerid][Seconds] = 0;
    }
    if(PlayerInfo[playerid][Minutes] == 60) {
        PlayerInfo[playerid][Hours]++;
        PlayerInfo[playerid][Minutes] = 0;
        PlayerInfo[playerid][Seconds] = 0;
    }
    return 1;
}
Reply
#8

Your code seems to be correct. Are you setting all the variables to 0 when the player disconnects (just in case a new player connects with the same ID)? I mean:

pawn Код:
public OnPlayerDisconnect(playerid,reason)
{
    PlayerInfo[playerid][Hours] = 0;
    PlayerInfo[playerid][Minutes] = 0;
    PlayerInfo[playerid][Seconds] = 0;
    return 1;
}
Reply
#9

Quote:
Originally Posted by PHudson
Посмотреть сообщение
Your code seems to be correct. Are you setting all the variables to 0 when the player disconnects (just in case a new player connects with the same ID)? I mean:

pawn Код:
public OnPlayerDisconnect(playerid,reason)
{
    PlayerInfo[playerid][Hours] = 0;
    PlayerInfo[playerid][Minutes] = 0;
    PlayerInfo[playerid][Seconds] = 0;
    return 1;
}
Sry idk what you mean but what could be the case then?
Reply
#10

Quote:
Originally Posted by PHudson
Посмотреть сообщение
Your code seems to be correct.
No, it's not correct. Everytime a player spawns, the timer is being created..

And use timestamp instead for such as things.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)