libdo

Untitled

Sep 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <cstrike>
  4. #include <nvault>
  5.  
  6. #pragma semicolon 1
  7.  
  8. #define TASKID 1337
  9.  
  10. new timeSeconds[ 33 ], timeMinute[ 33 ], timeHour[ 33 ];
  11. new nVault;
  12. new pCvarAddTimeWay;
  13.  
  14. public plugin_init()
  15. {
  16. register_plugin( "Total Time Connection" , "0.1" , "oMz'" );
  17.  
  18. register_clcmd( "say /time" , "cmdShowTotalTimeConnection" );
  19. register_clcmd( "ttc_infos" , "cmdGetInfosPlayer" , ADMIN_KICK , "< authid >" );
  20.  
  21. pCvarAddTimeWay = register_cvar( "ttc_addtime" , "2" );
  22. }
  23.  
  24. public client_putinserver( id )
  25. {
  26. LoadTime( id );
  27. set_task( 1.0 , "addTime" , id+TASKID , .flags="b" );
  28. }
  29.  
  30. public client_disconnect( id )
  31. {
  32. if( task_exists( id+TASKID ) )
  33. {
  34. remove_task( id+TASKID );
  35. }
  36.  
  37. SaveTime( id );
  38. }
  39.  
  40. public plugin_cfg()
  41. {
  42. nVault = nvault_open( "TotalTimeConnection" );
  43.  
  44. if ( nVault == INVALID_HANDLE )
  45. {
  46. set_fail_state("Error opening nVault");
  47. }
  48. }
  49.  
  50. public plugin_end()
  51. {
  52. nvault_close( nVault );
  53. }
  54.  
  55. public addTime( id )
  56. {
  57. id -= TASKID;
  58.  
  59. new CsTeams:team = cs_get_user_team( id );
  60.  
  61. if( is_user_connected( id ) )
  62. {
  63. if( get_pcvar_num( pCvarAddTimeWay ) == 2 )
  64. {
  65. if( team != CS_TEAM_T && team != CS_TEAM_CT )
  66. {
  67. return PLUGIN_HANDLED;
  68. }
  69. }
  70.  
  71. timeSeconds[ id ]++;
  72.  
  73. if( timeSeconds[ id ] == 60 )
  74. {
  75. timeMinute[ id ]++;
  76. timeSeconds[ id ] = 0;
  77.  
  78. if( timeMinute[ id ] == 60 )
  79. {
  80. timeHour[ id ] ++;
  81. timeMinute[ id ] = 0;
  82. }
  83. }
  84. }
  85.  
  86. return PLUGIN_CONTINUE;
  87. }
  88.  
  89. public SaveTime( id )
  90. {
  91. new AuthID[ 35 ];
  92. get_user_authid( id , AuthID , charsmax( AuthID ) );
  93.  
  94. new data[ 15 ];
  95.  
  96. formatex( data , charsmax( data ) , "%d %d %d" , timeSeconds[ id ] , timeMinute[ id ] , timeHour[ id ] );
  97.  
  98. nvault_set( nVault , AuthID , data );
  99. }
  100.  
  101. public LoadTime( id )
  102. {
  103. new AuthID[ 35 ];
  104. get_user_authid( id , AuthID , charsmax( AuthID ) );
  105.  
  106. new data[ 15 ];
  107.  
  108. if( nvault_get( nVault , AuthID , data , charsmax( data ) ) )
  109. {
  110. new space = contain( data , " " );
  111.  
  112. if( space > -1 )
  113. {
  114. new valTimeSeconds[ 4 ];
  115. new valTimeMinute[ 4 ];
  116. new valTimeHour[ 10 ];
  117.  
  118. formatex( valTimeSeconds , space , "%s" , data );
  119. formatex( valTimeMinute , charsmax( valTimeMinute ) ,"%s" , data[ space + 1 ] );
  120. formatex( valTimeHour , charsmax( valTimeHour ) , "%s" , data[ space + 2 ] );
  121.  
  122. timeSeconds[ id ] = str_to_num( valTimeSeconds );
  123. timeMinute[ id ] = str_to_num( valTimeMinute );
  124. timeHour[ id ] = str_to_num( valTimeHour );
  125. }
  126. }
  127.  
  128. else
  129. {
  130. timeSeconds[ id ] = 0;
  131. timeMinute[ id ] = 0;
  132. timeHour[ id ] = 0;
  133. }
  134. }
  135.  
  136. public cmdShowTotalTimeConnection( id )
  137. {
  138. 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" : "" );
  139. }
  140.  
  141. public cmdGetInfosPlayer( id , level , cid )
  142. {
  143. if ( !cmd_access( id , level , cid , 1 ) )
  144. {
  145. client_print( id , print_chat , "You have not access!" );
  146. return PLUGIN_HANDLED;
  147. }
  148.  
  149. new AuthID[ 35 ];
  150. read_argv( 1 , AuthID , charsmax( AuthID ) );
  151.  
  152. if( !equal( AuthID ,"STEAM_" , 6 ) )
  153. {
  154. client_print( id , print_console , "Error, it isn't an AuthID" );
  155. return PLUGIN_HANDLED;
  156. }
  157.  
  158. new data[ 15 ];
  159.  
  160. new players[ 32 ] , num , i ;
  161. get_players( players , num , "h" );
  162.  
  163. for( i = 0; i < num; i++ )
  164. {
  165. SaveTime( players[ i ] );
  166. }
  167.  
  168. if( nvault_get( nVault , AuthID , data , charsmax( data ) ) )
  169. {
  170. new space = contain( data , " " );
  171.  
  172. if( space > -1 )
  173. {
  174. new valTimeSeconds[ 4 ];
  175. new valTimeMinute[ 4 ];
  176. new valTimeHour[ 10 ];
  177.  
  178. formatex( valTimeSeconds , space , "%s" , data );
  179. formatex( valTimeMinute , charsmax( valTimeMinute ) ,"%s" , data[ space + 1 ] );
  180. formatex( valTimeHour , charsmax( valTimeHour ) , "%s" , data[ space + 2 ] );
  181.  
  182. new iSeconds = str_to_num( valTimeSeconds );
  183. new iMinute = str_to_num( valTimeMinute );
  184. new iHour = str_to_num( valTimeHour );
  185.  
  186. client_print( id , print_chat , "Infos printed in console !" );
  187. 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" : "" );
  188. }
  189. }
  190.  
  191. return PLUGIN_HANDLED;
  192. }
Add Comment
Please, Sign In to add comment