TOTAL online time
#1

Well, I'm using this for getting players total online time. I just wanted to ask is it good the way i am using? Cuz i have seen and heard gettime is best way. but i don't know how to save online time in gettime ways. Anyone post some codes?

PHP код:
forward TimeOnServer(); //Defining the public
public TimeOnServer() //calling the public for the timer
{
    for(new 
i=0i<MAX_PLAYERSi++) //Looping through players
    
{
       if(
IsPlayerConnected(i)) //For me I rather use IsSpawned, but for most people who might not have IsSpawned Variable, use IsPlayerConnected
       
{
          
pData[i][pMinutes] ++; //Increasing pMinutes every 60 seconds.
          
if(pData[i][pMinutes] >= 60//Checking if minutes reached 60. (one hour) pData[playerid][pVip] == 1
          
{
              
pData[i][pMinutes] =0//Setting a new hour.
              
pData[i][pHours] ++;  //Increasing online hour +1.
          
}
          return 
1;

Reply
#2

Hello!

This is a good way.
PHP код:
public TimeOnServer()
{
    for(new 
i;i<MAX_PLAYERS;i++)
    {
        if(!
IsPlayerConnected(i) || IsPlayerNPC(i))continue;
        
pData[i][pMinutes] ++;
        if(
pData[i][pMinutes] >= 60)
        {
            
pData[i][pMinutes] = 0;
            
pData[i][pHours] ++;
        }
    }
    return 
1;

You can do this also with gettime() but it is cumbersome and it need more time.
Reply
#3

And i am using this ongamemode
PHP код:
SetTimer("TimeOnServer",60000,1); /// for hours and mins 
Reply
#4

Keeping multiple variables for time is inefficient, as is using timers. You only need one unit of time (usually seconds) and all the rest can be deducted from that; 86400 seconds is 1440 minutes is 24 hours is 1 day. That is the principle of the Unix timestamp.
PHP код:
new gTimeJoined[MAX_PLAYERS]; 
When the player logs in you save a timestamp.
PHP код:
gTimeJoined[playerid] = gettime(); 
When the player leaves (or requests his stats) you calculate the difference.
PHP код:
new difference gettime() - gTimeJoined[playerid]; 
Now you have the total time in seconds the player has been playing during that session. Then it's a simple matter of addition. Very easy in SQL based systems. Slightly more tricky in file based system: read the total time, add the session time and then write the result back to the file.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)