Raised This Month: $51 Target: $400
 12% 

get_user_time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 04-16-2014 , 09:36   get_user_time
Reply With Quote #1

Hi, how can i get user play time?
get_user_time resets on map change. I want to get time is user online from last connection.
Example:
Player connects, plays for 10 minutes, map changes, and player continue to play for 10 minutes on new map. His play time should be 20 minutes.

How can i achieve this?
OvidiuS is offline
Send a message via Skype™ to OvidiuS
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-16-2014 , 09:40   Re: get_user_time
Reply With Quote #2

Use SQL or Vault or a File to save their play time at the end of the map
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 04-16-2014 , 09:56   Re: get_user_time
Reply With Quote #3

I'll take that as second option. How does hl engine handle this? Is there any way to hook some function?

Last edited by OvidiuS; 04-16-2014 at 10:05.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-16-2014 , 10:00   Re: get_user_time
Reply With Quote #4

Handle what? You need to save the information at the end of the map. Search around and look at the various methods you can save and then implement one of them
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
swapped
BANNED
Join Date: Mar 2014
Location: OrpheuRegisterHook
Old 04-16-2014 , 11:43   Re: get_user_time
Reply With Quote #5

check played time
swapped is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 04-16-2014 , 12:13   Re: get_user_time
Reply With Quote #6

Ok, i made something.
Code:
#include < amxmodx > #include < amxmisc > new global_iPlayerTime[ 33 ]; new Trie:global_tChangeLevel; public plugin_init( ) {     global_tChangeLevel = TrieCreate( );     LoadTimes( ); } LoadTimes( ) {     if( file_exists( "mapchange_times.ini" ) )     {         new f = fopen( "mapchange_times.ini", "rt" );                 new sFileData[ 128 ], sLength[ 64 ];         new sAuthId[ 35 ];                 while( !feof(f) )         {             fgets( f, sFileData, sizeof( sFileData ) - 1);                         if( !sFileData[ 0 ] )                 continue;                             parse( sFileData, sAuthId, charsmax( sAuthId ), sLength, charsmax( sLength ) );             TrieSetCell( global_tChangeLevel, sAuthId, str_to_num( sLength )  );         }                 set_task( 3.0, "_TaskDelete_Times", _, _, _ );         delete_file( "mapchange_times.ini" );     } } public _TaskDelete_Times( ) {     TrieClear( global_tChangeLevel ); } public client_authorized( id ) {     new szAuthId[ 35 ], iValue = 0;     get_user_authid( id, szAuthId, charsmax( szAuthId ) );     if( TrieGetCell( global_tChangeLevel, szAuthId, iValue ) )     {         global_iPlayerTime[ id ] -= iValue ;     } } public client_connect( id ) {     global_iPlayerTime[ id ] = get_systime( ); } public client_changelevel_disconnect( id ) {     if( !is_user_bot( id ) )     {         new szAuthId[ 35 ];         get_user_authid( id, szAuthId, charsmax( szAuthId ) );         new f = fopen( "mapchange_times.ini", "a+" );                 fprintf( f, "^"%s^" %d^n", szAuthId, get_systime( ) - global_iPlayerTime[ id ] );         fclose( f );     } }
client_changelevel_disconnect is forward called on map change.
EDIT: Solved by saving user id instead of authid.

Last edited by OvidiuS; 04-16-2014 at 17:03. Reason: Sorry for bad english.
OvidiuS is offline
Send a message via Skype™ to OvidiuS
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 20:38.


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