[HELP]Saving Hours, Minutes, Seconds
#3

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;
}
Reply


Messages In This Thread
[HELP]Saving Hours, Minutes, Seconds - by ApOcAlYpSe98 - 22.03.2014, 12:26
Re: [HELP]Saving Hours, Minutes, Seconds - by Knappen - 22.03.2014, 13:14
Re: [HELP]Saving Hours, Minutes, Seconds - by Konstantinos - 22.03.2014, 13:51
Re: [HELP]Saving Hours, Minutes, Seconds - by Knappen - 22.03.2014, 17:01
Re: [HELP]Saving Hours, Minutes, Seconds - by Konstantinos - 22.03.2014, 20:27
Re: [HELP]Saving Hours, Minutes, Seconds - by Knappen - 22.03.2014, 20:29
Re: [HELP]Saving Hours, Minutes, Seconds - by Konstantinos - 22.03.2014, 20:39
Re: [HELP]Saving Hours, Minutes, Seconds - by Knappen - 22.03.2014, 21:51

Forum Jump:


Users browsing this thread: 1 Guest(s)