Not working properly?
#1

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]) );
    
floatround(PlayerInfo[playerid][TotalTime] / 3600floatround_floor);
    
floatround(PlayerInfo[playerid][TotalTime] / 60,   floatround_floor) % 60;
    
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.
Reply
#2

PlayedHours is minute or hours?
Reply
#3

Playedhours is totalTime. Which is everything; it's created by milliseconds using gettime function.
Reply
#4

Guys there's a func by samp that tells you the exact time the player has been connected for why not using it?
Reply
#5

Hour = (get time()1 - gettime2) / 3600
Mins = (get time()1 - gettime2) /60
Reply
#6

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.
Reply
#7

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
Reply
#8

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.
Reply
#9

I got a similiar function but i am doing it with another method.

Ill post it in a few mins
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)