Raised This Month: $ Target: $400
 0% 

Played Time Counter ( The problem of saving )


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-18-2022 , 23:15   Re: Played Time Counter ( The problem of saving )
Reply With Quote #2

1. Is it tracking time correctly during a connection and only failing to remember time on re-connect?
2. If 1 is yes, did you do some debugging to ensure your parse() is working correctly to assign the correct day/hour/minute/second values into the variables?
3. You can simplify this by instead using a unix timestamps and deriving the weeks/days/minutes/etc.. See the below plugin I quickly put together.

PHP Code:

#include <amxmodx>
#include <nvault>

new const Version[] = "0.1";

enum PlayerData
{
    
AuthID35 ],
    
ConnectTS,
    
TotalTime
}

new 
g_pdDataMAX_PLAYERS ][ PlayerData ];
new 
g_Vault;

public 
plugin_init() 
{
    
register_plugin"Time Played" Version "bugsy" );
    
    
g_Vault nvault_open"timeVault" );
    
    
register_clcmd"say /time" "ShowTime" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szTime10 ] , iTS;
    
    
get_user_authidid g_pdDataid ][ AuthID ] , charsmaxg_pdData[][ AuthID ] ) );
    
    
g_pdDataid ][ ConnectTS ] = get_systime();
    
g_pdDataid ][ TotalTime ] = 0;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
g_pdDataid ][ TotalTime ] = str_to_numszTime );
    }
}

#if AMXX_VERSION_NUM >= 190 
public client_disconnectedid )
#else
public client_disconnectid )
#endif
{
    new 
szTime10 ] , iTime iTS;
    
    if ( 
nvault_lookupg_Vault g_pdDataid ][ AuthID ] , szTime charsmaxszTime ) , iTS ) )
    {
        
iTime str_to_numszTime );
    }
    
    
num_to_str( ( get_systime() - g_pdDataid ][ ConnectTS ] ) + iTime szTime charsmaxszTime ) );
    
nvault_setg_Vault g_pdDataid ][ AuthID ] , szTime );
}

public 
ShowTimeid )
{
    new 
iWeeks iDays iHours iMinutes iSeconds;
    
    
ConvertTimeStampg_pdDataid ][ TotalTime ] + ( get_systime() - g_pdDataid ][ ConnectTS ] ) , iWeeks iDays iHours iMinutes iSeconds );
    
client_printid print_chat "* Time played: %d weeks, %d days, %d hours, %d minutes, %d seconds" iWeeks iDays iHours iMinutes iSeconds );
}

ConvertTimeStampiTimestamp , &iWeeks , &iDays , &iHours , &iMinutes , &iSeconds )
{
    if ( 
iTimestamp >= 604800 )
    {
        
iWeeks iTimestamp 604800;
        
iTimestamp -= ( iWeeks 604800 );
    }
    
    if ( 
iTimestamp >= 86400 )
    {
        
iDays iTimestamp 86400;
        
iTimestamp -= ( iDays 86400 );
    }
    
    if ( 
iTimestamp >= 3600 )
    {
        
iHours = ( iTimestamp 3600 );
        
iTimestamp -= ( iHours 3600 );
    }
    
    if ( 
iTimestamp >= 60 )
    {
        
iMinutes = ( iTimestamp 60 );
        
iTimestamp -= ( iMinutes 60 );
    }
    
    
iSeconds iTimestamp;

__________________
Bugsy is offline
 



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 15:40.


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