Not working properly? -
Tass007 - 27.09.2016
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.
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 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.
Re: Not working properly? -
HoangNam - 27.09.2016
PlayedHours is minute or hours?
Re: Not working properly? -
Tass007 - 27.09.2016
Playedhours is totalTime. Which is everything; it's created by milliseconds using gettime function.
Re: Not working properly? - iLearner - 27.09.2016
Guys there's a func by samp that tells you the exact time the player has been connected for why not using it?
Re: Not working properly? -
Dayrion - 27.09.2016
Hour = (get time()1 - gettime2) / 3600
Mins = (get time()1 - gettime2) /60
Re: Not working properly? -
Tass007 - 27.09.2016
But I already have a variable that uses gettime.
@iLearner what is that function called then? I'm still going to be having the same trouble using that function as well. Getting the existing time and then somehow adding to it.
Re: Not working properly? - iLearner - 27.09.2016
Could you please tell me what you want to do exactly? I might give you the complete func.
BTW
https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime
Re: Not working properly? -
Tass007 - 27.09.2016
I want to record the players connection time and save it into PlayerInfo[playerid][TotalTime]
Whenever a player reconnects it gets the existing TotalTime and updates it to the new TotalTime (Including the new amount of time the player is connected)
Another part is every 3 hours a player hits e.g 3 hours, 6 hours, 9 hours they get +1 score.
Re: Not working properly? - iLearner - 27.09.2016
I got a similiar function but i am doing it with another method.
Ill post it in a few mins
Re: Not working properly? -
justjamie - 27.09.2016
Quote:
Originally Posted by Tass007
I want to record the players connection time and save it into PlayerInfo[playerid][TotalTime]
Whenever a player reconnects it gets the existing TotalTime and updates it to the new TotalTime (Including the new amount of time the player is connected)
Another part is every 3 hours a player hits e.g 3 hours, 6 hours, 9 hours they get +1 score.
|
i get what you mean.
You need to store it in some kind of database.
The most commonly used is MySQL.
Check out this thread:
https://sampforum.blast.hk/showthread.php?tid=56564