Quote:
Originally Posted by [KHK]Khalid
In my opinion, this is a bad way of doing it, with timers, I think it'll decrease server performance a lot as long as new players keep joining. I have a better way of doing it perhaps, check it out because I dunno if it works, however it should do:
pawn Код:
enum PLAYER_SPENT_TIME_STRUCT { connectedAtHr, // When did this player connect to our server (hour)? connectedAtMin, // ~ ~ ~ minute ~ ~ ~ connectedAtSec // ~ ~ ~ second ~ ~ ~ }
new PlayerConnectedTime[MAX_PLAYERS][PLAYER_SPENT_TIME_STRUCT];
public OnPlayerConnect() { // Update player new time // gettime gets the current time in hours, minutes and seconds // So this is when they connected gettime(PlayerConnectedTime[playerid][connectedAtHr], PlayerConnectedTime[playerid][connectedAtMin], PlayerConnectedTime[playerid][connectedAtSec]); return 1; }
public OnPlayerDisconnect() { // Now they're leaving the server // Let's see the difference between time now and time when they connected // Yes, we can do that as we've saved it in the PlayerConnectedTime variables new curHr, curMin, curSec; gettime(curHr, curMin, curSec); new newHrs, newMins, newSecs; newHrs = curHr - PlayerConnectedTime[playerid][connectedAtHr]; newSecs = curSec - PlayerConnectedTime[playerid][connectedAtSec]; newMins = curMin - PlayerConnectedTime[playerid][connectedAtMin]; // Now newHrs, newMins, newSecs is the newly spent time // Do whatever you want with them! return 1; }
|
Quote:
Originally Posted by Yashas
NetStats_GetConnectedTime
You don't need a timer dedicated to keep track of player's playing time.You can save some CPU by avoiding it
|
So once I actually get that time, how should I store it for when they go offline, just store it into the mysql table and when they reconnect retrieve that time and continue from that?