Raised This Month: $ Target: $400
 0% 

best way to keep track of client time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yusufali
Member
Join Date: Feb 2014
Old 09-13-2014 , 12:39   best way to keep track of client time
Reply With Quote #1

I was wondering what is the best way to keep track of the amount of time a client has played of the particular round in question (not the total time on the server)

So far what i have is a time that repeats and in which some variable is incremented by the repeat time in seconds. If the client has disconnected, it stops the timer.

I was wondering if there was a better way to do so?
__________________
yusufali is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-13-2014 , 13:01   Re: best way to keep track of client time
Reply With Quote #2

Store time as a unix timestamp and then subtract from the timestamp again when you want to aggregate.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
yusufali
Member
Join Date: Feb 2014
Old 09-13-2014 , 14:04   Re: best way to keep track of client time
Reply With Quote #3

ah yes, much smarter idea, thank you
__________________
yusufali is offline
yusufali
Member
Join Date: Feb 2014
Old 09-17-2014 , 13:52   Re: best way to keep track of client time
Reply With Quote #4

so how would somebody subtract the unix time stamps to get the time in seconds

Code:
new time1 = GetTime();
new time2 = GetTime(); // called at some later time during the program
         
 new time3 = time2 - time1; //gives difference between time2 and time1 in???
would that work, what unit of time would time3 be? minutes/hours/seconds ?
__________________
yusufali is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 09-17-2014 , 13:56   Re: best way to keep track of client time
Reply With Quote #5

Quote:
Originally Posted by yusufali View Post
so how would somebody subtract the unix time stamps to get the time in seconds

Code:
new time1 = GetTime();
new time2 = GetTime(); // called at some later time during the program
         
 new time3 = time2 - time1; //gives difference between time2 and time1 in???
would that work, what unit of time would time3 be? minutes/hours/seconds ?
GetTime()
Return: 32bit timestamp (number of seconds since unix epoch).


Obviously seconds.
__________________

Last edited by floube; 09-17-2014 at 13:56.
floube is offline
yusufali
Member
Join Date: Feb 2014
Old 09-17-2014 , 14:35   Re: best way to keep track of client time
Reply With Quote #6

Quote:
Originally Posted by floube View Post
GetTime()
Return: 32bit timestamp (number of seconds since unix epoch).


Obviously seconds.
so simply subtracting them should work?
__________________
yusufali is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-17-2014 , 16:06   Re: best way to keep track of client time
Reply With Quote #7

Yup.
__________________
Impact123 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 09-17-2014 , 21:16   Re: best way to keep track of client time
Reply With Quote #8

For more precision You can use getgametime, but i would suggest against it as it stops when the server is hibernating. Getenginetime is better. However, you have to convert this or compare it, it does not persist like a timestamp and is onky valid from the point the server starts (or the map, whatever)
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 00:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode