14.06.2015, 02:45
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;
}