27.05.2014, 13:50
Well, to calculate time played, you need to get the time at which the player started playing.
Now in order to calculate the time played in the current session, you just simply get the current time and take away the time in which they joined, giving you the total amount in seconds.
Functions used to achieve this:
gettime
Explanation of Unix timestamps
If you wanted to get the TOTAL time that the player has been on the server, you need to save the time to their personal file, load it when they rejoin then add their session time on top of it.
EDIT: I guess I can attempt to make some sort of saving/loading system for you if you really need it...
pawn Код:
new TimeJoined[MAX_PLAYERS]; //This is used to store the time that each player joined.
public OnPlayerConnect(playerid) //Called when a player connects
{
TimeJoined[playerid] = gettime(); //Will store a unix timestamp as the time that the player joined.
return 1;
}
pawn Код:
CMD:timeplayed(playerid, params[])
{
new fstr[50];
format(fstr, sizeof(fstr), "You have been playing for %d seconds.", gettime() - TimeJoined[playerid]);
SendClientMessage(playerid, -1, fstr);
return 1;
}
gettime
Explanation of Unix timestamps
If you wanted to get the TOTAL time that the player has been on the server, you need to save the time to their personal file, load it when they rejoin then add their session time on top of it.
EDIT: I guess I can attempt to make some sort of saving/loading system for you if you really need it...