27.07.2015, 22:03
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.
When the player logs in you save a timestamp.
When the player leaves (or requests his stats) you calculate the difference.
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.
PHP код:
new gTimeJoined[MAX_PLAYERS];
PHP код:
gTimeJoined[playerid] = gettime();
PHP код:
new difference = gettime() - gTimeJoined[playerid];