Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include < amxmodx >
- #include < sqlx >
- new Handle:DB_CONNECT;
- new Handle:DB_TUPLE;
- new error[ 128 ];
- new error_code;
- new pcvar_host, pcvar_user, pcvar_pass, pcvar_db;
- new RuName[ 6 ][ 32 ], WrType[ 6 ][ 32 ], WrName[ 6 ][ 32 ], SName[ 32 ], WrMType[ 6 ][ 32 ], RuMType[ 6 ][ 32 ];
- new Float:Rtime[ 6 ], Float:Wtime[ 6 ], Float:Stime = 999999.0;
- public plugin_init( )
- {
- register_plugin( "Kz Record's", "1.3", "olala" );
- pcvar_host = register_cvar( "kz_sql_host", "127.0.0.1", FCVAR_PROTECTED );
- pcvar_user = register_cvar( "kz_sql_user", "kz", FCVAR_PROTECTED );
- pcvar_pass = register_cvar( "kz_sql_pass", "kz", FCVAR_PROTECTED );
- pcvar_db = register_cvar( "kz_sql_db", "kz", FCVAR_PROTECTED );
- new host[ 64 ], user[ 64 ], pass[ 64 ], db[ 64 ];
- get_pcvar_string( pcvar_host, host, charsmax( host ) );
- get_pcvar_string( pcvar_user, user, charsmax( user ) );
- get_pcvar_string( pcvar_pass, pass, charsmax( pass ) );
- get_pcvar_string( pcvar_db, db, charsmax( db ) );
- DB_TUPLE = SQL_MakeDbTuple( host, user, pass, db );
- DB_CONNECT = SQL_Connect( DB_TUPLE, error_code, error, 127 );
- if( DB_CONNECT == Empty_Handle )
- {
- log_amx( "Can't connect to MySQL, error: %s", error );
- return PLUGIN_HANDLED;
- }
- else
- {
- new query_c[ 1024 ];
- 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" )
- SQL_ThreadQuery( DB_TUPLE, "QueryHandle", query_c );
- new map[ 64 ];
- get_mapname( map, charsmax( map ) );
- new Handle:queryR, Handle:queryW, Handle:queryProMap;
- new Handle:_queryR, Handle:_queryW;
- // RU
- _queryR = SQL_PrepareQuery( DB_CONNECT, "SELECT COUNT(*) FROM `kz_records` WHERE map_name='%s' AND fin_time != '0' AND type = 'RU'", map );
- 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 );
- // WR
- _queryW = SQL_PrepareQuery( DB_CONNECT, "SELECT COUNT(*) FROM `kz_records` WHERE map_name='%s' AND fin_time != '0' AND type != 'RU'", map );
- 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 );
- // SERVER
- queryProMap = SQL_PrepareQuery( DB_CONNECT, "SELECT `name`,`time` FROM kz_pro15 WHERE mapname='%s' ORDER BY time LIMIT 1", map );
- if( !SQL_Execute( _queryR ) )
- {
- SQL_QueryError( _queryR, error, 127 );
- }
- SQL_FreeHandle( _queryR );
- if( !SQL_Execute( queryR ) )
- {
- SQL_QueryError( queryR, error, 127 );
- }
- else
- {
- if( SQL_NumResults( queryR ) )
- {
- new x = 0;
- while( SQL_MoreResults( queryR ) )
- {
- SQL_ReadResult( queryR, 2, RuMType[ x ], 31 );
- SQL_ReadResult( queryR, 3, Rtime[ x ] );
- SQL_ReadResult( queryR, 5, RuName[ x ], 31 );
- SQL_NextRow( queryR );
- x++;
- }
- }
- else
- {
- Rtime[ 0 ] = 0.0;
- }
- }
- SQL_FreeHandle( queryR );
- if( !SQL_Execute( _queryW ) )
- {
- SQL_QueryError( _queryW, error, 127 );
- }
- SQL_FreeHandle( _queryW );
- if( !SQL_Execute( queryW ) )
- {
- SQL_QueryError( queryW, error, 127 );
- }
- else
- {
- if( SQL_NumResults( queryW ) )
- {
- new y = 0;
- while( SQL_MoreResults( queryW ) )
- {
- SQL_ReadResult( queryW, 0, WrType[ y ], 31 );
- SQL_ReadResult( queryW, 2, WrMType[ y ], 31 );
- SQL_ReadResult( queryW, 3, Wtime[ y ] );
- SQL_ReadResult( queryW, 5, WrName[ y ], 31 );
- SQL_NextRow( queryW );
- y++;
- }
- }
- else
- {
- Wtime[ 0 ] = 0.0;
- }
- }
- SQL_FreeHandle( queryW );
- if( !SQL_Execute( queryProMap ) )
- {
- SQL_QueryError( queryProMap, error, 127 );
- }
- else
- {
- if( SQL_NumResults( queryProMap ) )
- {
- SQL_ReadResult( queryProMap, 0, SName, 31 );
- SQL_ReadResult( queryProMap, 1, Stime );
- }
- else
- {
- Stime = 999999.0;
- }
- }
- SQL_FreeHandle( queryProMap );
- }
- return PLUGIN_CONTINUE;
- }
- public QueryHandle( failstate, Handle:query, error[ ], errnum, data[ ], size, Float:queuetime )
- {
- if( failstate != TQUERY_SUCCESS )
- {
- log_amx( "Records SQL: SQL Error #%d - %s", errnum, error );
- }
- return PLUGIN_CONTINUE;
- }
- public client_putinserver( id )
- {
- if( !is_user_bot( id ) || !is_user_hltv( id ) )
- {
- set_task( 7.0, "GetServerRec", id );
- set_task( 7.0, "PrintRu", id );
- set_task( 7.0, "PrintWr", id );
- }
- }
- public client_command( id )
- {
- new cmd[ 21 ]
- read_argv( 0, cmd, 20 )
- if( equal( cmd, "say" ) || equal( cmd, "say_team" ) )
- {
- read_argv( 1, cmd, 20 )
- trim( cmd )
- if( contain( cmd, " " ) > -1 )
- {
- return PLUGIN_CONTINUE;
- }
- }
- if( equal( cmd, "/", 1 ) || equal( cmd, "\", 1 ) || equal( cmd, ".", 1 ) || equal( cmd, "!", 1 ) )
- {
- copy( cmd, 20, cmd[ 1 ] )
- }
- if( equali( cmd, "wr" ) || equali( cmd, "xj" ) || equali( cmd, "cc" ) )
- {
- PrintWr( id )
- }
- else if( equali( cmd, "ru" ) || equali( cmd, "kzru" ) )
- {
- PrintRu( id )
- }
- else if( equali( cmd, "record" ) || equali( cmd, "rec" ) )
- {
- GetServerRec( id )
- }
- else
- {
- return PLUGIN_CONTINUE;
- }
- return PLUGIN_HANDLED;
- }
- public PrintRu( id )
- {
- if( Rtime[ 0 ] == 0 )
- {
- client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Russian record on:^x01 N/A" );
- }
- else
- {
- new minutes, Float:seconds;
- minutes = floatround( Rtime[ 0 ], floatround_floor ) / 60;
- seconds = Rtime[ 0 ] - ( 60 * minutes );
- 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 ] );
- }
- return PLUGIN_HANDLED;
- }
- public PrintWr( id )
- {
- if( Wtime[ 0 ] == 0 )
- {
- client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current World record on:^x01 N/A" );
- }
- else
- {
- new minutes, Float:seconds;
- minutes = floatround( Wtime[ 0 ], floatround_floor ) / 60;
- seconds = Wtime[ 0 ] - ( 60 * minutes );
- 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 ] );
- }
- return PLUGIN_HANDLED;
- }
- public GetServerRec( id )
- {
- if( Stime == 999999.0 )
- {
- client_print_color( id, print_team_grey, "^x04[Kz]^x03 Current Server record on:^x01 N/A" );
- }
- else
- {
- new minutes, Float:seconds;
- minutes = floatround( Stime, floatround_floor ) / 60;
- seconds = Stime - ( 60 * minutes );
- 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 );
- }
- return PLUGIN_HANDLED;
- }
- public plugin_end( )
- {
- SQL_FreeHandle( DB_TUPLE );
- SQL_FreeHandle( DB_CONNECT );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement