Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <amxmisc>
- #include <cstrike>
- #include <nvault>
- #pragma semicolon 1
- #define TASKID 1337
- new timeSeconds[ 33 ], timeMinute[ 33 ], timeHour[ 33 ];
- new nVault;
- new pCvarAddTimeWay;
- public plugin_init()
- {
- register_plugin( "Total Time Connection" , "0.1" , "oMz'" );
- register_clcmd( "say /time" , "cmdShowTotalTimeConnection" );
- register_clcmd( "ttc_infos" , "cmdGetInfosPlayer" , ADMIN_KICK , "< authid >" );
- pCvarAddTimeWay = register_cvar( "ttc_addtime" , "2" );
- }
- public client_putinserver( id )
- {
- LoadTime( id );
- set_task( 1.0 , "addTime" , id+TASKID , .flags="b" );
- }
- public client_disconnect( id )
- {
- if( task_exists( id+TASKID ) )
- {
- remove_task( id+TASKID );
- }
- SaveTime( id );
- }
- public plugin_cfg()
- {
- nVault = nvault_open( "TotalTimeConnection" );
- if ( nVault == INVALID_HANDLE )
- {
- set_fail_state("Error opening nVault");
- }
- }
- public plugin_end()
- {
- nvault_close( nVault );
- }
- public addTime( id )
- {
- id -= TASKID;
- new CsTeams:team = cs_get_user_team( id );
- if( is_user_connected( id ) )
- {
- if( get_pcvar_num( pCvarAddTimeWay ) == 2 )
- {
- if( team != CS_TEAM_T && team != CS_TEAM_CT )
- {
- return PLUGIN_HANDLED;
- }
- }
- timeSeconds[ id ]++;
- if( timeSeconds[ id ] == 60 )
- {
- timeMinute[ id ]++;
- timeSeconds[ id ] = 0;
- if( timeMinute[ id ] == 60 )
- {
- timeHour[ id ] ++;
- timeMinute[ id ] = 0;
- }
- }
- }
- return PLUGIN_CONTINUE;
- }
- public SaveTime( id )
- {
- new AuthID[ 35 ];
- get_user_authid( id , AuthID , charsmax( AuthID ) );
- new data[ 15 ];
- formatex( data , charsmax( data ) , "%d %d %d" , timeSeconds[ id ] , timeMinute[ id ] , timeHour[ id ] );
- nvault_set( nVault , AuthID , data );
- }
- public LoadTime( id )
- {
- new AuthID[ 35 ];
- get_user_authid( id , AuthID , charsmax( AuthID ) );
- new data[ 15 ];
- if( nvault_get( nVault , AuthID , data , charsmax( data ) ) )
- {
- new space = contain( data , " " );
- if( space > -1 )
- {
- new valTimeSeconds[ 4 ];
- new valTimeMinute[ 4 ];
- new valTimeHour[ 10 ];
- formatex( valTimeSeconds , space , "%s" , data );
- formatex( valTimeMinute , charsmax( valTimeMinute ) ,"%s" , data[ space + 1 ] );
- formatex( valTimeHour , charsmax( valTimeHour ) , "%s" , data[ space + 2 ] );
- timeSeconds[ id ] = str_to_num( valTimeSeconds );
- timeMinute[ id ] = str_to_num( valTimeMinute );
- timeHour[ id ] = str_to_num( valTimeHour );
- }
- }
- else
- {
- timeSeconds[ id ] = 0;
- timeMinute[ id ] = 0;
- timeHour[ id ] = 0;
- }
- }
- public cmdShowTotalTimeConnection( id )
- {
- client_print( id , print_chat , "Total Time Connection : %d hour%s, %d minute%s, %d second%s" , timeHour[ id ] , timeHour[ id ] > 1 ? "s" : "" , timeMinute[ id ] , timeMinute[ id ] > 1 ? "s" : "" , timeSeconds[ id ] , timeSeconds[ id ] > 1 ? "s" : "" );
- }
- public cmdGetInfosPlayer( id , level , cid )
- {
- if ( !cmd_access( id , level , cid , 1 ) )
- {
- client_print( id , print_chat , "You have not access!" );
- return PLUGIN_HANDLED;
- }
- new AuthID[ 35 ];
- read_argv( 1 , AuthID , charsmax( AuthID ) );
- if( !equal( AuthID ,"STEAM_" , 6 ) )
- {
- client_print( id , print_console , "Error, it isn't an AuthID" );
- return PLUGIN_HANDLED;
- }
- new data[ 15 ];
- new players[ 32 ] , num , i ;
- get_players( players , num , "h" );
- for( i = 0; i < num; i++ )
- {
- SaveTime( players[ i ] );
- }
- if( nvault_get( nVault , AuthID , data , charsmax( data ) ) )
- {
- new space = contain( data , " " );
- if( space > -1 )
- {
- new valTimeSeconds[ 4 ];
- new valTimeMinute[ 4 ];
- new valTimeHour[ 10 ];
- formatex( valTimeSeconds , space , "%s" , data );
- formatex( valTimeMinute , charsmax( valTimeMinute ) ,"%s" , data[ space + 1 ] );
- formatex( valTimeHour , charsmax( valTimeHour ) , "%s" , data[ space + 2 ] );
- new iSeconds = str_to_num( valTimeSeconds );
- new iMinute = str_to_num( valTimeMinute );
- new iHour = str_to_num( valTimeHour );
- client_print( id , print_chat , "Infos printed in console !" );
- client_print( id , print_console , "Total Time Connection for AuthID %s : %d hour%s, %d minute%s, %d second%s" , AuthID , iHour , iHour > 1 ? "s" : "" , iMinute , iMinute > 1 ? "s" : "" , iSeconds , iSeconds > 1 ? "s" : "" );
- }
- }
- return PLUGIN_HANDLED;
- }
Add Comment
Please, Sign In to add comment