22.03.2014, 13:51
Using only gettime and save the time in seconds is the best way. Then you can convert it and display hours-minutes-seconds.
pawn Код:
#include <a_samp>
static
Player_ConnectTime[MAX_PLAYERS],
Player_Time[MAX_PLAYERS];
main() {}
public OnPlayerConnect(playerid)
{
Player_ConnectTime[playerid] = gettime();
Player_Time[playerid] = 0;
// load the saved time in seconds and assign it to Player_Time[playerid]
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Player_Time[playerid] += (gettime() - Player_ConnectTime[playerid]);
// save the time in seconds, it's stored to Player_Time[playerid]
return 1;
}
//...
// showing the game time in a command or whatever:
new
temp = (gettime() - Player_ConnectTime[playerid]) + Player_Time[playerid];
h, m, s;
ReturnGameTime(temp, h, m, s);
format(string, sizeof(string), "Total Time: %d hours %d minutes %d seconds", h, m, s);
SendClientMessage(playerid, -1, string);
//...
stock ReturnGameTime(seconds, &h, &m, &s)
{
h = seconds / 3600;
m = seconds / 60 % 60;
seconds = seconds % 60;
}