#include < amxmodx >
#include < engine >
#include < hamsandwich >
#include < sqlx >
#include < RegSystem >

#pragma semicolon 1

#define PRIMARIWEAPON 3 // Scout
#define KNIFEID 29 // KNIFE
#define CHESTNUM 4 // Lada szama

new const g_sPrefix[ ] = "WorldServer";

new const g_sSQL_INFOS[ ][ ] =
{
	"",     // HOST
	"",     // USERNAME
	"",     // PASSWORD
	""  // DATABASE
};

new const g_sDefPrefix[ ][ ] =
{
	"",
	"Tulaj", //Tulaj
	"FõAdmin", //Foadmin
	"Admin", //Admin
	"VIP", //Premium VIP
	"VIP" //VIP
};

new const g_sDefKnife[ ] = "models/worldsniper/knife/knife.mdl";
new const g_sDefSniper[ ] = "models/worldsniper/scout/scout.mdl";
new sBuffer[ 32 ];

new Handle: g_iSqlTuple, bool: g_bIsUser[ MAX_PLAYERS + 1 ], g_iUId[ MAX_PLAYERS + 1 ], g_iURang[ MAX_PLAYERS + 1 ], g_sUDate[ MAX_PLAYERS + 1 ][ 32 ], g_sUName[ MAX_PLAYERS + 1 ][ 16 ], g_sUPass[ MAX_PLAYERS + 1 ][ 16 ], g_sUPrefix[ MAX_PLAYERS + 1 ][ 16 ], g_sUADate[ MAX_PLAYERS + 1 ][ 32 ];
new Array: g_daSkins[ 6 ], Array: g_daChestKey[ 6 ], Array: g_daMarket[ 3 ], g_iUSkins[ MAX_PLAYERS + 1 ][ 80 ], g_iSkins, g_iMarket;
new g_iChests[ MAX_PLAYERS + 1 ][ CHESTNUM ], g_iKeys[ MAX_PLAYERS + 1 ][ CHESTNUM ], g_iMoney[ MAX_PLAYERS + 1 ], g_iMenu[ MAX_PLAYERS + 1 ], g_iUsingSniper[ MAX_PLAYERS + 1 ] = -1, g_iUsingKnife[ MAX_PLAYERS + 1 ] = -1, g_iUMarket[ MAX_PLAYERS + 1 ], g_iSelected[ MAX_PLAYERS + 1 ][ 4 ], g_iSNum[ MAX_PLAYERS + 1 ][ 5 ], g_iSWeaps[ MAX_PLAYERS + 1 ][ 5 ], bool: g_bOptions[ MAX_PLAYERS + 1 ][ 6 ];
new g_sName[ MAX_PLAYERS + 1 ][ 32 ], g_iSnipSkins, g_iKnifeSkins;

public plugin_init( )
{
	register_plugin( "Skin System", "1.0", "Demon" );
	register_cvar( "Skin System", "By Demon", FCVAR_SERVER );
	
	register_dictionary( "RegSystem.txt" );
	
	g_iSqlTuple = SQL_MakeDbTuple( g_sSQL_INFOS[ 0 ], g_sSQL_INFOS[ 1 ], g_sSQL_INFOS[ 2 ], g_sSQL_INFOS[ 3 ] );
	
	RegisterHam( Ham_Item_Deploy, "weapon_knife", "fwWeaponKnifePost", 1, true );
	RegisterHam( Ham_Item_Deploy, "weapon_scout", "fwWeaponSniperPost", 1, true );
	
	register_event( "DeathMsg", "evDeathPost", "a" );
	
	register_clcmd( "say /menu", "cmdMenu" );
	register_clcmd( "say /menuki", "cmdMenuKi" );
	register_clcmd( "say /skin", "cmdSkin" );
	register_impulse( 201, "cmdMenu2" );
	
	register_clcmd( "Dollar", "GetCost" );
	register_clcmd( "Mennyiseg", "GetPiece" );
}

public cmdSkin( iPlayerId )
{
	client_print_color( iPlayerId, iPlayerId, "^4[%s] %L", g_sPrefix, iPlayerId, ( g_bOptions[ iPlayerId ][ 0 ] ^= true ) ? "SNIPER60" : "SNIPER61" );
	g_iUsingKnife[ iPlayerId ] = g_iUsingSniper[ iPlayerId ] = g_bOptions[ iPlayerId ][ 0 ] ? -1 : -2;
}
public cmdMenuKi( iPlayerId ) { client_print_color( iPlayerId, iPlayerId, "^4[%s] ^3%skapcsoltad^1 a menüt!", g_sPrefix, ( g_bOptions[ iPlayerId ][ 5 ] ^= true ) ? "Be" : "Ki" ); }

public plugin_natives( ) { register_native( "dn_get_user_vis", "_get_vis", 1 ); }
 
public _get_vis( iPlayerId ) { return g_bOptions[ iPlayerId ][ 4 ]; }

public fwWeaponKnifePost( iEnt )
{
	new iOwner = entity_get_edict( iEnt, EV_ENT_owner );
	
	if ( 0 < iOwner <= MaxClients )
	{
		if ( g_iUsingKnife[ iOwner ] > -1 && g_bIsUser[ iOwner ] )
		{
			new sModels[ 128 ];
			ArrayGetString( g_daSkins[ 1 ], g_iUsingKnife[ iOwner ], sModels, charsmax( sModels ) );
			entity_set_string( iOwner, EV_SZ_viewmodel, sModels );
		}
		else if ( g_iUsingKnife[ iOwner ] != -2 ) entity_set_string( iOwner, EV_SZ_viewmodel, g_sDefKnife );
	}
}

public fwWeaponSniperPost( iEnt )
{
	new iOwner = entity_get_edict( iEnt, EV_ENT_owner );
	
	if ( 0 < iOwner <= MaxClients )
	{
		if ( g_iUsingSniper[ iOwner ] > -1 && g_bIsUser[ iOwner ] )
		{
			new sModels[ 128 ];
			ArrayGetString( g_daSkins[ 1 ], g_iUsingSniper[ iOwner ], sModels, charsmax( sModels ) );
			entity_set_string( iOwner, EV_SZ_viewmodel, sModels );
		}
		else if ( g_iUsingSniper[ iOwner ] != -2 )  entity_set_string( iOwner, EV_SZ_viewmodel, g_sDefSniper );
	}
}

public evDeathPost( )
{
	new iKiller = read_data( 1 );
	
	if ( 0 < iKiller <= MaxClients )
	{
		if ( !g_bIsUser[ iKiller ] ) return;
		new iHs = read_data( 3 );
		new iRand = read_data( 3 ) ? random_num( 1, 6 ) : random_num( 1, 3 ), Float: fRandom = random_float( 0.0, 100.0 );
		if ( 0 < g_iURang[ iKiller ] < 6 )
		{
			iRand = iHs ? random_num( 2, 7 ) : random_num( 2, 4 );
			fRandom = random_float( 0.0, 90.0 );
		}
		
		g_iMoney[ iKiller ] += iRand;
		
		iRand = random_num( 1, 2 );
		
		if ( iRand == 1 )
		{
			for ( new i = CHESTNUM - 1; i >= 0; --i )
			{
				if ( Float: ArrayGetCell( g_daChestKey[ 3 ], i ) >= Float: fRandom )
				{
					++g_iKeys[ iKiller ][ i ];
					client_print_color( 0, print_team_default, "^4[%s] ^3%L", g_sPrefix, LANG_PLAYER, "SNIPER59", g_sName[ iKiller ], ArrayGetStringHandle( g_daChestKey[ 2 ], i ), Float:ArrayGetCell( g_daChestKey[ 3 ], i ) );
					break;
				}
			}
		}
		else
		{
			for ( new i = CHESTNUM - 1; i >= 0; --i )
			{
				if ( Float: ArrayGetCell( g_daChestKey[ 1 ], i ) >= Float: fRandom )
				{
					++g_iChests[ iKiller ][ i ];
					client_print_color( 0, print_team_default, "^4[%s] ^3%L", g_sPrefix, LANG_PLAYER, "SNIPER59", g_sName[ iKiller ], ArrayGetStringHandle( g_daChestKey[ 0 ], i ), Float:ArrayGetCell( g_daChestKey[ 1 ], i ) );
					break;
				}
			}
		}
	}
}

public client_putinserver( iPlayerId )
{
	ResetVars( iPlayerId );
	for( new i; i < 6; ++i ) g_bOptions[ iPlayerId ][ i ] = true;
	get_user_name( iPlayerId, g_sName[ iPlayerId ], 31 );
	
}
public client_disconnected( iPlayerId )
{
	RemoveMarketItems( iPlayerId, -1 );
	if ( g_bIsUser[ iPlayerId ] ) SaveDatas( iPlayerId, 0 );
	g_bIsUser[ iPlayerId ] = false;
}

public cmdMenu2( iPlayerId )
{
	if ( !g_bOptions[ iPlayerId ][ 5 ] ) return;
	cmdMenu( iPlayerId );
}

public cmdMenu( iPlayerId )
{
	if ( !g_bIsUser[ iPlayerId ] ) MainMenu( iPlayerId, -1 );
	else MainMenu( iPlayerId, 0 );
}

public plugin_precache( )
{
	precache_model( g_sDefKnife );
	precache_model( g_sDefSniper );
	
	g_daMarket[ 0 ] = ArrayCreate( 1 );
	g_daMarket[ 1 ] = ArrayCreate( 1 );
	g_daMarket[ 2 ] = ArrayCreate( 1 );
	
	g_daSkins[ 0 ] = ArrayCreate( 64 );
	g_daSkins[ 1 ] = ArrayCreate( 128 );
	g_daSkins[ 2 ] = ArrayCreate( 1 );
	g_daSkins[ 3 ] = ArrayCreate( 1 );
	g_daSkins[ 4 ] = ArrayCreate( 1 );
	g_daSkins[ 5 ] = ArrayCreate( 1 );
	
	g_daChestKey[ 0 ] = ArrayCreate( 32 );
	g_daChestKey[ 1 ] = ArrayCreate( 1 );
	g_daChestKey[ 2 ] = ArrayCreate( 32 );
	g_daChestKey[ 3 ] = ArrayCreate( 1 );
	g_daChestKey[ 4 ] = ArrayCreate( 1 );
	g_daChestKey[ 5 ] = ArrayCreate( 1 );
	
	new sFile[ 64 ], pFile;
	get_localinfo( "amxx_configsdir", sFile, charsmax( sFile ) );
	add( sFile, charsmax( sFile ), "/skins.txt" );
	
	pFile = fopen( sFile, "rt" );
	
	if ( pFile )
	{
		new sBuffer[ 128 ], iNum = -1, sData[ 5 ][ 128 ];
		
		while ( !feof( pFile ) )
		{
			fgets( pFile, sBuffer, charsmax( sBuffer ) );
			trim( sBuffer );
			
			if ( sBuffer[ 0 ] == '/' || sBuffer[ 0 ] == ';' || !sBuffer[ 0 ] ) continue;
			
			if ( sBuffer[ 0 ] == '[' )
			{
				sBuffer[ 0 ] = ' ';
				sBuffer[ strlen( sBuffer ) - 1 ] = EOS;
				iNum = str_to_num( sBuffer );
				continue;
			}
			
			if ( iNum != PRIMARIWEAPON && iNum != KNIFEID ) continue;
			
			switch ( iNum )
			{
				case PRIMARIWEAPON: g_iSnipSkins++;
				case KNIFEID: g_iKnifeSkins++;
			}
			
			parse( sBuffer, sData[ 0 ], 127, sData[ 1 ], 127, sData[ 2 ], 127, sData[ 3 ], 127, sData[ 4 ], 127 );
			
			ArrayPushString( g_daSkins[ 0 ], sData[ 0 ] );
			CheckModel( sData[ 1 ], 127 );
			ArrayPushCell( g_daSkins[ 2 ], str_to_float( sData[ 2 ] ) );
			ArrayPushCell( g_daSkins[ 3 ], iNum );
			ArrayPushCell( g_daSkins[ 4 ], str_to_num( sData[ 3 ] ) );
			ArrayPushCell( g_daSkins[ 5 ], str_to_num( sData[ 4 ] ) );
		}
		
		fclose( pFile );
		g_iSkins = ArraySize( g_daSkins[ 0 ] );
		if ( g_iSkins > 80 ) g_iSkins = 80;
	}
	else
	{
		format( sFile, charsmax( sFile ), "Nem talalhato a %s fajl!", sFile );
		set_fail_state( sFile );
	}
	
	get_localinfo( "amxx_configsdir", sFile, charsmax( sFile ) );
	add( sFile, charsmax( sFile ), "/chest_key_names.txt" );
	
	pFile = fopen( sFile, "rt" );
	
	if ( pFile )
	{
		new sBuffer[ 32 ], sData[ 6 ][ 16 ];
		
		while ( !feof( pFile ) )
		{
			fgets( pFile, sBuffer, charsmax( sBuffer ) );
			trim( sBuffer );
			
			if ( sBuffer[ 0 ] == '/' || sBuffer[ 0 ] == ';' || !sBuffer[ 0 ] ) continue;
			
			parse( sBuffer, sData[ 0 ], 15, sData[ 1 ], 15, sData[ 2 ], 15, sData[ 3 ], 15, sData[ 4 ], 15, sData[ 5 ], 15 );
			
			ArrayPushString( g_daChestKey[ 0 ], sData[ 0 ] );
			ArrayPushCell( g_daChestKey[ 1 ], str_to_float( sData[ 1 ] ) );
			ArrayPushString( g_daChestKey[ 2 ], sData[ 3 ] );
			ArrayPushCell( g_daChestKey[ 3 ], str_to_float( sData[ 4 ] ) );
			ArrayPushCell( g_daChestKey[ 4 ], str_to_num( sData[ 2 ] ) );
			ArrayPushCell( g_daChestKey[ 5 ], str_to_num( sData[ 5 ] ) );
		}
		
		fclose( pFile );
	}
	else
	{
		format( sFile, charsmax( sFile ), "Nem talalhato a %s fajl!", sFile );
		set_fail_state( sFile );
	}
}

CheckModel( sMdl[ ], iMdl )
{
	if ( !equal( sMdl, "models/", 7 ) )
		format( sMdl, iMdl, "models/%s", sMdl );
	
	if ( !equal( sMdl[ strlen( sMdl ) - 4 ], ".mdl", 4 ) )
		add( sMdl, iMdl, ".mdl" );
	
	precache_model( sMdl );
	ArrayPushString( g_daSkins[ 1 ], sMdl );
}

public dn_user_logged_in( iPlayerId, iUId, sUName[ ], sUPass[ ], sUDate[ ], iURang, sUPrefix[ ], sADate[ ] )
{
	g_bIsUser[ iPlayerId ] = true;
	g_iUId[ iPlayerId ] = iUId;
	copy( g_sUName[ iPlayerId ], 15, sUName );
	copy( g_sUPass[ iPlayerId ], 15, sUPass );
	copy( g_sUDate[ iPlayerId ], 31, sUDate );
	g_iURang[ iPlayerId ] = iURang;
	copy( g_sUPrefix[ iPlayerId ], 15, sUPrefix );
	copy( g_sUADate[ iPlayerId ], 31, sADate );
	g_iUsingSniper[ iPlayerId ] = g_iUsingKnife[ iPlayerId ] = -1;
	
	LoadDatas( iPlayerId, 1 );
}
public dn_user_changed_prefix( iPlayerId, sNewPrefix[ ] )
{
	copy( g_sUPrefix[ iPlayerId ], 15, sNewPrefix );
}

public dn_user_logged_out( iPlayerId )
{
	SaveDatas( iPlayerId, 0 );
	g_bIsUser[ iPlayerId ] = false;
	MainMenu( iPlayerId, -1 );
	RemoveMarketItems( iPlayerId, -1 );
	
	set_task( 4.0, "ResetVars", iPlayerId );
}

public ResetVars( iPlayerId )
{
	g_iMoney[ iPlayerId ] = g_iUId[ iPlayerId ] = g_iUMarket[ iPlayerId ] = 0;
	g_bIsUser[ iPlayerId ] = false;
	g_bOptions[ iPlayerId ][ 4 ] = true;
	g_sUName[ iPlayerId ][ 0 ] = g_sUPrefix[ iPlayerId ][ 0 ]= EOS;
	g_iURang[ iPlayerId ] = -1;
	g_iUsingSniper[ iPlayerId ] = g_iUsingKnife[ iPlayerId ] = -2;
	arrayset( g_iUSkins[ iPlayerId ], 0, sizeof g_iUSkins[ ] );
	arrayset( g_iChests[ iPlayerId ], 0, CHESTNUM );
	arrayset( g_iKeys[ iPlayerId ], 0, CHESTNUM );
}

public MainMenu( iPlayerId, iMenu )
{
	new sTxt[ 256 ], iMenuId, sItemId[ 8 ];
	
	switch ( iMenu )
	{
		case -3:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %d", g_sPrefix, iPlayerId, "SNIPER56", iPlayerId, "SNIPER57", g_iSelected[ iPlayerId ][ 1 ] );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			new iAll, bool: bFound;
			for ( new i; i < g_iSkins; i++ )
			{
				if ( g_iUSkins[ iPlayerId ][ i ] < 1 || ( ArrayGetCell( g_daSkins[ 5 ], i ) + 1 ) != g_iSelected[ iPlayerId ][ 1 ] )
					continue;
				bFound = false;
				
				for ( new j; j < g_iSelected[ iPlayerId ][ 0 ]; ++j )
				{
					if ( g_iSWeaps[ iPlayerId ][ j ] == i )
					{
						bFound = true;
						break;
					}
				}
				if ( bFound ) continue;
	 
				formatex( sTxt, 255, "%a\y [\r%d\y]", ArrayGetStringHandle( g_daSkins[ 0 ], i ), g_iUSkins[ iPlayerId ][ i ] );
				formatex( sItemId, 7, "%d -3", i );
				menu_additem( iMenuId, sTxt, sItemId );
				++iAll;
			}
			if ( iAll == 0 )
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, g_iSelected[ iPlayerId ][ 1 ], iPlayerId, "SNIPER58" );
				MainMenu( iPlayerId, 11 );
				return;
			}
		}
		case -2:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER55" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			new iCount;
			
			if ( g_iMenu[ iPlayerId ] == 9 )
			{
				if ( g_iMoney[ iPlayerId ] > 0 )
				{
					formatex( sTxt, 255, "%L\y (\r%d\y)", iPlayerId, "SNIPER10", g_iMoney[ iPlayerId ] );
					menu_additem( iMenuId, sTxt, "-4 -2" );
					++iCount;
				}
			}
			
			for ( new i; i < CHESTNUM; ++i )
			{
				if ( g_iChests[ iPlayerId ][ i ] > 0 )
				{
					formatex( sTxt, 255, "%a\y [\r%d\y]", ArrayGetStringHandle( g_daChestKey[ 0 ], i ), g_iChests[ iPlayerId ][ i ] );
					formatex( sItemId, 7, "%d -2", ( -3 - ( i * 10 ) ) );
					menu_additem( iMenuId, sTxt, sItemId );
					++iCount;
				}
				
				if ( g_iKeys[ iPlayerId ][ i ] > 0 )
				{
					formatex( sTxt, 255, "%a\y [\r%d\y]", ArrayGetStringHandle( g_daChestKey[ 2 ], i ), g_iKeys[ iPlayerId ][ i ] );
					formatex( sItemId, 7, "%d -2", ( -2 - ( i * 10 ) ) );
					menu_additem( iMenuId, sTxt, sItemId );
					++iCount;
				}
			}
			
			for ( new i; i < g_iSkins; ++i )
			{
				if ( g_iUSkins[ iPlayerId ][ i ] > 0 )
				{
					formatex( sItemId, 7, "%d -2", i );
					
					formatex( sTxt, 255, "%a\y [\r%d\y] (\r%d %L\y)", ArrayGetStringHandle( g_daSkins[ 0 ], i ), g_iUSkins[ iPlayerId ][ i ], ArrayGetCell( g_daSkins[ 5 ], i ) + 1, iPlayerId, "SNIPER14" );
					menu_additem( iMenuId, sTxt, sItemId );
					++iCount;
				}
			}
			
			if ( iCount == 0 )
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER11" );
				return;
			}
		}
		case -1:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER9" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			formatex( sTxt, 255, "%L", iPlayerId, "REG3" );
			menu_additem( iMenuId, sTxt, "1 -1" );
			formatex( sTxt, 255, "%L", iPlayerId, "REG4" );
			menu_additem( iMenuId, sTxt, "2 -1" );
		}
		case 0:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %d", g_sPrefix, iPlayerId, "SNIPER9", iPlayerId, "SNIPER10", g_iMoney[ iPlayerId ] );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER1" );
			menu_additem( iMenuId, sTxt, "1 0" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER2" );
			menu_additem( iMenuId, sTxt, "2 0" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER3" );
			menu_additem( iMenuId, sTxt, "3 0" );
			formatex( sTxt, 255, "%L^n", iPlayerId, "SNIPER4" );
			menu_additem( iMenuId, sTxt, "11 0" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER5" );
			menu_additem( iMenuId, sTxt, "4 0" );
			formatex( sTxt, 255, "%L^n", iPlayerId, "SNIPER6" );
			menu_additem( iMenuId, sTxt, "5 0" );
			
			if ( 0 < g_iURang[ iPlayerId ] < 4 )
			{
				formatex( sTxt, 255, "%L", iPlayerId, "SNIPER7" );
				menu_additem( iMenuId, sTxt, "6 0" );
			}
			else if ( g_iURang[ iPlayerId ] == 4 )
			{
				formatex( sTxt, 255, "%L", iPlayerId, "SNIPER8" );
				menu_additem( iMenuId, sTxt, "7 0" );
			}
		}
		case 1:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %d", g_sPrefix, iPlayerId, "SNIPER1", iPlayerId, "SNIPER10", g_iMoney[ iPlayerId ] );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			new iCount;
			
			for ( new i; i < g_iSkins; ++i )
				if ( g_iUSkins[ iPlayerId ][ i ] > 0 )
				{
					++iCount;
					break;
				}
			
			if ( iCount == 0 )
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER11" );
				return;
			}
			
			formatex( sTxt, 255, "\y%L", iPlayerId, "SNIPER12" );
			menu_additem( iMenuId, sTxt, "-1 1" );
			formatex( sTxt, 255, "\y%L: \r%L^n", iPlayerId, "SNIPER13", iPlayerId, g_iSelected[ iPlayerId ][ 3 ] == KNIFEID ? "SNIPER15" : "SNIPER17" );
			menu_additem( iMenuId, sTxt, "-2 1" );
			
			iCount = 0;
			
			for ( new i; i < g_iSkins; ++i )
			{
				if ( g_iUSkins[ iPlayerId ][ i ] > 0 )
				{
					if ( ArrayGetCell( g_daSkins[ 3 ], i ) != g_iSelected[ iPlayerId ][ 3 ] ) continue;
					
					formatex( sItemId, 7, "%d 1", i );
					
					formatex( sTxt, 255, "%a\y [\r%d\y] (\r%d %L\y)", ArrayGetStringHandle( g_daSkins[ 0 ], i ), g_iUSkins[ iPlayerId ][ i ], ArrayGetCell( g_daSkins[ 5 ], i ) + 1, iPlayerId, "SNIPER14" );
					menu_additem( iMenuId, sTxt, sItemId );
					++iCount;
				}
			}
			
			if ( iCount == 0 )
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER18", iPlayerId, g_iSelected[ iPlayerId ][ 3 ] == KNIFEID ? "SNIPER15" : "SNIPER17" );
				g_iSelected[ iPlayerId ][ 3 ] = g_iSelected[ iPlayerId ][ 3 ] == KNIFEID ? PRIMARIWEAPON : KNIFEID;
				g_iMenu[ iPlayerId ] = 1;
				MainMenu( iPlayerId, 1 );
				return;
			}
		}
		case 2:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n\d%L", g_sPrefix, iPlayerId, "SNIPER2", iPlayerId, "SNIPER19" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			for ( new i; i < CHESTNUM; ++i )
			{
				formatex( sTxt, 255, "%a %L \d|\y %d %L \d|\y %d %L", ArrayGetStringHandle( g_daChestKey[ 0 ], i ), iPlayerId, "SNIPER20", g_iChests[ iPlayerId ][ i ], iPlayerId, "SNIPER21", g_iKeys[ iPlayerId ][ i ], iPlayerId, "SNIPER22" );
				formatex( sItemId, 7, "%d 2", i );
				menu_additem( iMenuId, sTxt, sItemId );
			}
		}
		case 3:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER3" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER23" );
			menu_additem( iMenuId, sTxt, "8 3" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER24" );
			menu_additem( iMenuId, sTxt, "12 3" );
			formatex( sTxt, 255, "%L", iPlayerId, "SNIPER25" );
			menu_additem( iMenuId, sTxt, "9 3" );
		}
		case 4:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER5" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			formatex( sTxt, 255, "%L: %L", iPlayerId, "SNIPER26", iPlayerId, ( g_iUsingKnife[ iPlayerId ] != -2 ) ? "SNIPER30" : "SNIPER31" );
			menu_additem( iMenuId, sTxt, "-1 4" );
			formatex( sTxt, 255, "%L: %L", iPlayerId, "SNIPER28", iPlayerId, ( g_iUsingSniper[ iPlayerId ] != -2 ) ? "SNIPER30" : "SNIPER31" );
			menu_additem( iMenuId, sTxt, "0 4" );
			formatex( sTxt, 255, "%L: %L", iPlayerId, "SNIPER29", iPlayerId, g_bOptions[ iPlayerId ][ 3 ] ? "SNIPER30" : "SNIPER31" );
			menu_additem( iMenuId, sTxt, "3 4" );
			formatex( sTxt, 255, "%L^n", iPlayerId, "SNIPER32" );
			menu_additem( iMenuId, sTxt, "4 4" );
			formatex( sTxt, 255, "%L^n", iPlayerId, "REG17" );
			menu_additem( iMenuId, sTxt, "5 4" );
		}
		case 5:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER6" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			//menu_additem( iMenuId, "Alap információk", "0 5" );
			//menu_additem( iMenuId, "VIP Vásárlás", "1 5" );
			//menu_additem( iMenuId, "ADMIN Vásárlás", "2 5" );
			menu_additem( iMenuId, "Jelenlévõ VIP tagok", "3 5" );
			menu_additem( iMenuId, "Jelenlévõ ADMINOK", "4 5" );
			menu_additem( iMenuId, "Felhasználó információk", "5 5" );
			menu_additem( iMenuId, "Rangom", "6 5" );
			menu_additem( iMenuId, "Rangok", "7 5" );
		}
		case 6:
		{
			if ( 0 < g_iURang[ iPlayerId ] < 4 )
			{
				formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %s", g_sPrefix, iPlayerId, "SNIPER7", iPlayerId, "SNIPER33", g_sUADate[ iPlayerId ] );
				iMenuId = menu_create( sTxt, "MainMenuH" );
				
				if ( 0 < g_iURang[ iPlayerId ] < 3 )
				{
					formatex( sTxt, 255, "%L", iPlayerId, "SNIPER34" );
					menu_additem( iMenuId, sTxt, "2 6" );
					formatex( sTxt, 255, "%L\r%s\w)", iPlayerId, "SNIPER35", g_sUPrefix[ iPlayerId ] );
					menu_additem( iMenuId, sTxt, "3 6" );
				}
				formatex( sTxt, 255, "%L: %L", iPlayerId, "SNIPER36", iPlayerId, g_bOptions[ iPlayerId ][ 4 ] ? "SNIPER30" : "SNIPER31" );
				menu_additem( iMenuId, sTxt, "4 6" );
			}
		}
		case 7:
		{
			if ( g_iURang[ iPlayerId ] == 4 )
			{
				formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %s", g_sPrefix, iPlayerId, "SNIPER8", iPlayerId, "SNIPER33", g_sUADate[ iPlayerId ] );
				iMenuId = menu_create( sTxt, "MainMenuH" );
				formatex( sTxt, 255, "%L: \r%s\w)", iPlayerId, "SNIPER35", g_sUPrefix[ iPlayerId ] );
				menu_additem( iMenuId, sTxt, "1 7" );
			}
		}
		case 8:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L\r ( %d / 3 )", g_sPrefix, iPlayerId, "SNIPER37", g_iUMarket[ iPlayerId ] );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			new iNum;
			if ( g_iSelected[ iPlayerId ][ 0 ] == -1 )
				formatex( sTxt, 255, "%L: \r%L", iPlayerId, "SNIPER38", iPlayerId, "SNIPER39" );
			else if ( ( iNum = is_chest( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
			{
				formatex( sTxt, 255, "%L: \r%d", iPlayerId, "SNIPER40", ArrayGetCell( g_daChestKey[ 4 ], iNum ) );
				menu_additem( iMenuId, sTxt, "0 8" );
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ) );
			}
			else if ( ( iNum = is_key( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
			{
				formatex( sTxt, 255, "%L: \r%d", iPlayerId, "SNIPER40", ArrayGetCell( g_daChestKey[ 5 ], iNum ) );
				menu_additem( iMenuId, sTxt, "0 8" );
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ) );
			}
			else
			{
				formatex( sTxt, 255, "%L: \r%d", iPlayerId, "SNIPER40", ArrayGetCell( g_daSkins[ 4 ], g_iSelected[ iPlayerId ][ 0 ] ) );
				menu_additem( iMenuId, sTxt, "0 8" );
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daSkins[ 0 ], g_iSelected[ iPlayerId ][ 0 ] ) );
			}
			menu_additem( iMenuId, sTxt, "1 8" );
			
			formatex( sTxt, 255, "%L: \r%d^n", iPlayerId, "SNIPER10", g_iSelected[ iPlayerId ][ 1 ] );
			menu_additem( iMenuId, sTxt, "2 8" );
			
			formatex( sTxt, 255, "\y%L", iPlayerId, "SNIPER37" );
			menu_additem( iMenuId, sTxt, "3 8" );
		}
		case 9:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER25" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			new iNum;
			if ( g_iSelected[ iPlayerId ][ 0 ] == -1 )
				formatex( sTxt, 255, "%L: \r%L", iPlayerId, "SNIPER38", iPlayerId, "SNIPER39" );
			else if ( g_iSelected[ iPlayerId ][ 0 ] == -4 )
				formatex( sTxt, 255, "%L: \r%L", iPlayerId, "SNIPER38", iPlayerId, "SNIPER10" );
			else if ( ( iNum = is_chest( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ) );
			else if ( ( iNum = is_key( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ) );
			else 
				formatex( sTxt, 255, "%L: \r%a", iPlayerId, "SNIPER38", ArrayGetStringHandle( g_daSkins[ 0 ], g_iSelected[ iPlayerId ][ 0 ] ) );
			menu_additem( iMenuId, sTxt, "1 9" );
			if ( g_iSelected[ iPlayerId ][ 2 ] == -1 )
				formatex( sTxt, 255, "%L: \r%L", iPlayerId, "SNIPER41", iPlayerId, "SNIPER39" );
			else
				formatex( sTxt, 255, "%L: \r%s", iPlayerId, "SNIPER41", g_sName[ g_iSelected[ iPlayerId ][ 2 ] ] );
			menu_additem( iMenuId, sTxt, "2 9" );
			
			formatex( sTxt, 255, "%L: \r%d^n", iPlayerId, "SNIPER42", g_iSelected[ iPlayerId ][ 1 ] );
			menu_additem( iMenuId, sTxt, "3 9" );
			
			formatex( sTxt, 255, "\y%L", iPlayerId, "SNIPER25" );
			menu_additem( iMenuId, sTxt, "4 9" );
		}
		case 10:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L", g_sPrefix, iPlayerId, "SNIPER43" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			new iCount;
			for ( new i = 1; i <= MaxClients; ++i )
			{
				if ( !is_user_connected( i ) ) continue;
				if ( !g_bIsUser[ i ] || i == iPlayerId ) continue;
				
				++iCount;
				
				formatex( sItemId, 7, "%d 10", i );
				
				formatex( sTxt, 255, "%s", g_sName[ i ] );
				menu_additem( iMenuId, sTxt, sItemId );
			}
			if ( iCount == 0 )
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER44" );
				MainMenu( iPlayerId, 0 );
				return;
			}
		}
		case 11:
		{
			new iWeaps, iNum = g_iSelected[ iPlayerId ][ 0 ];
			for ( new i; i < iNum; ++i )
				iWeaps += g_iSNum[ iPlayerId ][ i ];
				
			if ( g_iSelected[ iPlayerId ][ 1 ] == 0 ) g_iSelected[ iPlayerId ][ 1 ] = 1;
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n\r%L:\y %d/[1-5] \w| \r%L:\y %d/10", g_sPrefix, iPlayerId, "SNIPER4", iPlayerId, "SNIPER45", g_iSelected[ iPlayerId ][ 0 ], iPlayerId, "SNIPER46", iWeaps );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			formatex( sTxt, 255, "" );
			if ( iNum != 0 )
			{
				
				for ( new i; i < iNum; ++i )
					format( sTxt, 255, "%s\y%a\r(%d)%s", sTxt, ArrayGetStringHandle( g_daSkins[ 0 ], g_iSWeaps[ iPlayerId ][ i ] ), g_iSNum[ iPlayerId ][ i ], ( ( i % 2 == 0 ) && ( i != g_iSelected[ iPlayerId ][ 0 ] - 1 ) ) ? "\d|" : "^n" );
				format( sTxt, 255, "%s^n", sTxt );
				menu_additem( iMenuId, sTxt, "1 11" );
			}
	
			if ( iWeaps < 10 && iNum < 5 )
			{
				formatex( sTxt, 255, "%L", iPlayerId, "SNIPER47" );
				menu_additem(iMenuId, sTxt, "2 11");
			}
				
			if ( iNum != 0 )
			{
				formatex( sTxt, 255, "%L", iPlayerId, "SNIPER48" );
				menu_additem(iMenuId, sTxt, "3 11");
			}
				
			formatex( sTxt, 255, "%L^n", iPlayerId, "SNIPER49", g_iSelected[ iPlayerId ][ 1 ], ( g_iSelected[ iPlayerId ][ 1 ] + 1 ) );
			menu_additem(iMenuId, sTxt, "4 11");
			
			if ( iNum != 0 )
			{
				formatex( sTxt, 255, "\y%L", iPlayerId, "SNIPER50" );
				menu_additem(iMenuId, sTxt, "5 11");
			}
		}
		case 12:
		{
			formatex( sTxt, 255, "\r[\w%s\r]\w %L^n%L:\r %d^n\r* - %L", g_sPrefix, iPlayerId, "SNIPER51", iPlayerId, "SNIPER10", g_iMoney[ iPlayerId ], iPlayerId, "SNIPER52" );
			iMenuId = menu_create( sTxt, "MainMenuH" );
			
			if ( g_iMarket > 0 )
			{
				formatex( sTxt, 255, "\y%L^n", iPlayerId, "SNIPER53", g_iUMarket[ iPlayerId ] );
				menu_additem( iMenuId, sTxt, "-1 12" );
				new iNum, iNum2;
				for ( new i; i < g_iMarket; ++i )
				{
					formatex( sItemId, 7, "%d 12", i );
					
					iNum2 = ArrayGetCell( g_daMarket[ 1 ], i );
					if ( ( iNum = is_chest( iNum2 ) ) != -1 )
					{
						formatex( sTxt, 255, "%a [\r%d$\y]", ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ), ArrayGetCell( g_daMarket[ 2 ], i ) );
					}
					else if ( ( iNum = is_key( iNum2 ) ) != -1 )
					{
						formatex( sTxt, 255, "%a [\r%d$\y]", ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ), ArrayGetCell( g_daMarket[ 2 ], i ) );
					}
					else
						formatex( sTxt, 255, "%a [\r%d$\y]", ArrayGetStringHandle( g_daSkins[ 0 ], iNum2 ), ArrayGetCell( g_daMarket[ 2 ], i ) );
					if ( ArrayGetCell( g_daMarket[ 0 ], i ) == iPlayerId )
						add( sTxt, 255, " \r*");
					menu_additem( iMenuId, sTxt, sItemId );
				}
			}
			else
			{
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER54" );
				return;
			}
		}
	}
	
	menu_display( iPlayerId, iMenuId, 0 );
}

public MainMenuH( iPlayerId, iMenuId, iItem )
{
	if ( iItem != MENU_EXIT )
	{
		new sMenuName[ 78 ], sInfo[ 32 ], sDatas[ 2 ][ 16 ], iKey, iMenuNum;
		menu_item_getinfo( iMenuId, iItem, iKey, sInfo, charsmax( sInfo ), sMenuName, charsmax( sMenuName ), iMenuNum );
		parse( sInfo, sDatas[ 0 ], charsmax( sDatas[ ] ), sDatas[ 1 ], charsmax( sDatas[ ] ) );
		iKey = str_to_num( sDatas[ 0 ] );
		iMenuNum = str_to_num( sDatas[ 1 ] );
		
		switch( iMenuNum )
		{
			case -3:
			{
				g_iSelected[ iPlayerId ][ 2 ] = iKey;
				client_cmd( iPlayerId, "messagemode Mennyiseg" );
			}
			case -2:
			{
				g_iSelected[ iPlayerId ][ 0 ] = iKey;
				if ( g_iMenu[ iPlayerId ] != 8 ) g_iSelected[ iPlayerId ][ 1 ] = 1;
				
				MainMenu( iPlayerId, g_iMenu[ iPlayerId ] );
			}
			case -1: { dn_open_menu( iPlayerId, iKey ); }
			case 0:
			{
				if ( iKey == 11 )
				{
					g_iSelected[ iPlayerId ][ 0 ] = 0;
					g_iSelected[ iPlayerId ][ 1 ] = 1;
				}
				g_iSelected[ iPlayerId ][ 3 ] = PRIMARIWEAPON;
				
				g_iMenu[ iPlayerId ] = iKey;
				MainMenu( iPlayerId, iKey );
			}
			case 1:
			{
				if ( iKey == -1 )
				{
					g_iUsingKnife[ iPlayerId ] = g_iUsingSniper[ iPlayerId ] = -1;
					client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER62" );
					g_bOptions[ iPlayerId ][ 0 ] = true;
					return PLUGIN_HANDLED;
				}
				if ( iKey == -2 )
				{
					g_iSelected[ iPlayerId ][ 3 ] = g_iSelected[ iPlayerId ][ 3 ] == KNIFEID ? PRIMARIWEAPON : KNIFEID;
					g_iMenu[ iPlayerId ] = 1;
					MainMenu( iPlayerId, 1 );
					return PLUGIN_HANDLED;
				}
				if ( ArrayGetCell( g_daSkins[ 3 ], iKey ) == KNIFEID ) g_iUsingKnife[ iPlayerId ] = iKey;
				else g_iUsingSniper[ iPlayerId ] = iKey;
				
				g_bOptions[ iPlayerId ][ 0 ] = true;
				
				client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER63", ArrayGetStringHandle( g_daSkins[ 0 ], iKey ) );
			}
			case 2:
			{
				if ( g_iChests[ iPlayerId ][ iKey ] > 0 && g_iKeys[ iPlayerId ][ iKey ] > 0 )
				{
					if ( g_iChests[ iPlayerId ][ iKey ] == 1 )
					{
						for ( new i; i < g_iMarket; ++i )
						{
							if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
							{
								if ( ArrayGetCell( g_daMarket[ 1 ], i ) == ( -3 - ( iKey * 10 ) ) )
								{
									RemoveMarketItems( iPlayerId, i );
									break;
								}
							}
						}
					}
					if ( g_iKeys[ iPlayerId ][ iKey ] == 1 )
					{
						for ( new i; i < g_iMarket; ++i )
						{
							if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
							{
								if ( ArrayGetCell( g_daMarket[ 1 ], i ) == ( -2 - ( iKey * 10 ) ) )
								{
									RemoveMarketItems( iPlayerId, i );
									break;
								}
							}
						}
					}
					
					ChestOpen( iPlayerId , iKey );
				}
				MainMenu( iPlayerId, 2 );
			}
			case 3:
			{
				g_iSelected[ iPlayerId ][ 0 ] = -1;
				if ( iKey == 8 ) g_iSelected[ iPlayerId ][ 1 ] = 20;
				else g_iSelected[ iPlayerId ][ 1 ] = 1;
				g_iSelected[ iPlayerId ][ 2 ] = -1;
				
				g_iMenu[ iPlayerId ] = iKey;
				MainMenu( iPlayerId, iKey );
			}
			case 4:
			{
				switch( iKey )
				{	
					case -1, 0:
					{
						if ( iKey == -1 ) g_iUsingKnife[ iPlayerId ] = g_iUsingKnife[ iPlayerId ] == -2 ? -1 : -2;
						else g_iUsingSniper[ iPlayerId ] = g_iUsingSniper[ iPlayerId ] == -2 ? -1 : -2;
						if ( g_iUsingSniper[ iPlayerId ] == -2 && g_iUsingKnife[ iPlayerId ] == -2 ) g_bOptions[ iPlayerId ][ 0 ] = false;
						else g_bOptions[ iPlayerId ][ 0 ] = true;
						MainMenu( iPlayerId, 4 );
						return PLUGIN_HANDLED; 
					}
					case 1: { client_cmd( iPlayerId, "roundsounds" ); }
					case 2: { client_cmd( iPlayerId, "soundsoff" ); }
					case 3: { client_cmd( iPlayerId, "hudoff" ); }
					case 4:
					{
						SendCmd( iPlayerId, "setinfo _dnreg ^"%s//%s^"", g_sUName[ iPlayerId ], g_sUPass[ iPlayerId ] );
						client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER64", g_sUName[ iPlayerId ], g_sUPass[ iPlayerId ] );
						return PLUGIN_HANDLED;
					}
					case 5: { dn_open_menu( iPlayerId, 3 ); return PLUGIN_HANDLED; }
				}
				g_bOptions[ iPlayerId ][ iKey ] ^= true;
				MainMenu( iPlayerId, 4 );
			}
			case 5:
			{
				switch( iKey )
				{	
					case 0: { show_motd( iPlayerId,"addons/amxmodx/configs/motd/alap.txt", "Alap információk" ); }
					case 1: { show_motd( iPlayerId,"addons/amxmodx/configs/motd/vip.txt", "VIP Vásárlás" ); }
					case 2: { show_motd( iPlayerId, "addons/amxmodx/configs/motd/admin.txt", "ADMIN Vásárlás" ); }
					case 3, 4:
					{
						new sText[ 512 ], iLen = 0, iFinded = 0;
						iLen = formatex( sText, 511, "<meta charset=utf-8><body bgcolor=#000><font color=#FFB000><pre>" );
						iLen += formatex( sText[ iLen ], 511 - iLen, "Jelenlévõ %s: ", iKey == 3 ? "VIP tagok" : "adminok" );
						
						if ( iKey == 4 )
						{
							for ( new i = 1; i <= MaxClients; ++i )
							{
								if ( !g_bIsUser[ i ] ) continue;
								if ( !g_bOptions[ i ][ 4 ] ) continue;
								if ( 0 < g_iURang[ i ] < 4 )
								{
									iLen += formatex( sText[ iLen ], 511 - iLen, "%s, ", g_sName[ i ] );
									++iFinded;
									if ( iFinded % 5 == 0 ) iLen += formatex( sText[ iLen ], 511 - iLen, "^n" );
								}
							}
						}
						else	
						{
							for ( new i = 1; i <= MaxClients; ++i )
							{
								if ( !g_bIsUser[ i ] ) continue;
								if ( 3 < g_iURang[ i ] < 6 )
								{
									iLen += formatex( sText[ iLen ], 511 - iLen, "%s, ", g_sName[ i ] );
									++iFinded;
									if ( iFinded % 5 == 0 ) iLen += formatex( sText[ iLen ], 511 - iLen, "^n" );
								}
							}
						}
						if ( iFinded ) sText[ strlen( sText ) - 2 ] = EOS;
						else iLen += formatex( sText[ iLen ], 511 - iLen, "Nincs jelen %s", iKey == 3 ? "VIP tag" : "admin" );
						
						show_motd( iPlayerId, sText, "Információk" );
					}
					case 5:
					{
						new iLen = 0, sMotd[ 2048 ];
						
						iLen = formatex( sMotd, 2047, "<meta charset=utf-8><body bgcolor=#000><font color=#FFB000><pre>" );
						iLen += formatex( sMotd[ iLen ], 2047 - iLen, "Id: #%d^n", g_iUId[ iPlayerId ] );
						iLen += formatex( sMotd[ iLen ], 2047 - iLen, "%L: %s^n", iPlayerId, "REG1", g_sUName[ iPlayerId ] );
						iLen += formatex( sMotd[ iLen ], 2047 - iLen, "%L: %s^n", iPlayerId, "SNIPER65", g_sUDate[ iPlayerId ] );
						if ( g_iURang[ iPlayerId ] > -1 )
						{
							iLen += formatex( sMotd[ iLen ], 2047 - iLen, "%L: %s^n", iPlayerId, "SNIPER66", g_sDefPrefix[ g_iURang[ iPlayerId ] ] );
							iLen += formatex( sMotd[ iLen ], 2047 - iLen, "%L: %s^n", iPlayerId, "SNIPER33", g_sUADate[ iPlayerId ] );
						}
						
						show_motd( iPlayerId, sMotd, "Felhasználó Információk" );
					}
					case 6: { client_cmd( iPlayerId, "rangmotd" ); }
					case 7: { client_cmd( iPlayerId, "rangsmotd" ); }
				}
			}
			case 6:
			{
				switch( iKey )
				{	
					case 1: { dn_open_menu( iPlayerId, 5 ); }
					case 2:
					{
						dn_open_menu( iPlayerId, 4 );
						client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 Az adminok újra be lettek töltve az adatbázisból.", g_sPrefix );
					}
					case 3:
					{
						client_cmd( iPlayerId, "messagemode ADMIN_PREFIX" );
						client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER67" );
					}
					case 4: { g_bOptions[ iPlayerId ][ 4 ] ^= true; }
				}
				MainMenu( iPlayerId, 6 );
			}
			case 7:
			{
				switch( iKey )
				{	
					case 1:
					{
						client_cmd( iPlayerId, "messagemode ADMIN_PREFIX" );
						client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER67" );
					}
				}
			}
			case 8:
			{
				switch( iKey )
				{	
					case 0: { MainMenu( iPlayerId, 8 ); }
					case 1: { MainMenu( iPlayerId, -2 ); }
					case 2: { client_cmd( iPlayerId, "messagemode Dollar" ); }
					case 3:
					{
						if ( g_iUMarket[ iPlayerId ] >= 3 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER68" );
							return PLUGIN_HANDLED;
						}
						
						if ( g_iSelected[ iPlayerId ][ 0 ] == -1 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER69" );
							MainMenu( iPlayerId, 8 );
							return PLUGIN_HANDLED;
						}
						
						for ( new i; i < g_iMarket; ++i )
						{
							if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
							{
								if ( ArrayGetCell( g_daMarket[ 1 ], i ) == g_iSelected[ iPlayerId ][ 0 ] )
								{
									client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER70" );
									MainMenu( iPlayerId, 8 );
									return PLUGIN_HANDLED;
								}
							}
						}
						ArrayPushCell( g_daMarket[ 0 ], iPlayerId );
						ArrayPushCell( g_daMarket[ 1 ], g_iSelected[ iPlayerId ][ 0 ] );
						ArrayPushCell( g_daMarket[ 2 ], g_iSelected[ iPlayerId ][ 1 ] );
						
						++g_iMarket;
						++g_iUMarket[ iPlayerId ];
						new iNum;
						
						if ( ( iNum = is_chest( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, iPlayerId, "SNIPER71", g_sName[ iPlayerId ], ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ), g_iSelected[ iPlayerId ][ 1 ] );
						else if ( ( iNum = is_key( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, iPlayerId, "SNIPER71", g_sName[ iPlayerId ], ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ), g_iSelected[ iPlayerId ][ 1 ] );
						else
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, iPlayerId, "SNIPER71", g_sName[ iPlayerId ], ArrayGetStringHandle( g_daSkins[ 0 ], g_iSelected[ iPlayerId ][ 0 ] ), g_iSelected[ iPlayerId ][ 1 ] );
						
					}
				}
			}
			case 9:
			{
				switch( iKey )
				{	
					case 1: { MainMenu( iPlayerId, -2 ); }
					case 2: { MainMenu( iPlayerId, 10 ); }
					case 3:
					{
						if ( g_iSelected[ iPlayerId ][ 0 ] == -1 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER69" );
							MainMenu( iPlayerId, 9 );
							return PLUGIN_HANDLED;
						}
						MainMenu( iPlayerId, 9 );
						client_cmd( iPlayerId, "messagemode Mennyiseg" );
					}
					case 4:
					{
						new iNum;
						
						if ( g_iSelected[ iPlayerId ][ 0 ] == -1 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER69" );
							MainMenu( iPlayerId, 9 );
							return PLUGIN_HANDLED;
						}
						
						if ( g_iSelected[ iPlayerId ][ 2 ] == -1 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER72" );
							MainMenu( iPlayerId, 9 );
							return PLUGIN_HANDLED;
						}
						
						if ( !is_user_connected( g_iSelected[ iPlayerId ][ 2 ] ) ) return PLUGIN_HANDLED;
						
						if ( g_iSelected[ iPlayerId ][ 0 ] == -4 )
						{
							g_iMoney[ iPlayerId ] -= g_iSelected[ iPlayerId ][ 1 ];
							g_iMoney[ g_iSelected[ iPlayerId ][ 2 ] ] += g_iSelected[ iPlayerId ][ 1 ];
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER73", g_iSelected[ iPlayerId ][ 1 ], g_sName[ g_iSelected[ iPlayerId ][ 2 ] ] );
							client_print_color( g_iSelected[ iPlayerId ][ 2 ], g_iSelected[ iPlayerId ][ 2 ], "^4[%s] %L", g_sPrefix, g_iSelected[ iPlayerId ][ 2 ], "SNIPER74", g_sName[ iPlayerId ], g_iSelected[ iPlayerId ][ 1 ] );
							return PLUGIN_HANDLED;
						}
						else if ( ( iNum = is_chest( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
						{
							if ( g_iChests[ iPlayerId ][ iNum ] <= g_iSelected[ iPlayerId ][ 1 ] )
							{
								for ( new i; i < g_iMarket; ++i )
								{
									if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
									{
										if ( ArrayGetCell( g_daMarket[ 1 ], i ) == g_iSelected[ iPlayerId ][ 0 ] )
										{
											RemoveMarketItems( iPlayerId, i );
											break;
										}
									}
								}
							}
							g_iChests[ iPlayerId ][ iNum ] -= g_iSelected[ iPlayerId ][ 1 ];
							g_iChests[ g_iSelected[ iPlayerId ][ 2 ] ][ iNum ] += g_iSelected[ iPlayerId ][ 1 ];
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER75", g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ), g_sName[ g_iSelected[ iPlayerId ][ 2 ] ] );
							client_print_color( g_iSelected[ iPlayerId ][ 2 ], g_iSelected[ iPlayerId ][ 2 ], "^4[%s] %L", g_sPrefix, g_iSelected[ iPlayerId ][ 2 ], "SNIPER76", g_sName[ iPlayerId ], g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ) );
						}
						else if ( ( iNum = is_key( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
						{
							if ( g_iKeys[ iPlayerId ][ iNum ] <= g_iSelected[ iPlayerId ][ 1 ] )
							{
								for ( new i; i < g_iMarket; ++i )
								{
									if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
									{
										if ( ArrayGetCell( g_daMarket[ 1 ], i ) == g_iSelected[ iPlayerId ][ 0 ] )
										{
											RemoveMarketItems( iPlayerId, i );
											break;
										}
									}
								}
							}
							g_iKeys[ iPlayerId ][ iNum ] -= g_iSelected[ iPlayerId ][ 1 ];
							g_iKeys[ g_iSelected[ iPlayerId ][ 2 ] ][ iNum ] += g_iSelected[ iPlayerId ][ 1 ];
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER75", g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ), g_sName[ g_iSelected[ iPlayerId ][ 2 ] ] );
							client_print_color( g_iSelected[ iPlayerId ][ 2 ], g_iSelected[ iPlayerId ][ 2 ], "^4[%s] %L", g_sPrefix, g_iSelected[ iPlayerId ][ 2 ], "SNIPER76", g_sName[ iPlayerId ], g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ) );
						}
						else
						{
							if ( g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 0 ] ] <= g_iSelected[ iPlayerId ][ 1 ] )
							{
								for ( new i; i < g_iMarket; ++i )
								{
									if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
									{
										if ( ArrayGetCell( g_daMarket[ 1 ], i ) == g_iSelected[ iPlayerId ][ 0 ] )
										{
											RemoveMarketItems( iPlayerId, i );
											break;
										}
									}
								}
								if ( g_iUsingKnife[ iPlayerId ] == g_iSelected[ iPlayerId ][ 0 ] ) g_iUsingKnife[ iPlayerId ] = -1;
								else if ( g_iUsingSniper[ iPlayerId ] == g_iSelected[ iPlayerId ][ 0 ] ) g_iUsingSniper[ iPlayerId ] = -1;
							}
							g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 0 ] ]  -= g_iSelected[ iPlayerId ][ 1 ];
							g_iUSkins[ g_iSelected[ iPlayerId ][ 2 ] ][ g_iSelected[ iPlayerId ][ 0 ] ]  += g_iSelected[ iPlayerId ][ 1 ];
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER75", g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daSkins[ 0 ], g_iSelected[ iPlayerId ][ 0 ] ), g_sName[ g_iSelected[ iPlayerId ][ 2 ] ] );
							client_print_color( g_iSelected[ iPlayerId ][ 2 ], g_iSelected[ iPlayerId ][ 2 ], "^4[%s] %L", g_sPrefix, g_iSelected[ iPlayerId ][ 2 ], "SNIPER76", g_sName[ iPlayerId ], g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daSkins[ 0 ], g_iSelected[ iPlayerId ][ 0 ] ) );
						}
					}
				}
			}
			case 10:
			{
				g_iSelected[ iPlayerId ][ 2 ] = iKey;
				MainMenu( iPlayerId, 9 );
			}
			case 11:
			{
				switch ( iKey )
				{
					case 1: MainMenu( iPlayerId, 11 );
					case 2: MainMenu( iPlayerId, -3 );
					case 3:
					{
						g_iSelected[ iPlayerId ][ 0 ] = 0;
						MainMenu( iPlayerId, 11 );
					}
					case 4:
					{
						if ( ++g_iSelected[ iPlayerId ][ 1 ] >= CHESTNUM ) g_iSelected[ iPlayerId ][ 1 ] = 1;
						g_iSelected[ iPlayerId ][ 0 ] = 0;
						MainMenu( iPlayerId, 11 );
					}
					case 5:
					{
						new iWeaps, iNum = g_iSelected[ iPlayerId ][ 0 ];
						for ( new i; i < iNum; ++i )
							iWeaps += g_iSNum[ iPlayerId ][ i ];
							
						if ( iWeaps > 10 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER77" );
							MainMenu( iPlayerId, 11 );
						}
						else if ( iWeaps < 10 )
						{
							client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER78" );
							MainMenu( iPlayerId, 11 );
						}
						else
						{
							TradeUp( iPlayerId );
							MainMenu( iPlayerId, 0 );
						}
					}
				}
			}
			case 12:
			{
				if ( iKey == -1 )
				{
					RemoveMarketItems( iPlayerId, -1 );
					client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER79" );
					return PLUGIN_HANDLED;
				}
				if ( g_iMarket > iKey )
				{
					if ( ArrayGetCell( g_daMarket[ 0 ], iKey ) == iPlayerId )
					{
						client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER80" );
						RemoveMarketItems( iPlayerId, iKey );
					}
					else if ( g_iMoney[ iPlayerId ] >= ArrayGetCell( g_daMarket[ 2 ], iKey ) )
					{
						g_iMoney[ iPlayerId ] -= ArrayGetCell( g_daMarket[ 2 ], iKey );
						g_iMoney[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ] += ArrayGetCell( g_daMarket[ 2 ], iKey );
						
						new iNum;
						
						if ( ( iNum = is_chest( ArrayGetCell( g_daMarket[ 1 ], iKey ) ) ) != -1 )
						{
							g_iChests[ iPlayerId ][ iNum ] += 1;
							g_iChests[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ][ iNum ] -= 1;
							
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, LANG_PLAYER, "SNIPER81", g_sName[  iPlayerId ], ArrayGetStringHandle( g_daChestKey[ 0 ], iNum ) );
						}
						else if ( ( iNum = is_key( ArrayGetCell( g_daMarket[ 1 ], iKey ) ) ) != -1 )
						{
							g_iKeys[ iPlayerId ][ iNum ] += 1;
							g_iKeys[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ][ iNum ] -= 1;
							
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, LANG_PLAYER, "SNIPER81", g_sName[  iPlayerId ], ArrayGetStringHandle( g_daChestKey[ 2 ], iNum ) );
						}
						else
						{
							if ( g_iUSkins[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ][ ArrayGetCell( g_daMarket[ 1 ], iKey ) ] == 1 )
							{
								if ( g_iUsingKnife[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ] == ArrayGetCell( g_daMarket[ 1 ], iKey ) ) g_iUsingKnife[ iPlayerId ] = -1;
								else if ( g_iUsingSniper[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ] == ArrayGetCell( g_daMarket[ 1 ], iKey ) ) g_iUsingSniper[ iPlayerId ] = -1;
							}
							++g_iUSkins[ iPlayerId ][ ArrayGetCell( g_daMarket[ 1 ], iKey ) ];
							--g_iUSkins[ ArrayGetCell( g_daMarket[ 0 ], iKey ) ][ ArrayGetCell( g_daMarket[ 1 ], iKey ) ];
							
							client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, LANG_PLAYER, "SNIPER81", g_sName[  iPlayerId ], ArrayGetStringHandle( g_daSkins[ 0 ], ArrayGetCell( g_daMarket[ 1 ], iKey ) ) );
						}
						RemoveMarketItems( ArrayGetCell( g_daMarket[ 0 ], iKey ), iKey );
					}
					else client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER82" );
				}
			}
		}
	}
	menu_destroy( iMenuId );
	return PLUGIN_HANDLED;
}

public TradeUp( iPlayerId )
{
	new iRandWeap, iWeap, iWeapNum, iWeaps[ 40 ];
	
	iWeapNum = 0;
	
	for ( new i; i < g_iSkins; ++i )
		if ( ArrayGetCell( g_daSkins[ 5 ], i ) == g_iSelected[ iPlayerId ][ 1 ] )
			iWeaps[ iWeapNum++ ] = i;
	
	if ( iWeapNum == 0 ) return;
	
	iRandWeap = random_num( 0, ( iWeapNum - 1 ) );
	iWeapNum = iWeaps[ iRandWeap ];
	
	for( new i; i < g_iSelected[ iPlayerId ][ 0 ]; ++i )
	{
		iWeap = g_iSWeaps[ iPlayerId ][ i ];
		if ( g_iUSkins[ iPlayerId ][ iWeap ] == g_iSNum[ iPlayerId ][ i ] )
		{
			for ( new j; j < g_iMarket; ++j )
			{
				if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], j ) )
				{
					if ( ArrayGetCell( g_daMarket[ 1 ], j ) == iWeap )
					{
						RemoveMarketItems( iPlayerId, j );
						break;
					}
				}
			}
			if ( g_iUsingKnife[ iPlayerId ] == iWeap ) g_iUsingKnife[ iPlayerId ] = -1;
			else if ( g_iUsingSniper[ iPlayerId ] == iWeap ) g_iUsingSniper[ iPlayerId ] = -1;
		}
		g_iUSkins[ iPlayerId ][ iWeap ] -= g_iSNum[ iPlayerId ][ i ];
	}
	
	++g_iUSkins[ iPlayerId ][ iWeapNum ];
	
	client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, LANG_PLAYER, "SNIPER83", g_sName[  iPlayerId ], g_iSelected[ iPlayerId ][ 1 ], ArrayGetStringHandle( g_daSkins[ 0 ], iWeapNum ), g_iSelected[ iPlayerId ][ 1 ] + 1 );
	g_iMenu[ iPlayerId ] = g_iSelected[ iPlayerId ][ 0 ] = 0;
}

public ChestOpen( iPlayerId , iChest )
{
	new Float: fRand, iRandWeap, iWeapNum, iWeaps[ 40 ];
	
	iWeapNum = 0;
	
	for ( new i; i < g_iSkins; ++i )
		if ( ArrayGetCell( g_daSkins[ 5 ], i ) == iChest )
			iWeaps[ iWeapNum++ ] = i;
	
	if ( iWeapNum == 0 ) return;
	
	g_iChests[ iPlayerId ][ iChest ] -= 1;
	g_iKeys[ iPlayerId ][ iChest ] -= 1;
	if ( iWeapNum != 1 )
	{
		do
		{
			iRandWeap = random_num( 0, ( iWeapNum - 1 ) );
			fRand = ( 0 < g_iURang[ iPlayerId ] < 6 ) ? random_float( 0.0, 85.0 ) : random_float( 0.0, 100.0 );
		}
		while ( Float:ArrayGetCell( g_daSkins[ 2 ], iWeaps[ iRandWeap ] ) < Float:fRand );
	}
	else iRandWeap = 0;
		
	iWeapNum = iWeaps[ iRandWeap ];
		
	client_print_color( 0, print_team_default, "^4[%s] %L", g_sPrefix, LANG_PLAYER, "SNIPER84", g_sName[  iPlayerId ], ArrayGetStringHandle( g_daSkins[ 0 ], iWeapNum ), Float:ArrayGetCell( g_daSkins[ 2 ], iWeapNum ) );
	++g_iUSkins[ iPlayerId ][ iWeapNum ];
	
}

public RemoveMarketItems( iPlayerId, iItem )
{
	if ( iItem == -1 )
	{
		for ( new i; i < g_iMarket; ++i )
		{
			if ( iPlayerId == ArrayGetCell( g_daMarket[ 0 ], i ) )
			{
				ArrayDeleteItem( g_daMarket[ 0 ], i );
				ArrayDeleteItem( g_daMarket[ 1 ], i );
				ArrayDeleteItem( g_daMarket[ 2 ], i );
				--g_iUMarket[ iPlayerId ];
				--g_iMarket;
				RemoveMarketItems( iPlayerId, iItem );
				return;
			}
		}
	}
	else
	{
		ArrayDeleteItem( g_daMarket[ 0 ], iItem );
		ArrayDeleteItem( g_daMarket[ 1 ], iItem );
		ArrayDeleteItem( g_daMarket[ 2 ], iItem );
		--g_iUMarket[ iPlayerId ];
		--g_iMarket;
	}
}

public GetPiece( iPlayerId )
{
	if ( !g_bIsUser[ iPlayerId ] ) return;
	new sData[ 16 ], iData, iNum;
	read_args( sData, 15 );
	remove_quotes( sData );
	iData = str_to_num( sData );
	
	if ( g_iMenu[ iPlayerId ] == 11 )
	{
		if ( g_iSelected[ iPlayerId ][ 2 ] == -1 ) return;
		
		if ( iData <= 0 || iData > 10 )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER85", 1, 10 );
			return;
		}
		if ( g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 2 ] ] < iData )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER86", g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 2 ] ] );
			return;
		}
		
		iNum = g_iSelected[ iPlayerId ][ 0 ];
		g_iSWeaps[ iPlayerId ][ iNum ] = g_iSelected[ iPlayerId ][ 2 ];
		g_iSNum[ iPlayerId ][ iNum ] = iData;
		++g_iSelected[ iPlayerId ][ 0 ];
		
		g_iSelected[ iPlayerId ][ 2 ] = -1;
		
		MainMenu( iPlayerId, 11 );
		return;
	}
	
	if ( g_iSelected[ iPlayerId ][ 0 ] == -1 ) return;
	
	if ( g_iSelected[ iPlayerId ][ 0 ] == -4 )
	{
		if ( iData <= 0 || iData > 1000000 )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER85", 1, 1000000 );
			return;
		}
		if ( g_iMoney[ iPlayerId ] < iData )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER87", g_iMoney[ iPlayerId ] );
			return;
		}
		
		g_iSelected[ iPlayerId ][ 1 ] = iData;
		MainMenu( iPlayerId, 9 );
		return;
	}
	
	if ( iData <= 0 || iData > 100 )
	{
		client_cmd( iPlayerId, "messagemode Mennyiseg" );
		client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER85", 1, 100 );
		return;
	}
	else if ( ( iNum = is_chest( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
	{
		if ( g_iChests[ iPlayerId ][ iNum ] < iData )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER86", g_iChests[ iPlayerId ][ iNum ] );
			return;
		}
	}
	else if ( ( iNum = is_key( g_iSelected[ iPlayerId ][ 0 ] ) ) != -1 )
	{
		if ( g_iKeys[ iPlayerId ][ iNum ] < iData )
		{
			client_cmd( iPlayerId, "messagemode Mennyiseg" );
			client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER86", g_iKeys[ iPlayerId ][ iNum ] );
			return;
		}
	}
	else if ( g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 0 ] ] < iData )
	{
		client_cmd( iPlayerId, "messagemode Mennyiseg" );
		client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER86", g_iUSkins[ iPlayerId ][ g_iSelected[ iPlayerId ][ 0 ] ] );
		return;
	}
	
	g_iSelected[ iPlayerId ][ 1 ] = iData;
	MainMenu( iPlayerId, 9 );
}

public GetCost( iPlayerId )
{
	if ( !g_bIsUser[ iPlayerId ] ) return;
	new sData[ 16 ], iData;
	read_args( sData, 15 );
	remove_quotes( sData );
	iData = str_to_num( sData );
 
	if ( iData <= 19 || iData > 1000000 )
	{
		client_cmd( iPlayerId, "messagemode Dollar" );
		client_print_color( iPlayerId, iPlayerId, "^4[%s]^1 %L", g_sPrefix, iPlayerId, "SNIPER85", 20, 1000000 );
	}
	else
	{
		g_iSelected[ iPlayerId ][ 1 ] = iData;
		MainMenu( iPlayerId, 8 );
	}
}

public SaveDatas( iPlayerId, iMode )
{
	new sText[ 1200 ];
	if ( iMode == 0 )
	{
		sText[ 0 ] = EOS;
		new sTxt[ 16 ], sSnip[ 512 ], sKnife[ 512 ], sChests[ 32 ], sKeys[ 32 ];
		for ( new i = 0; i < g_iSkins; ++i )
		{
			num_to_str( g_iUSkins[ iPlayerId ][ i ], sTxt, 15 );
			switch( ArrayGetCell( g_daSkins[ 3 ], i ) )
			{
				case PRIMARIWEAPON: 
				{
					add( sSnip, 511, sTxt );
					add( sSnip, 511, " " );
				}
				case KNIFEID:
				{
					add( sKnife, 511, sTxt );
					add( sKnife, 511, " " );
				}
			}
		}
		if ( strlen( sSnip ) )
			sSnip[ strlen( sSnip ) - 1 ] = EOS;
		if ( strlen( sKnife ) )
			sKnife[ strlen( sKnife ) - 1 ] = EOS;
		for ( new i = 0; i < CHESTNUM; ++i )
		{
			num_to_str( g_iChests[ iPlayerId ][ i ], sTxt, charsmax( sTxt ) );
			add( sChests, 31, sTxt );
			num_to_str( g_iKeys[ iPlayerId ][ i ], sTxt, charsmax( sTxt ) );
			add( sKeys, 31, sTxt );
			if ( i != CHESTNUM - 1 )
			{
				add( sChests, 31, " " );
				add( sKeys, 31, " " );
			}
		}
		
		if ( g_iUsingKnife[ iPlayerId ] > -1 ) g_iUsingKnife[ iPlayerId ] -= g_iSnipSkins;
		
		formatex( sText, charsmax( sText ), "UPDATE `skin_system_new` SET `chests` = ^"%s^", `keys` = ^"%s^", `money` = %d, `scout_skins` = ^"%s^", `knife_skins` = ^"%s^", `sel_scout` = %d, `sel_knife` = %d WHERE `userid` = %d;", sChests, sKeys, g_iMoney[ iPlayerId ], sSnip, sKnife, g_iUsingSniper[ iPlayerId ], g_iUsingKnife[ iPlayerId ], g_iUId[ iPlayerId ] );
		
		if ( g_iUsingKnife[ iPlayerId ] > -1 ) g_iUsingKnife[ iPlayerId ] += g_iSnipSkins;
	}
	else formatex( sText, charsmax( sText ), "INSERT INTO `skin_system_new` (`userid`) VALUES (%d);", g_iUId[ iPlayerId ] );
	
	SQL_ThreadQuery( g_iSqlTuple, "ThreadHandler", sText, { 0 }, 1 );
}

public LoadDatas( iPlayerId, iMode )
{
	new sText[ 128 ], iArray[ 1 ];
	
	iArray[ 0 ] = iPlayerId;
	
	if ( iMode == 1 ) formatex( sText, charsmax( sText ), "SELECT * FROM `skin_system_new` WHERE `userid` = %d;", g_iUId[ iPlayerId ] );
	SQL_ThreadQuery( g_iSqlTuple, "ThreadHandler", sText, iArray, sizeof( iArray ) );
}
 
public ThreadHandler( iFailState, Handle:iQuery, const sErrorMsg[ ], iErrorCode, const iARRAY[ ], iArraySize, Float:fQueueTime )
{
	if ( iFailState == TQUERY_CONNECT_FAILED )
	{
		log_amx( "%i - %s", iErrorCode, sErrorMsg );
		set_fail_state( "Nem tudtam csatlakozni az adatbazishoz." );
		return;
	}
	else if ( iFailState == TQUERY_QUERY_FAILED )
	{
		log_amx( "%i - %s", iErrorCode, sErrorMsg );
		return;
	}
	
	new iPlayerId = iARRAY[ 0 ];
	if ( iPlayerId )
	{
		if ( iPlayerId < 100 )
		{
			if ( SQL_NumResults( iQuery ) > 0 )
			{
				g_iMoney[ iPlayerId ] = SQL_ReadResult( iQuery, 4 );
				g_iUsingSniper[ iPlayerId ] = SQL_ReadResult( iQuery, 9 );
				g_iUsingKnife[ iPlayerId ] = SQL_ReadResult( iQuery, 10 );
				
				if ( g_iUsingSniper[ iPlayerId ] == -2 && g_iUsingKnife[ iPlayerId ] == -2 )
					g_bOptions[ iPlayerId ][ 0 ] = false;
					
				if ( g_iUsingKnife[ iPlayerId ] > -1 ) g_iUsingKnife[ iPlayerId ] += g_iSnipSkins;
				
				new sText[ 1024 ], sTxt[ 16 ];
				
				SQL_ReadResult( iQuery, 2, sText, 31 );
				if ( strlen( sText ) > 3 )
				{
					for ( new i = 0; i < CHESTNUM; ++i )
					{
						argbreak( sText, sTxt, 15, sText, 31 );
						g_iChests[ iPlayerId ][ i ] = str_to_num( sTxt );
					}
				}
				SQL_ReadResult( iQuery, 3, sText, 31 );
				if ( strlen( sText ) > 3 )
				{
					for ( new i = 0; i < CHESTNUM; ++i )
					{
						argbreak( sText, sTxt, 15, sText, 31 );
						g_iKeys[ iPlayerId ][ i ] = str_to_num( sTxt );
					}
				}
				
				new i;
				
				SQL_ReadResult( iQuery, 6, sText, 511 );
				
				if ( sText[ 0 ] )
				{
					for ( new j; j < g_iSnipSkins; ++j )
					{
						if ( argbreak( sText, sTxt, 15, sText, 511 ) )
							g_iUSkins[ iPlayerId ][ i ] = str_to_num( sTxt );
						++i;
					}
				}
				else i = g_iSnipSkins;
				SQL_ReadResult( iQuery, 7, sText, 511 );
				
				if ( sText[ 0 ] )
				{
					for ( new j; j < g_iKnifeSkins; ++j )
					{
						if ( argbreak( sText, sTxt, 15, sText, 511 ) )
							g_iUSkins[ iPlayerId ][ i ] = str_to_num( sTxt );
						++i;
					}
				}
			}
			else SaveDatas( iPlayerId, 1 );
			MainMenu( iPlayerId, 0 );
		}
	}
	
	return;
}

public plugin_end( )
{
	SQL_FreeHandle( g_iSqlTuple );
	for ( new i; i < sizeof( g_daSkins ); ++i )
		ArrayDestroy( g_daSkins[ i ] );
	for ( new i; i < sizeof( g_daMarket ); ++i )
		ArrayDestroy( g_daMarket[ i ] );
	for ( new i; i < sizeof( g_daChestKey ); ++i )
		ArrayDestroy( g_daChestKey[ i ] );
}

stock is_chest( iNum )
{
	switch ( iNum )
	{
		case -3: return 0;
		case -13: return 1;
		case -23: return 2;
		case - 33: return 3;
	}
	return -1;
}

stock is_key( iNum )
{
	switch ( iNum )
	{
		case -2: return 0;
		case -12: return 1;
		case -22: return 2;
		case - 32: return 3;
	}
	return -1;
}

stock SendCmd( iPlayerId, const sText[ ], any:... )
{
	static sCmd[ 128 ]; vformat( sCmd, 127, sText, 3 );
	message_begin( MSG_ONE, SVC_DIRECTOR, _, iPlayerId );
	write_byte( strlen( sCmd ) + 2 );
	write_byte( 10 );
	write_string( sCmd );
	message_end( );
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/
