Playing Time in stats command
#1

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

Reply
#2

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

Which return 1;
Reply
#4

Here:

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

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?
Reply
#6

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

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

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;
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)