Advertisement
Guest User

rec

a guest
Oct 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.28 KB | None | 0 0
  1.  
  2.     #include < amxmodx >
  3.     #include < sqlx >
  4.  
  5.     new Handle:DB_CONNECT;
  6.     new Handle:DB_TUPLE;
  7.  
  8.     new error[ 128 ];
  9.     new error_code;
  10.  
  11.     new pcvar_host, pcvar_user, pcvar_pass, pcvar_db;
  12.  
  13.     new RuName[ 6 ][ 32 ], WrType[ 6 ][ 32 ], WrName[ 6 ][ 32 ], SName[ 32 ], WrMType[ 6 ][ 32 ], RuMType[ 6 ][ 32 ];
  14.     new Float:Rtime[ 6 ], Float:Wtime[ 6 ], Float:Stime = 999999.0;
  15.  
  16.     public plugin_init( )
  17.     {
  18.         register_plugin( "Kz Record's", "1.3", "olala" );
  19.  
  20.         pcvar_host = register_cvar( "kz_sql_host", "127.0.0.1", FCVAR_PROTECTED );
  21.         pcvar_user = register_cvar( "kz_sql_user", "kz", FCVAR_PROTECTED );
  22.         pcvar_pass = register_cvar( "kz_sql_pass", "kz", FCVAR_PROTECTED );
  23.         pcvar_db = register_cvar( "kz_sql_db", "kz", FCVAR_PROTECTED );
  24.  
  25.         new host[ 64 ], user[ 64 ], pass[ 64 ], db[ 64 ];
  26.         get_pcvar_string( pcvar_host, host, charsmax( host ) );
  27.         get_pcvar_string( pcvar_user, user, charsmax( user ) );
  28.         get_pcvar_string( pcvar_pass, pass, charsmax( pass ) );
  29.         get_pcvar_string( pcvar_db, db, charsmax( db ) );
  30.  
  31.         DB_TUPLE = SQL_MakeDbTuple( host, user, pass, db );
  32.         DB_CONNECT = SQL_Connect( DB_TUPLE, error_code, error, 127 );
  33.  
  34.         if( DB_CONNECT == Empty_Handle )
  35.         {
  36.             log_amx( "Can't connect to MySQL, error: %s", error );
  37.  
  38.             return PLUGIN_HANDLED;
  39.         }
  40.         else
  41.         {
  42.             new query_c[ 1024 ];
  43.             formatex( query_c, sizeof query_c - 1, "CREATE TABLE IF NOT EXISTS `kz_records` (`type` varchar(32) DEFAULT NULL,`map_name` varchar(32) DEFAULT NULL,`map_type` varchar(32) DEFAULT '0',`fin_time` float DEFAULT NULL, `country` varchar(3) default NULL, `name` varchar(32) DEFAULT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8" )
  44.             SQL_ThreadQuery( DB_TUPLE, "QueryHandle", query_c );
  45.  
  46.             new map[ 64 ];
  47.             get_mapname( map, charsmax( map ) );
  48.  
  49.             new Handle:queryR, Handle:queryW, Handle:queryProMap;
  50.             new Handle:_queryR, Handle:_queryW;
  51.  
  52.             // RU
  53.             _queryR = SQL_PrepareQuery( DB_CONNECT, "SELECT COUNT(*) FROM `kz_records` WHERE map_name='%s' AND fin_time != '0' AND type = 'RU'", map );
  54.             queryR = SQL_PrepareQuery( DB_CONNECT, "SELECT * FROM `kz_records` WHERE map_name='%s' AND fin_time != '0' AND type = 'RU' ORDER BY `map_type` , `fin_time` ASC", map );
  55.  
  56.             // WR
  57.             _queryW = SQL_PrepareQuery( DB_CONNECT, "SELECT COUNT(*) FROM `kz_records` WHERE map_name='%s'  AND fin_time != '0' AND type != 'RU'", map );
  58.             queryW = SQL_PrepareQuery( DB_CONNECT, "SELECT * FROM `kz_records` WHERE map_name='%s'  AND fin_time != '0' AND type != 'RU' ORDER BY `map_type` , `fin_time` ASC", map );
  59.  
  60.             // SERVER
  61.             queryProMap = SQL_PrepareQuery( DB_CONNECT, "SELECT `name`,`time` FROM kz_pro15 WHERE mapname='%s' ORDER BY time LIMIT 1", map );
  62.  
  63.             if( !SQL_Execute( _queryR ) )
  64.             {
  65.                 SQL_QueryError( _queryR, error, 127 );
  66.             }
  67.  
  68.             SQL_FreeHandle( _queryR );
  69.  
  70.             if( !SQL_Execute( queryR ) )
  71.             {
  72.                 SQL_QueryError( queryR, error, 127 );
  73.             }
  74.             else
  75.             {
  76.                 if( SQL_NumResults( queryR ) )
  77.                 {
  78.                     new x = 0;
  79.  
  80.                     while( SQL_MoreResults( queryR ) )
  81.                     {
  82.                         SQL_ReadResult( queryR, 2, RuMType[ x ], 31 );
  83.                         SQL_ReadResult( queryR, 3, Rtime[ x ] );
  84.                         SQL_ReadResult( queryR, 5, RuName[ x ], 31 );
  85.                         SQL_NextRow( queryR );
  86.  
  87.                         x++;
  88.                     }
  89.                 }
  90.                 else
  91.                 {
  92.                     Rtime[ 0 ] = 0.0;
  93.                 }
  94.             }
  95.  
  96.             SQL_FreeHandle( queryR );
  97.  
  98.             if( !SQL_Execute( _queryW ) )
  99.             {
  100.                 SQL_QueryError( _queryW, error, 127 );
  101.             }
  102.  
  103.             SQL_FreeHandle( _queryW );
  104.            
  105.             if( !SQL_Execute( queryW ) )
  106.             {
  107.                 SQL_QueryError( queryW, error, 127 );
  108.             }
  109.             else
  110.             {
  111.                 if( SQL_NumResults( queryW ) )
  112.                 {
  113.                     new y = 0;
  114.  
  115.                     while( SQL_MoreResults( queryW ) )
  116.                     {
  117.                         SQL_ReadResult( queryW, 0, WrType[ y ], 31 );
  118.                         SQL_ReadResult( queryW, 2, WrMType[ y ], 31 );
  119.                         SQL_ReadResult( queryW, 3, Wtime[ y ] );
  120.                         SQL_ReadResult( queryW, 5, WrName[ y ], 31 );
  121.                         SQL_NextRow( queryW );
  122.  
  123.                         y++;
  124.                     }
  125.                 }
  126.                 else
  127.                 {
  128.                     Wtime[ 0 ] = 0.0;
  129.                 }
  130.             }
  131.  
  132.             SQL_FreeHandle( queryW );
  133.  
  134.             if( !SQL_Execute( queryProMap ) )
  135.             {
  136.                 SQL_QueryError( queryProMap, error, 127 );
  137.             }
  138.             else
  139.             {
  140.                 if( SQL_NumResults( queryProMap ) )
  141.                 {
  142.                     SQL_ReadResult( queryProMap, 0, SName, 31 );
  143.                     SQL_ReadResult( queryProMap, 1, Stime );
  144.                 }
  145.                 else
  146.                 {
  147.                     Stime = 999999.0;
  148.                 }
  149.             }
  150.  
  151.             SQL_FreeHandle( queryProMap );
  152.         }
  153.  
  154.         return PLUGIN_CONTINUE;
  155.     }
  156.  
  157.     public QueryHandle( failstate, Handle:query, error[ ], errnum, data[ ], size, Float:queuetime )
  158.     {
  159.         if( failstate != TQUERY_SUCCESS )
  160.         {
  161.             log_amx( "Records SQL: SQL Error #%d - %s", errnum, error );
  162.         }
  163.  
  164.         return PLUGIN_CONTINUE;
  165.     }
  166.  
  167.     public client_putinserver( id )
  168.     {  
  169.         if( !is_user_bot( id ) || !is_user_hltv( id ) )
  170.         {
  171.             set_task( 7.0, "GetServerRec", id );
  172.             set_task( 7.0, "PrintRu", id );
  173.             set_task( 7.0, "PrintWr", id );
  174.         }
  175.     }
  176.  
  177.     public client_command( id )
  178.     {
  179.         new cmd[ 21 ]
  180.         read_argv( 0, cmd, 20 )
  181.  
  182.         if( equal( cmd, "say" ) || equal( cmd, "say_team" ) )
  183.         {
  184.             read_argv( 1, cmd, 20 )
  185.             trim( cmd )
  186.  
  187.             if( contain( cmd, " " ) > -1 )
  188.             {
  189.                 return PLUGIN_CONTINUE;
  190.             }
  191.         }
  192.  
  193.         if( equal( cmd, "/", 1 ) || equal( cmd, "\", 1 ) || equal( cmd, ".", 1 ) || equal( cmd, "!", 1 ) )
  194.         {
  195.             copy( cmd, 20, cmd[ 1 ] )
  196.         }
  197.  
  198.         if( equali( cmd, "wr" ) || equali( cmd, "xj" ) || equali( cmd, "cc" ) )
  199.         {
  200.             PrintWr( id )
  201.         }
  202.         else if( equali( cmd, "ru" ) || equali( cmd, "kzru" ) )
  203.         {
  204.             PrintRu( id )
  205.         }
  206.         else if( equali( cmd, "record" ) || equali( cmd, "rec" ) )
  207.         {
  208.             GetServerRec( id )
  209.         }
  210.         else
  211.         {
  212.             return PLUGIN_CONTINUE;
  213.         }
  214.  
  215.         return PLUGIN_HANDLED;
  216.     }
  217.  
  218.     public PrintRu( id )
  219.     {
  220.         if( Rtime[ 0 ] == 0 )
  221.         {
  222.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Russian record on:^x01 N/A" );
  223.         }
  224.         else
  225.         {
  226.             new minutes, Float:seconds;
  227.             minutes = floatround( Rtime[ 0 ], floatround_floor ) / 60;
  228.             seconds = Rtime[ 0 ] - ( 60 * minutes );
  229.  
  230.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Russian record on: !y%s !g[!t %02d:%s%.2f !g] %s !y[KZRU]", RuName[ 0 ], minutes, seconds < 10 ? "0" : "", seconds, RuMType[ 0 ][ 1 ] == 0 ? "" : RuMType[ 0 ] );
  231.         }
  232.  
  233.         return PLUGIN_HANDLED;
  234.     }
  235.  
  236.     public PrintWr( id )
  237.     {
  238.         if( Wtime[ 0 ] == 0 )
  239.         {
  240.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current World record on:^x01 N/A" );
  241.         }
  242.         else
  243.         {
  244.             new minutes, Float:seconds;
  245.             minutes = floatround( Wtime[ 0 ], floatround_floor ) / 60;
  246.             seconds = Wtime[ 0 ] - ( 60 * minutes );
  247.  
  248.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current World record on: !y%s !g[!t %02d:%s%.2f !g] %s !y[%s]", WrName[ 0 ], minutes, seconds < 10 ? "0" : "", seconds, WrMType[ 0 ][ 1 ] == 0 ? "" : WrMType[ 0 ], WrType[ 0 ] );
  249.         }
  250.  
  251.         return PLUGIN_HANDLED;
  252.     }
  253.  
  254.     public GetServerRec( id )
  255.     {
  256.         if( Stime == 999999.0 )
  257.         {
  258.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Server record on:^x01 N/A" );
  259.         }
  260.         else
  261.         {
  262.             new minutes, Float:seconds;
  263.             minutes = floatround( Stime, floatround_floor ) / 60;
  264.             seconds = Stime - ( 60 * minutes );
  265.  
  266.             client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Server record on: !y%s !g[!t %02d:%s%.2f !g]", SName, minutes, seconds < 10 ? "0" : "", seconds );
  267.         }
  268.  
  269.         return PLUGIN_HANDLED;
  270.     }
  271.  
  272.     public plugin_end( )
  273.     {
  274.         SQL_FreeHandle( DB_TUPLE );
  275.         SQL_FreeHandle( DB_CONNECT );
  276.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement