Count online time
#1

hi,

i have this system to count a players online time and giving 500 score for an hour a player has been online but for some reason it doesnt work the right way.
I get the score message every 20 minutes instead of every hour only once!
Wheres the prob?

pawn Код:
new Hours[MAX_PLAYERS];
new Minutes[MAX_PLAYERS];
new OnlineCheck[MAX_PLAYERS];

//OnPlayerConnect
OnlineCheck[playerid] = SetTimerEx("TimePlayed",60000,1,"playerid",playerid);
Minutes[playerid] = 0;
Hours[playerid] = 0;

//OnPlayerDisconnect
KillTimer(OnlineCheck[playerid]);
OnlineCheck[playerid]=-1;

//timer
forward TimePlayed(playerid);
public TimePlayed(playerid)
{
    Minutes[playerid]++;
    if(Minutes[playerid] == 60)
    {
    Hours[playerid]++;
    Minutes[playerid] = 0;
    SetPlayerScore(playerid,GetPlayerScore(playerid)+15);
        SendClientMessage(playerid,-1,"You got 500 score cause youve been online for 1 hour!");
    }
    return 1;
}
Reply
#2

Removed: Error in edited code which I dont have time to fix.
Reply
#3

mhh, no, i think this is completly wrong
Cause the first timer that is set on player connect is true, that means hes repeating...
You just set the timer again after every hour so theres gonna be another timer every hour running parallel to the first/previous ones?
Reply
#4

pawn Код:
OnlineCheck[playerid] = SetTimerEx("TimePlayed",60000,true,"i",playerid);
Try this snippit of code
Reply
#5

Isn't it because this is using your in-game clock while you'd like to use realtime ?
Reply
#6

Fist thing, Why are you checking minutes after the timer has ended the timer is in milliseconds so you dont need to check the time?

Second thing, Custom time might be messing up your code as your using a timer then checking the time and your custom clock may be slower
Reply
#7

what do u mean with custom?
This aint gonna mess up my code...

Also im checking the minutes so the script knows when the player has reached 1 hour. The minutes variable is gonna be resetted back to 0 and starts to count again untill the next hour is completed.
In theory this should work..., pretty simple.

Also the code snippet u posted is the same as mine
the only difference is that u used a bolean instead of an intreger...
Reply
#8

lol, do it using a variable, set the timer to 1 sec to count the played time and use this function:
pawn Код:
stock GetPlayerOnlineTime(playerid, &hours, &minutes, &seconds)
{
    hours = (your var / (60 * 60)) % 24;
    minutes = (your var / 60) % 60;
    seconds = your var % 60;
}
//made by iPLEOMAX
Reply
#9

so i should use this stock function in a timer that has an intervall of 1000? (ms)
Reply
#10

no, make a variable, and use that in a timer :

myvariable[playerid] ++;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)