#if defined _Bux_Main_Core_included
  #endinput
#endif
#define _Bux_Main_Core_included

/* Авторство */
#define VERSION "1.0"
#define AUTHOR "BuxChumStar"

/* Флаги */
#define VIP ADMIN_LEVEL_B
#define ADMIN ADMIN_LEVEL_C
#define HUNTER ADMIN_LEVEL_G
#define GLAVA ADMIN_IMMUNITY

/* Базовые библиотеки */
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < hamsandwich >
#include < fakemeta_util >
#include < fun >
#include < engine >
#include < xs >
#include < sqlx >
#include < dhudmessage >

/* Возвращаем опыт игрока, серебро и золото */
native GetUserLevel( iPlayer )
native SetUserLevel( iPlayer, num )
native GetUserNext( iPlayer )
native SetUserNext( iPlayer, num )
native GetUserGold( iPlayer )
native SetUserGold( iPlayer, num )
native GetUserSilver( iPlayer )
native SetUserSilver( iPlayer, num )

/* Возвращаем функции из режимов */
native get_buttons( iPlayer )
native set_buttons( iPlayer, num )
native set_winchester( iPlayer )
native set_minigun( iPlayer )

/* Туман */
stock Bux_Set_Fog( red, green, blue ) {
	message_begin( MSG_ALL, get_user_msgid( "Fog" ) )
	write_byte( red )
	write_byte( green )
	write_byte( blue )
	write_long(_:0.00030) 
	message_end()
}

stock Bux_Reset_Fog( red, green, blue ) {
	message_begin( MSG_ALL, get_user_msgid( "Fog" ) ) 
	write_byte( red )
	write_byte( green )
	write_byte( blue )
	write_long( _:0.00000 ) 
	message_end()
}

/* Скринфэйд */
stock Bux_ScreenFade( iPlayer ) {
	message_begin ( MSG_ONE_UNRELIABLE, get_user_msgid ( "ScreenFade" ), { 0, 0, 0 }, iPlayer )
	write_short ( 1<<10 )
	write_short ( 1<<11 )
	write_short ( 0x0000 )
	write_byte ( random_num( 0, 255 ) )
	write_byte ( random_num( 0, 255 ) )
	write_byte ( random_num( 0, 255 ) )
	write_byte ( random_num ( 50, 100 ) ) // Alpha
	message_end ( )
}

/* Перевод в привелегиях */
stock Bux_ChatReplase( string[], len, const what[], const with[] ) {
	new pos
	if( ( pos = contain( string, what ) ) == -1 ) {
		return 0
	}
	new total, with_len = strlen( with ), diff = strlen( what ) - with_len, total_len = strlen( string ), temp_pos
	while( total_len + with_len < len && replace( string[ pos ], len - pos, what, with ) != 0 ) {
		total++
		pos += with_len
		total_len -= diff
		if ( pos >= total_len ) break
		temp_pos = contain( string[ pos ], what )
		if ( temp_pos == -1 ) break
		pos += temp_pos
	}
	return total
}

#define	get_bit( %1,%2 )	( %1 & ( 1 << ( %2 & 31 ) ) )
#define	set_bit( %1,%2 )	%1 |= ( 1 << ( %2 & 31 ) )
#define	clr_bit( %1,%2 )	%1 &= ~( 1 << ( %2 & 31 ) )

/* Цветной чат */
stock Bux_ColorPrint( const iPlayer, const input[], any:... ) {
	new count = 1, players[ 32 ]
	static msg[ 191 ]
	vformat( msg, 190, input, 3 )
	replace_all( msg, 190, "!g", "^4" )
	replace_all( msg, 190, "!y", "^1" )
	replace_all( msg, 190, "!team", "^3" )
	if( iPlayer ) {
		players[ 0 ] = iPlayer
	}
	else {
		get_players( players, count, "ch" )
	}
	for ( new i = 0; i < count; i++ ) {
		if (is_user_connected( players[ i ] ) ) {
			message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
			write_byte( players[ i ] )
			write_string( msg )
			message_end()
		}
	}
}