SA-MP Forums Archive
Playing Time in stats command - 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: Playing Time in stats command (/showthread.php?tid=486307)



Playing Time in stats command - TomatoRage - 08.01.2014

I made a stats command and i put in it playing time everything went prefect but when the mins reached 60 the hours didn't increase

pawn Код:
public PlayingTime(playerid)
{
    if(PlayingTimeSec[playerid] < 59)
    {
        PlayingTimeSec[playerid] ++;
        return 1;
    }
    if(PlayingTimeSec[playerid] == 59)
    {
        PlayingTimeMin[playerid] ++;
        PlayingTimeSec[playerid] =0;
        return 1;
    }
    if(PlayingTimeMin[playerid] == 59)
    {
        PlayingTimeHour[playerid] ++;
        PlayingTimeMin[playerid] =0;
        return 1;
    }
    return 1;
}
but here ss to show what i mean




Re: Playing Time in stats command - Voxel - 08.01.2014

I think its because you are returning 1; or the minute timer is never actually comming on 59 (it might be skipping it).


Re: Playing Time in stats command - TomatoRage - 08.01.2014

Which return 1;


Re: Playing Time in stats command - Face9000 - 08.01.2014

Here:

pawn Код:
if(PlayingTimeMin[playerid] == 59)
    {
        PlayingTimeHour[playerid] ++;
        PlayingTimeMin[playerid] =0;
        return 1;
    }



Re: Playing Time in stats command - KingHual - 08.01.2014

Quote:
Originally Posted by Face9000
Посмотреть сообщение
Here:

pawn Код:
if(PlayingTimeMin[playerid] == 59)
    {
        PlayingTimeHour[playerid] ++;
        PlayingTimeMin[playerid] =0;
        return 1;
    }
Nice, you managed to copy the OP's code.

OT: Have you tried printing the values? As in, literally using printf instead of a textdraw to make sure it's not a textdraw redraw issue?


Re: Playing Time in stats command - Patrick - 08.01.2014

Use the function I posted on Useful Functions/Snippets it's called ConverTime, Just search it because i'm at school at the moment, and its been blocked for some reason. it does the work for you.


AW: Playing Time in stats command - BigETI - 08.01.2014

Just record the playing time in seconds. I advice you to use gettime() instead of timers counting seconds.
You know when a player joins and leaves a server, so you could basicly calculate for how long now a player has played on this server, by just doing ((current time - join time) + recorded time from other play sessions).

To calculate hours, minutes, and seconds, you have to do something like this:

pawn Код:
new seconds = playing_time, minutes, hours;
while(seconds >= 3600)
{
    seconds -= 3600;
    hours++;
}
while(seconds >= 60)
{
    seconds -= 60;
    minutes++;
}



AW: Playing Time in stats command - Nero_3D - 08.01.2014

No need for a loop
pawn Код:
// OnPlayerConnect
    Time[playerid] = gettime();
pawn Код:
new
    seconds = gettime() - Time[playerid],
    minutes = (seconds % 3600) / 60,
    hours = seconds / 3600
;
seconds %= 60;



Re: Playing Time in stats command - Face9000 - 10.01.2014

Quote:
Originally Posted by king_hual
Посмотреть сообщение
Nice, you managed to copy the OP's code.
I answered at the OP's question that he was asking which return 1 Voxel was referring. And i pointed at that part of code.


Re: Playing Time in stats command - BlackBank - 10.01.2014

If you don't want to use gettime etc, then just use this code:
pawn Код:
public PlayingTime(playerid)
{
    PlayingTimeSec[playerid]++;
    if(PlayingTimeSec[playerid] == 59)
    {
        PlayingTimeSec[playerid] = 0;
        PlayingTimeMin[playerid]++;
       
        if(PlayingTimeMin[playerid] == 59) {
            PlayingTimeHour[playerid]++;
            PlayingTimeMin[playerid] = 0;
        }
    }
    return 1;
}