Online time bugged in /stats
#1

So, I have a /stats command. The online time is bugged.

Here is the code:
Code of /stats:
pawn Код:
CMD:stats(playerid, params[])
{
    #pragma unused params
    new Float:health;
    new Float:armor;
    new deaths = pInfo[playerid][Deaths];
    new kills = pInfo[playerid][Kills];
    new spawns = pInfo[playerid][Spawns];
    new h;
    new m;
    new s;
    new ip[16];
    new level = pInfo[playerid][Level];
    new money = GetPlayerMoney(playerid);
    new interior = GetPlayerInterior(playerid);
    new adminlvl = pInfo[playerid][ALevel];
    new adminlvlname[95];
    new viplvl = pInfo[playerid][DLevel];
    new viplvlname[75];
    new tadminlvl = pInfo[playerid][TALevel];
    new tadminname[90];
    new pName[MAX_PLAYER_NAME];
    new score = GetPlayerScore(playerid);
    new ping = GetPlayerPing(playerid);
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armor);
    GetPlayerIp(playerid, ip, sizeof(ip));
    GetPlayerName(playerid, pName, sizeof(pName));
    new string[150];
   
    switch(viplvl)
    {
        case 0: viplvlname = "Not a Donator";
        case 1: viplvlname = "Bronze VIP";
        case 2: viplvlname = "Silver VIP";
        case 3: viplvlname = "Iron VIP";
        case 4: viplvlname = "Gold VIP";
        case 5: viplvlname = "Diamond VIP";
    }
   
    switch(adminlvl)
    {
        case 0: adminlvlname = "Not a staff member";
        case 1: adminlvlname = "Basic Moderator";
        case 2: adminlvlname = "Moderator";
        case 3: adminlvlname = "Full Moderator";
        case 4: adminlvlname = "Basic Administrator";
        case 5: adminlvlname = "Administrator";
        case 6: adminlvlname = "Full Administrator";
        case 7: adminlvlname = "Co-Manager";
        case 8: adminlvlname = "Manager";
        case 9: adminlvlname = "Co-Owner";
        case 10: adminlvlname = "Owner";
    }
   
    switch(tadminlvl)
    {
        case 0: tadminname = "Not a Trial Administrator";
        case 1: tadminname = "Trial Administrator Level 1";
        case 2: tadminname = "Trial Admimistrator Level 2";
    }
   
    TotalGameTime(playerid, h, m, s);
   
    SendClientMessage(playerid, COLOR_YELLOW, "-| Your Stats |-");
    format(string, sizeof(string), "Name: %s - Player ID: %d - IP: %s - Ping: %d", pName, playerid, ip, ping);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Health: %d - Armor: %d - Spawns: %d - Kills: %d - Deaths: %d", health, armor, spawns, kills, deaths);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Score: %d - Level: %d - Money: $%d", score, level, money);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Admin Level: %s (%d) - Donator Level: %s (%d)", adminlvlname, adminlvl, viplvlname, viplvl);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Trial Administrator: %s (%d)", tadminname, tadminlvl);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Interior: %d", interior);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Online Time: %d hours, %d minutes, %d seconds", h, m, s);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    return 1;
}
Code of TotalGameTime (used for Online time):
pawn Код:
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
    pInfo[playerid][TotalTime] = ( (gettime() - pInfo[playerid][ConnectTime]) + (pInfo[playerid][hours]*60*60) + (pInfo[playerid][mins]*60) + (pInfo[playerid][secs]) );

    h = floatround(pInfo[playerid][TotalTime] / 3600, floatround_floor);
    m = floatround(pInfo[playerid][TotalTime] / 60,   floatround_floor) % 60;
    s = floatround(pInfo[playerid][TotalTime] % 60,   floatround_floor);

    return pInfo[playerid][TotalTime];
}
(Note: the TotalGameTime I got from LuxAdmin)

Here is a picture of the /stats:


Any idea on what could be happening?
Reply
#2

I bet there's something wrong with the pInfo array (hours, mins, secs).

Why do you save hours, minutes and seconds in separate variables if you can just save them all in seconds?
Reply
#3

Quote:
Originally Posted by Finn
Посмотреть сообщение
I bet there's something wrong with the pInfo array (hours, mins, secs).

Why do you save hours, minutes and seconds in separate variables if you can just save them all in seconds?
Could you explain a bit more please? Also, here is my pInfo:
pawn Код:
enum PlayerInfo
{
    Name,
    Password,
    OnlineTime,
    Kills,
    Deaths,
    WarningsGotten,
    KicksGotten,
    WarningsGiven,
    KicksGiven,
    BansGiven,
    Money,
    Score,
    Level,
    Spawns,
    DLevel,
    ALevel,
    TotalTime,
    ConnectTime,
    hours, //Hours
    mins, //Minutes
    secs, //Seconds
    TALevel,
    Registered,
    LoggedIn,
    Banned,
    YearRegistered,
    MonthRegistered,
    DayRegistered,
    HourRegistered,
    MinuteRegistered,
    SecondRegistered,
    TempBansGotten,
    TempBansGiven,
    Connects
}
Reply
#4

I don't know about you saving system.
Maybe this will help you.

pawn Код:
//firs Start a timer that runs every 1 seconds then ito the callback

//start the timer
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);

forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
    {
        PlayerInfo[playerid][Min]++;
        PlayerInfo[playerid][Sec]=0;
    }
if(PlayerInfo[playerid][Min]>=60)
    {
        PlayerInfo[playerid][Min]=0;
        PlayerInfo[playerid][Hour]++;
    }
}
//and that's all you need to have a timer with [hours,mins,sec]

//This is to save it
INI_WriteInt(Acc,"Min",PlayerInfo[playerid][Min]);
INI_WriteInt(Acc,"Hour",PlayerInfo[playerid][Hour]);
INI_WriteInt(Acc,"Sec",PlayerInfo[playerid][Sec]);

//To load it
PlayerInfo[playerid][Min] = GetPVarInt(playerid, "Min");
PlayerInfo[playerid][Hour] = GetPVarInt(playerid, "Hour");
PlayerInfo[playerid][Sec] = GetPVarInt(playerid, "Sec");
Reply
#5

This can be done without even a timer.

When a player logins, use GetTickCount and store it in a temporary variable.
When a player disconnects, use GetTickCount again minus the variable you used before.

You've got the milliseconds of the online time for the player. That can be easily converted to seconds/minutes/hours. The last step is to add the previous results (those you loaded on login) with the converted results and you get the sum of the online time.

If you want to display the current online time, then follow: "use GetTickCount again minus the variable you used before." and there you go!
Reply
#6

Quote:
Originally Posted by Champ
Посмотреть сообщение
I don't know about you saving system.
Maybe this will help you.

pawn Код:
//firs Start a timer that runs every 1 seconds then ito the callback

//start the timer
SetTimerEx("TimeOnServer", 1000, 1, "i", playerid);

forward TimeOnServer(playerid);
public TimeOnServer(playerid)
{
PlayerInfo[playerid][Sec] ++;
if(PlayerInfo[playerid][Sec]>=60)
    {
        PlayerInfo[playerid][Min]++;
        PlayerInfo[playerid][Sec]=0;
    }
if(PlayerInfo[playerid][Min]>=60)
    {
        PlayerInfo[playerid][Min]=0;
        PlayerInfo[playerid][Hour]++;
    }
}
//and that's all you need to have a timer with [hours,mins,sec]

//This is to save it
INI_WriteInt(Acc,"Min",PlayerInfo[playerid][Min]);
INI_WriteInt(Acc,"Hour",PlayerInfo[playerid][Hour]);
INI_WriteInt(Acc,"Sec",PlayerInfo[playerid][Sec]);

//To load it
PlayerInfo[playerid][Min] = GetPVarInt(playerid, "Min");
PlayerInfo[playerid][Hour] = GetPVarInt(playerid, "Hour");
PlayerInfo[playerid][Sec] = GetPVarInt(playerid, "Sec");
Thanks. It worked, I just had to change a few things to fit my script.
Reply
#7

Looks like a new problem related to this one. It only started after I used that timer.
ALL of the stats are the same for each person. I'm not sure if you need the code, as I didn't really change anything.
Reply
#8

Bump. Still need help. Here is the new code just in case:
pawn Код:
CMD:stats(playerid, params[])
{
    #pragma unused params
    new Float:health;
    new Float:armor;
    new deaths = pInfo[playerid][Deaths];
    new kills = pInfo[playerid][Kills];
    new spawns = pInfo[playerid][Spawns];
    new d = pInfo[playerid][days];
    new h = pInfo[playerid][hours];
    new m = pInfo[playerid][mins];
    new s = pInfo[playerid][secs];
    new ip[16];
    new level = pInfo[playerid][Level];
    new money = GetPlayerMoney(playerid);
    new interior = GetPlayerInterior(playerid);
    new adminlvl = pInfo[playerid][ALevel];
    new adminlvlname[95];
    new viplvl = pInfo[playerid][DLevel];
    new viplvlname[75];
    new tadminlvl = pInfo[playerid][TALevel];
    new tadminname[90];
    new pName[MAX_PLAYER_NAME];
    new score = GetPlayerScore(playerid);
    new ping = GetPlayerPing(playerid);
    GetPlayerHealth(playerid, health);
    GetPlayerArmour(playerid, armor);
    GetPlayerIp(playerid, ip, sizeof(ip));
    GetPlayerName(playerid, pName, sizeof(pName));
    new string[150];
   
    switch(viplvl)
    {
        case 0: viplvlname = "Not a Donator";
        case 1: viplvlname = "Bronze VIP";
        case 2: viplvlname = "Silver VIP";
        case 3: viplvlname = "Iron VIP";
        case 4: viplvlname = "Gold VIP";
        case 5: viplvlname = "Diamond VIP";
    }
   
    switch(adminlvl)
    {
        case 0: adminlvlname = "Not a staff member";
        case 1: adminlvlname = "Basic Moderator";
        case 2: adminlvlname = "Moderator";
        case 3: adminlvlname = "Full Moderator";
        case 4: adminlvlname = "Basic Administrator";
        case 5: adminlvlname = "Administrator";
        case 6: adminlvlname = "Full Administrator";
        case 7: adminlvlname = "Co-Manager";
        case 8: adminlvlname = "Manager";
        case 9: adminlvlname = "Co-Owner";
        case 10: adminlvlname = "Owner";
    }
   
    switch(tadminlvl)
    {
        case 0: tadminname = "Not a Trial Administrator";
        case 1: tadminname = "Trial Administrator Level 1";
        case 2: tadminname = "Trial Admimistrator Level 2";
    }
   
    SendClientMessage(playerid, COLOR_YELLOW, "-| Your Stats |-");
    format(string, sizeof(string), "Name: %s - Player ID: %d - IP: %s - Ping: %d", pName, playerid, ip, ping);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Health: %d - Armor: %d - Spawns: %d - Kills: %d - Deaths: %d", floatround(health), floatround(armor), spawns, kills, deaths);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Score: %d - Level: %d - Money: $%d", score, level, money);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Admin Level: %s (%d) - Donator Level: %s (%d)", adminlvlname, adminlvl, viplvlname, viplvl);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Trial Administrator: %s (%d)", tadminname, tadminlvl);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Interior: %d", interior);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    format(string, sizeof(string), "Online Time: %d Days, %d hours, %d minutes, %d seconds", d, h, m, s); //Added days
    SendClientMessage(playerid, COLOR_ORANGE, string);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)