SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 24/06/2020, 12:50 AM   #1
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 40
Reputation: 5
Default Played time problem - gettime();

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 ... ?
LowIQ is offline   Reply With Quote
Old 24/06/2020, 03:01 AM   #2
LetsDoItPerfect
Little Clucker
 
Join Date: Mar 2020
Posts: 27
Reputation: 0
Default Re: Played time problem - gettime();

Alt tab definitely has nothing to do with it. Do you have other parts of that activity system?
LetsDoItPerfect is offline   Reply With Quote
Old 24/06/2020, 06:01 AM   #3
Sultanz
Little Clucker
 
Join Date: Jun 2019
Posts: 26
Reputation: 0
Default Re: Played time problem - gettime();

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?
Sultanz is offline   Reply With Quote
Old 24/06/2020, 01:19 PM   #4
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 40
Reputation: 5
Default Re: Played time problem - gettime();

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.
LowIQ is offline   Reply With Quote
Old 24/06/2020, 01:41 PM   #5
Filbert
Huge Clucker
 
Join Date: May 2016
Posts: 251
Reputation: 1
Default Re: Played time problem - gettime();

https://wiki.sa-mp.com/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?
Filbert is offline   Reply With Quote
Old 24/06/2020, 01:56 PM   #6
LowIQ
Little Clucker
 
Join Date: May 2019
Posts: 40
Reputation: 5
Default Re: Played time problem - gettime();

Quote:
Originally Posted by Filbert View Post
https://wiki.sa-mp.com/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!

Last edited by LowIQ; 24/06/2020 at 02:35 PM.
LowIQ is offline   Reply With Quote
Old 26/06/2020, 04:41 AM   #7
LetsDoItPerfect
Little Clucker
 
Join Date: Mar 2020
Posts: 27
Reputation: 0
Default Re: Played time problem - gettime();

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
LetsDoItPerfect is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Played Time IchNar Scripting Help 2 07/10/2017 08:57 AM
Played time ( non A.F.K ) TheDarkBlade Scripting Help 1 08/10/2016 09:44 PM
Played time kalanerik99 Scripting Help 9 19/06/2015 04:42 PM
Time Played Help GlaL Scripting Help 1 13/03/2015 10:33 AM
Time played Ananisiki Scripting Help 9 23/04/2014 01:10 AM


All times are GMT. The time now is 12:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.