Played time problem - gettime();
#1

Hello!
I have a problem with players played time checking!

1. Check when player joined the game and save it to variable:

Code:
new TimeJoined[MAX_PLAYERS];

public OnPlayerConnect(playerid) //... or when player login to the account
{
     TimeJoined[playerid] = gettime();
}
2. Store the time when i need to

Code:
public OnPlayerDisconnect(playerid, reason)
{
PlayerInfo[playerid][pPlayedTime] += (gettime() - TimeJoined[playerid]);
}
Everything works fine untill the player goes ALT+TAB for more then 3 minutes.

- Option one: Someone joined the server, was not ALT+TAB and after 300 seconds leave the server.

PlayerInfo[playerid][pPlayedTime] is saved as 300 and THAT IS CORRECT!

- Option two: Someone joined the server, used ALT+TAB to be afk for 10 minutes, came back and...

PlayerInfo[playerid][pPlayedTime] is saved as 1593137909 and THATS INCORRECT!


What can i do ... ?
Reply
#2

Alt tab definitely has nothing to do with it. Do you have other parts of that activity system?
Reply
#3

Quote:
Originally Posted by LowIQ
View Post
Hello!
I have a problem with players played time checking!

1. Check when player joined the game and save it to variable:

Code:
new TimeJoined[MAX_PLAYERS];

public OnPlayerConnect(playerid) //... or when player login to the account
{
     TimeJoined[playerid] = gettime();
}
2. Store the time when i need to

Code:
public OnPlayerDisconnect(playerid, reason)
{
PlayerInfo[playerid][pPlayedTime] += (gettime() - TimeJoined[playerid]);
}
Everything works fine untill the player goes ALT+TAB for more then 3 minutes.

- Option one: Someone joined the server, was not ALT+TAB and after 300 seconds leave the server.

PlayerInfo[playerid][pPlayedTime] is saved as 300 and THAT IS CORRECT!

- Option two: Someone joined the server, used ALT+TAB to be afk for 10 minutes, came back and...

PlayerInfo[playerid][pPlayedTime] is saved as 1593137909 and THATS INCORRECT!


What can i do ... ?
I'm guessing it is because the time is being counted even when the player is AFK?
Reply
#4

Quote:
Originally Posted by LetsDoItPerfect
View Post
Alt tab definitely has nothing to do with it. Do you have other parts of that activity system?
There is no other part of the code, it looks like it store gettime(); without -TimeJoined[playerid], becasue the problem is same output of 1593137909 for every player, and this number (or around) is unix timestamps output (in seconds) wich is equal to (around) 18600 days. The wierd thing is that this happens when a player is ALT+TABBED out for long time, looks like TimeJioned[playerid] become Gettime(); instead of Gettime() - TimeJoined[playerid].

Quote:
Originally Posted by Sultanz
View Post
I'm guessing it is because the time is being counted even when the player is AFK?
Does not make sense, if the time counts properly when the player is AFK then it should not be output of 1593137909 (SECONDS), because its arounr 18 600 days if you convert it, and for that long they was not afk ofc.
Reply
#5

https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime

Try to use this, see if it fixes the prob..

EDIT: You don't save it to sql or something else, no?
Reply
#6

Quote:
Originally Posted by Filbert
View Post
https://sampwiki.blast.hk/wiki/NetStats_GetConnectedTime

Try to use this, see if it fixes the prob..

EDIT: You don't save it to sql or something else, no?
I dont want to save player played time in miliseconds...
I save player stats to .ini file with #include <YSI\y_ini>

EDIT: FIXED
My Automatic Saving system messed up some things...
Thanks for help!
Reply
#7

Quote:
Originally Posted by LowIQ
View Post
I dont want to save player played time in miliseconds...
I save player stats to .ini file with #include <YSI\y_ini>

EDIT: FIXED
My Automatic Saving system messed up some things...
Thanks for help!
"no other part of the code" .. pretty low iq
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)