27.09.2016, 01:13
Hey guys. I have a system the records the players TOTAL time in game. However some reason it's doubling or something I'm not sure.
I've been in my server for probably around 4 hours? Maybe more maybe less but somewhere around there and I use this function to see how many hours i've played. Server says 20 hours.
Here is my code.
I will explain everything that is here.
I think the error is in PlayerInfo[playerid][PlayedHours] = PlayerInfo[playerid][TotalTime]; I use this because I need to somehow get the existing time of the player before I save the new connection time.
The next line is getting the time as the player disconnects and then minus the time of when the player connected. Then plus the already existing time.
I've been in my server for probably around 4 hours? Maybe more maybe less but somewhere around there and I use this function to see how many hours i've played. Server says 20 hours.
Here is my code.
PHP код:
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
PlayerInfo[playerid][PlayedHours] = PlayerInfo[playerid][TotalTime];
PlayerInfo[playerid][TotalTime] = ( (gettime() - gPlayerJoin[playerid]) + (PlayerInfo[playerid][PlayedHours]) );
h = floatround(PlayerInfo[playerid][TotalTime] / 3600, floatround_floor);
m = floatround(PlayerInfo[playerid][TotalTime] / 60, floatround_floor) % 60;
s = floatround(PlayerInfo[playerid][TotalTime] % 60, floatround_floor);
return PlayerInfo[playerid][TotalTime];
}
I think the error is in PlayerInfo[playerid][PlayedHours] = PlayerInfo[playerid][TotalTime]; I use this because I need to somehow get the existing time of the player before I save the new connection time.
The next line is getting the time as the player disconnects and then minus the time of when the player connected. Then plus the already existing time.