Advertisement
OvidiuS

CheckCvars

Jul 10th, 2011
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.02 KB | None | 0 0
  1. /*
  2.     Formatright © 2012
  3.    
  4.     CheckCvars v1.0
  5.     Author: OvidiuS
  6.    
  7.     *English*
  8.     This plugin is free software;
  9.     you can modify it under the terms of the
  10.     GNU General Public License as published by the Free Software Foundation.
  11.    
  12.     *Serbian*
  13.     Ovaj plugin je besplatni program;
  14.     mozete ga menjati postujuci prava autora, samo ga ne smete prodavati.
  15.     Svako krsenje GNU Licence moze da rezultitra tuzbom.
  16. */
  17.  
  18. #include <amxmodx>
  19. #include <amxmisc>
  20.  
  21. new Array:g_aCvars, Trie:g_tCvarName;
  22. new g_szCvarFile[ 64 ];
  23.  
  24. public plugin_init()
  25. {
  26.     register_plugin("CvarCheck", "1.0", "OvidiuS");
  27.     register_cvar("checkcvars" , "1.0" , (FCVAR_SERVER|FCVAR_SPONLY))
  28.  
  29.     get_configsdir( g_szCvarFile, charsmax( g_szCvarFile ) );
  30.     add( g_szCvarFile, charsmax( g_szCvarFile ), "/cvarovi.ini");
  31.    
  32.     set_task( 10.0, "CheckCvars", _, _, _, "b" );
  33.     ReadCvarsFile( );
  34. }
  35.  
  36. public plugin_end( )
  37. {
  38.     TrieDestroy( g_tCvarName );
  39.     ArrayDestroy( g_aCvars );
  40. }
  41.  
  42. ReadCvarsFile()
  43. {
  44.     if( !file_exists( g_szCvarFile ) )
  45.     {
  46.         write_file( g_szCvarFile, ";Ime Cvara | Min. vrednost | Srednja vrednost | Max. vrednost");
  47.         write_file( g_szCvarFile, "rate 18000 20000 25000" );
  48.         write_file( g_szCvarFile, "fps_max 100 100 100" );
  49.     }
  50.    
  51.     new iFile = fopen( g_szCvarFile, "rt" );
  52.    
  53.     if( !iFile )
  54.         return;
  55.  
  56.     g_aCvars = ArrayCreate( 256 );
  57.     g_tCvarName = TrieCreate( );
  58.  
  59.     new szBuffer[ 128 ], szCvar[ 48 ], iPosition;
  60.     while( !feof( iFile ) )
  61.     {
  62.         fgets( iFile, szBuffer, charsmax( szBuffer ) );
  63.  
  64.         if( !szBuffer[ 0 ] || szBuffer[ 0 ] == '#' || szBuffer[ 0 ] == '/' || szBuffer[ 0 ] == ';' )
  65.             continue;
  66.  
  67.         parse( szBuffer, szCvar, charsmax( szCvar ) );
  68.        
  69.         TrieSetCell( g_tCvarName, szCvar, iPosition );     
  70.         ArrayPushString( g_aCvars, szBuffer );
  71.         iPosition++;
  72.     }
  73.     fclose( iFile );
  74. }
  75.  
  76. public CheckCvars( )
  77. {
  78.     new iAllPlayers[ 32 ], iAllCount;
  79.    
  80.     get_players(iAllPlayers, iAllCount, "ch")
  81.     if( iAllCount )
  82.     {
  83.         new szBuffer[ 128 ], szCvar[ 48 ];
  84.         new iCvarsNum = ArraySize( g_aCvars );
  85.        
  86.         for( --iAllCount; iAllCount >= 0; iAllCount-- )
  87.         {
  88.             new iPlayer = iAllPlayers[ iAllCount ]
  89.    
  90.             for( --iCvarsNum; iCvarsNum >= 0; iCvarsNum-- )
  91.             {
  92.                 ArrayGetString( g_aCvars, iCvarsNum, szBuffer, charsmax( szBuffer ) );
  93.                 parse( szBuffer, szCvar, charsmax( szCvar ) );
  94.                 query_client_cvar( iPlayer, szCvar, "CvarResult_48" );
  95.             }
  96.         }
  97.     }
  98. }
  99.  
  100. public CvarResult_48( iPlayer, const Cvar[ ], const Value[ ] )
  101. {
  102.     static iArrayPosition;
  103.     if( TrieGetCell( g_tCvarName, Cvar, iArrayPosition ) )
  104.     {
  105.         new Float:iValue, Float:iMin, Float:iMax;
  106.         new szBuffer[ 128 ], szCvar[ 48 ], szValue[ 32 ], szMin[ 32 ], szMax[ 32 ];
  107.        
  108.         ArrayGetString( g_aCvars, iArrayPosition, szBuffer, charsmax( szBuffer ) );
  109.         parse( szBuffer, szCvar, charsmax( szCvar ), szMin, charsmax( szMin ), szValue, charsmax( szValue ), szMax, charsmax( szMax ) );
  110.        
  111.         iValue = str_to_float( Value );
  112.         iMin = str_to_float( szMin );
  113.         iMax = str_to_float( szMax );
  114.        
  115.         if( iValue < iMin || iValue > iMax )
  116.             client_cmd( iPlayer, "%s %s", szCvar, szValue );
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement