Playing Time - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Playing Time (
/showthread.php?tid=612410)
Playing Time -
Rockyyy - 17.07.2016
Hey i have a bug in player stats (played time) the time increases by 160 hours or smthing after a minutes from register
when player register the time is working good but after few minutes it gets bugged.
Код:
TotalGameTime(playerid, &h=0, &m=0, &s=0)
{
PInfo[playerid][TotalTime] = ( (gettime() - PInfo[playerid][ConnectTime]) + (PInfo[playerid][hours]*60*60) + (PInfo[playerid][mins]*60) + (PInfo[playerid][secs]) );
h = floatround(PInfo[playerid][TotalTime] / 3600, floatround_floor);
m = floatround(PInfo[playerid][TotalTime] / 60, floatround_floor) % 60;
s = floatround(PInfo[playerid][TotalTime] % 60, floatround_floor);
return PInfo[playerid][TotalTime];
}
thats the code of how it should count the played time i guess its the wrong one
also under onplayerconnect
PInfo[playerid][ConnectTime] = gettime();
Re: Playing Time -
GuyB790 - 19.07.2016
What is the purpose of this section?:
Код:
(PInfo[playerid][hours]*60*60) + (PInfo[playerid][mins]*60) + (PInfo[playerid][secs])
You just need this code:
Код:
(gettime() - PInfo[playerid][ConnectTime])
Re: Playing Time -
OneDay - 19.07.2016
If PInfo[playerid][TotalTime] is integer you dont use floatround. It is not float. How do you call TotalGameTime if you call repeatedly PInfo[playerid][hours] and PInfo[playerid][TotalTime] will increase also and increase each other.
Re: Playing Time -
GuyB790 - 19.07.2016
What is the point of PInfo[playerid][hours]?
Just use (gettime() - PInfo[playerid][ConnectTime]) to calculate how much time passed since the player has last connected.
Save that value each time into your player's db/ini file (incrementing your current totalplaytime). Then do whatever calculations you want to display the hours, minutes and seconds. There's no point saving them in variables once you have a timestamp..