/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <ColorChat>
#include <cstrike>
#include <codmod>
#include <hamsandwich>
#include <Fakemeta>
#include <engine>
#include <fun>


#define DMG_HEGRENADE (1<<24)
#define DMG_BULLET (1<<1)

#define PLUGIN "COD Elite | Sklep"
#define VERSION "1.0"
#define AUTHOR "Play"

#define set_waluta  cod_set_user_Ordery
#define get_waluta  cod_get_user_Ordery(id)

new tytul[512], name[33];
new const prefix[ ] = "[COD Elite | Sklep]^01";

native cod_set_user_Ordery(id, wartosc);
native cod_get_user_Ordery(id);

native cod_set_user_hud(id)
native cod_get_user_hud(id)

new const max_clip[31] = { -1, 13, -1, 10,  1,  7,  1,  30, 30,  1,  30,  20,  25, 30, 35, 25,  12,  20, 
10,  30, 100,  8, 30,  30, 20,  2,  7, 30, 30, -1,  50 };

new sprite_blast, ilosc_rakiet[33], poprzednia_rakieta[33], bool:ma_rakiete[33], bool:rakieta_gracza[33];

new CsArmorType:armortype

new g_msg_screenfade;
new g_msgHostageAdd, g_msgHostageDel;
new const sound_radar[] = "radar.wav"

new bool: a_dmg[33], odpornosc_he[33], odpornosc_fb[33], DodatkowySkok[33], skoki[33], NoRecoil[33], Niewidzialnosc[33], Regeneracja[33], NoAmmo[33], Radar[33]

/*================================
	   [WYPOSAŻENIE]
=================================*/
new cvar_dmg, 
	cvar_ciche_kroki, 
	cvar_odpornosc_he, 
	cvar_odpornosc_fb, 
	cvar_skoki, 
	cvar_pancerz, 
	cvar_ile_pancerz, 
	cvar_ile_skokow
	
/*================================
	    [APTEKA]
=================================*/
new cvar_mhp, 
	cvar_ile_mhp, 
	cvar_shp, 
	cvar_ile_shp, 
	cvar_dhp, 
	cvar_ile_dhp, 
	cvar_rhp, 
	cvar_lhp, 
	cvar_min_lhp, 
	cvar_max_lhp
	
/*================================
	  [Doswiadczenie]
=================================*/	
new cvar_ile_mze,
	cvar_mze,
	cvar_ile_sze,
	cvar_sze,
	cvar_ile_dze,
	cvar_dze,
	cvar_min_lexp,
	cvar_max_lexp,
	cvar_lexp
	

/*================================
	  [Czarny Rynek]
=================================*/
	
new cvar_ile_rakiet, 
	cvar_rakiety, 
	cvar_zestaw, 
	cvar_perk, 
	cvar_recoil, 
	cvar_plaszcz,
	cvar_ile_plaszcz,
	cvar_noammo, 
	cvar_radar

new const g_Lang[][]={"say /sklep","say_team /sklep","say /shop","say_team /shop"};

	
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	for(new i;i<sizeof g_Lang;i++)
		register_clcmd(g_Lang[i], "cmd_menu");
		
		
	g_msgHostageAdd = get_user_msgid("HostagePos");
	g_msgHostageDel = get_user_msgid("HostageK");	
	
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
	register_forward(FM_CmdStart, "fwCmdStart_MultiJump");
	register_message(get_user_msgid("ScreenFade"), "messageScreenFade");
	g_msg_screenfade = get_user_msgid("ScreenFade");
	register_touch("rocket2", "*" , "DotykRakiety");
	register_forward(FM_PlayerPreThink, "PreThink");
	register_forward(FM_UpdateClientData, "UpdateClientData", 1)	
	register_forward(FM_CmdStart, "CmdStart");
	
	register_logevent("Koniec_Rundy", 2, "1=Round_End")
	
	
	/*================================
		   [WYPOSAŻENIE]
	=================================*/
	
	cvar_dmg 		= register_cvar("cena_dmg", 			"15");		// Cena dodatkowego dmg
	cvar_ciche_kroki	= register_cvar("cena_ciche_buty", 		"10");		// Cena za cichebuty
	cvar_odpornosc_he	= register_cvar("cena_odpornosc_he", 		"13");		// Cena za odpornosc na granaty wybuchowe
	cvar_odpornosc_fb	= register_cvar("cena_odpornosc_fb", 		"11");		// Cena za odporność na fleshe
	cvar_skoki		= register_cvar("cena_dodatkowe_skoki", 	"16");		// Cena za dodatkowe skoki
	cvar_pancerz		= register_cvar("cena_dodatkowy_pancerz", 	"11");		// Cena za dodatkowy pancerz
	cvar_ile_skokow		= register_cvar("ile_skokow", 			"2");		// ilosc skoko wdo kupienia
	cvar_ile_pancerz	= register_cvar("ile_pancerza", 		"100");		// ilość pancerza do kupienia limit 300
	
	
	/*================================
		    [APTEKA]
	=================================*/

	cvar_mhp		= register_cvar("cena_mala_mikstura_hp", 	"15");		// Cena za male hp
	cvar_ile_mhp		= register_cvar("ile_mala_mikstura_hp", 	"10");		// Ilość malego hp do kupienia.
	cvar_shp		= register_cvar("cena_srednia_mikstura_hp", 	"24");		// Cena za srednia miksture hp
	cvar_ile_shp		= register_cvar("ile_srednia_mikstura_hp", 	"20");		// Ilość sredniego hp do kupienia
	cvar_dhp		= register_cvar("cena_duza_mikstura_hp", 	"34");		// Cena za dużą miksture hp.
	cvar_ile_dhp		= register_cvar("ile_duzego_hp", 		"30");		// Ilość dużego hp do kupienia
	cvar_rhp		= register_cvar("cena_regeneracji_hp", 		"35");		// Cena za regeneracje hp.
	cvar_lhp		= register_cvar("cena_losowego_hp", 		"40");		// Cena za losowe hp.	
	cvar_min_lhp		= register_cvar("cena_min_losowego_hp",	 	"10")		// minimum hp ktore mozna wylosowac
	cvar_max_lhp		= register_cvar("cena_max_losowego_hp", 	"70")		// max hp ktore mzona wylosowac
	
	
	/*================================
		  [Czarny Rynek]
	=================================*/
	
	cvar_ile_rakiet		= register_cvar("ilosc_rakiet", 		"1");		// ilsoc rakiet do kupienia
	cvar_rakiety		= register_cvar("cena_za_rakiety", 		"35");		// Cena za rakiete
	cvar_zestaw		= register_cvar("cena_za_zestaw_granatow", 	"25");		// Cena za Zestaw Granatow
	cvar_perk		= register_cvar("cena_za_perk", 		"30");		// Cena za losowy perk
	cvar_recoil		= register_cvar("cena_za_norecoil", 		"45");		// Cena za NoRecoil
	cvar_plaszcz		= register_cvar("cena_za_plaszcz", 		"35");		// Mniejsza widzialność
	cvar_ile_plaszcz	= register_cvar("ile_procent_niewidzialnosci", 	"60");		// ilość niewidzialności
	cvar_noammo		= register_cvar("cena_za_noammo", 		"65");		// Cena za Nieskonczoność ammo
	cvar_radar		= register_cvar("cena_za_radar", 		"50");		// Cena za Radar
	
	/*================================
		  [Doswiadczenie]
	=================================*/
	
	cvar_ile_mze 		= register_cvar("ile_malego_zestawu_xp", 	"300");		// ilosc malego expa do kupienia
	cvar_mze		= register_cvar("cena_malego_zestawu_xp", 	"50");		// cena za maly zestaw expa
	cvar_ile_sze		= register_cvar("ile_sredniego_zestawu_xp", 	"700");		// ilosc sredniego expa do kupienia
	cvar_sze		= register_cvar("cena_sredniego_zestawu_xp", 	"120");		// cena za sredni zestaw expa
	cvar_ile_dze		= register_cvar("ile_duzego_zestawu_xp",	"1200");	// ilosc duzego expa do kupienia
	cvar_dze		= register_cvar("cena_duzego_zestawu_xp", 	"190");		// cena za duzy zestaw expa
	
	cvar_min_lexp		= register_cvar("ile_mix_losowego_xp", 		"300");		// minimum loswego doswiadczenia
	cvar_max_lexp		= register_cvar("ile_max_losowego_xp", 		"300");		// max losowego doswiadcznia
	cvar_lexp		= register_cvar("cena_losowego_xp", 		"2100");	// cena losowego doswiadczenia
	
	
	set_task(1.0, "plugin_cfg");
}
public plugin_cfg()
{
	new lokalizacja_cfg[33];
	get_configsdir(lokalizacja_cfg, charsmax(lokalizacja_cfg));
	server_cmd("exec %s/sklep.cfg", lokalizacja_cfg);
	server_exec()
}
public Koniec_Rundy()
{
	for(new i =1;i<33;i++)
	{
		if(is_user_connected(i))
		{
			a_dmg[i] = false;
			set_user_footsteps(i, 0);
			odpornosc_he[i] = false;
			odpornosc_fb[i] = false;
			DodatkowySkok[i] = false;
			NoRecoil[i] = false;
			Niewidzialnosc[i] = false;
			Regeneracja[i] = false;
			NoAmmo[i] = false;
			Radar[i] = false;
		}
	}
}
public client_authorized(id)
{	
	/* Rakiety */
	ilosc_rakiet[id] = 0;
	ma_rakiete[id] = false;
	
}
public plugin_precache() 
{ 	
	precache_sound(sound_radar)	
	sprite_blast = precache_model("sprites/dexplo.spr");
	precache_model("models/rpgrocket.mdl");	
	precache_sound("misc/select.wav");
	return PLUGIN_CONTINUE;
}
public client_disconnect(id)
{	
	/* Rakiety */
	new entRakiety = find_ent_by_class(0, "rocket2");
	while(entRakiety > 0)
	{
		if(entity_get_edict(entRakiety, EV_ENT_owner) == id)
			remove_entity(entRakiety);
		entRakiety = find_ent_by_class(entRakiety, "rocket2");
	}
	ilosc_rakiet[id] = 0;
	ma_rakiete[id] = false;
}
public cmd_menu(id)
{
	if(is_user_alive(id)) {
		Menu(id);
	}
	else {
		ColorChat( id, TEAM_COLOR, "%s Musisz byc zywy, aby korzystac ze sklepu!", prefix );
	}
	return PLUGIN_HANDLED;
}
public Menu(id)
{
	if(cod_set_user_hud(id))
		return PLUGIN_CONTINUE;
		
	get_user_name(id, name, 32);
	formatex(tytul, 124,"Witaj %s, w naszym Sklepie :)", name );
	new menu = menu_create(tytul, "Menu_Handler" );	
	
	menu_additem(menu, "Wyposazenie")
	menu_additem(menu, "Apteka");
	menu_additem(menu, "Doswiadczenie");
	menu_additem(menu, "Czarny Rynek");
	
	menu_display(id, menu)
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}

public Menu_Handler(id, menu, key)
{
	if(key == MENU_EXIT)
	{
		cod_get_user_hud(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	switch(key)
	{
		case 0: MenuWyposazenie(id)
		case 1: MenuApteka(id)
		case 2: MenuDoswiadczenie(id)
		case 3: CzarnyRynek(id)
	}
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}

public MenuWyposazenie(id)
{
	new tytul[128];
	
	formatex(tytul, charsmax(tytul), "\w-==|\r Wyposazenie\w |==-^nPosiadasz:\r %i\w Orderow", get_waluta );
	new menu = menu_create(tytul, "Wyposazenie_Handler");
	
	formatex(tytul, charsmax(tytul), "Wieksze DMG \d[ +5 ] \yKoszt:\r %i Orderow", get_pcvar_num(cvar_dmg) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Ciche Chodzenie \yKoszt:\r %i Orderow", get_pcvar_num(cvar_ciche_kroki) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Odpornosc na HE \yKoszt:\r %i Orderow", get_pcvar_num(cvar_odpornosc_he) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Odpornosc na Fleshe \yKoszt:\r %i Orderow", get_pcvar_num(cvar_odpornosc_fb) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Dodatkowe Skoki \d[ +%i ] \yKoszt:\r %i Orderow", get_pcvar_num(cvar_ile_skokow), get_pcvar_num(cvar_skoki) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Dodatkowy Pancerz \d[ +%i ] \yKoszt:\r %i Orderow", get_pcvar_num(cvar_ile_pancerz), get_pcvar_num(cvar_pancerz) );	
	menu_additem(menu, tytul);
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu);
	
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}
public Wyposazenie_Handler(id, menu, key)
{
	if(key == MENU_EXIT)
	{
		Menu(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	
	new kasa = get_waluta;
	switch(key)
	{
		case 0:
		{
			if(kasa >= get_pcvar_num(cvar_dmg) )
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_dmg) )
				a_dmg[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles dodatkowe^x04 +5 dmg", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 1:
		{
			if(kasa >= get_pcvar_num(cvar_ciche_kroki) )
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_ciche_kroki) )
				set_user_footsteps(id, 1);
				ColorChat( id, TEAM_COLOR, "%s Kupiles Ciche Chodzenie", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 2:
		{
			if(kasa >= get_pcvar_num(cvar_odpornosc_he) )
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_odpornosc_he) )
				odpornosc_he[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles Odpornosc na Granaty Wybuchowe", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 3:
		{
			if(kasa >= get_pcvar_num(cvar_odpornosc_fb))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_odpornosc_fb))
				odpornosc_fb[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles Odpornosc na Fleshe", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 4:
		{
			if(kasa >= get_pcvar_num(cvar_skoki) )
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_skoki) )
				DodatkowySkok[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i Skokow", prefix, get_pcvar_num(cvar_ile_skokow) );
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 5:
		{
			if(kasa >= get_pcvar_num(cvar_pancerz) )
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_pancerz) )
				cs_set_user_armor(id, min(cs_get_user_armor(id,armortype)+ get_pcvar_num(cvar_ile_pancerz), 300), armortype);
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i Pancerza", prefix, get_pcvar_num(cvar_ile_pancerz) );
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}		
	}
	cod_get_user_hud(id)
	return PLUGIN_CONTINUE
}	
public MenuApteka(id)
{
	formatex(tytul, 124,"\w-==|\r Apteka\w |==-^nPosiadasz:\r %i\w Orderow ", get_waluta );
	new menu = menu_create(tytul, "Apteka_Handler" );
	
	
	formatex(tytul, charsmax(tytul), "Mala Mikstura Leczenia \d[ +%i HP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_mhp), get_pcvar_num(cvar_mhp) )
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Srednia Mikstura Leczenia \d[ +%i HP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_shp), get_pcvar_num(cvar_shp) )
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Duza Mikstura Leczenia \d[ +%i HP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_dhp), get_pcvar_num(cvar_dhp) )	
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Regenreacja HP \d[ +1HP / 1Sekunda ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_rhp))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Losowe HP \d[ +%i / %i HP ] \yKoszt: \r40 Orderow", get_pcvar_num(cvar_min_lhp), get_pcvar_num(cvar_max_lhp), get_pcvar_num(cvar_lhp))	 
	menu_additem(menu, tytul);
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu);
	
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}
public Apteka_Handler(id, menu, key)
{
	if(key == MENU_EXIT)
	{
		Menu(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	
	new kasa = get_waluta;
	
	switch(key)
	{
		case 0:
		{
			if(kasa >= get_pcvar_num(cvar_mhp))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_mhp))
				set_user_health( id, get_user_health( id ) + get_pcvar_num(cvar_ile_mhp) );
				Display_Fade(id, 1<<10, 1<<10 ,1<<14, 118, 253, 89, 230);
				ColorChat( id, TEAM_COLOR, "%s Kupiles^x04 +%i HP", prefix, get_pcvar_num(cvar_ile_mhp));
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 1:
		{
			if(kasa >= get_pcvar_num(cvar_shp))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_shp))
				set_user_health( id, get_user_health( id ) + get_pcvar_num(cvar_ile_shp));
				Display_Fade(id, 1<<10, 1<<10 ,1<<14, 118, 253, 89, 230);
				ColorChat( id, TEAM_COLOR, "%s Kupiles^x04 +%i HP", prefix, get_pcvar_num(cvar_ile_shp));
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 2:
		{
			if(kasa >= get_pcvar_num(cvar_dhp))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_dhp))
				set_user_health( id, get_user_health( id ) + get_pcvar_num(cvar_ile_dhp));
				Display_Fade(id, 1<<10, 1<<10 ,1<<14, 118, 253, 89, 230);
				ColorChat( id, TEAM_COLOR, "%s Kupiles^x04 +%i HP", prefix, get_pcvar_num(cvar_ile_dhp));
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 3:
		{
			if(kasa >= get_pcvar_num(cvar_rhp))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_rhp))
				Regeneracja[id] = true
				Display_Fade(id, 1<<10, 1<<10 ,1<<14, 118, 253, 89, 230);
				ColorChat( id, TEAM_COLOR, "%s Kupiles^x04 Regeneracje HP", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}	
		case 4:
		{
			if(kasa >= get_pcvar_num(cvar_lhp))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_lhp))
				new los = random_num(get_pcvar_num(cvar_min_lhp), get_pcvar_num(cvar_max_lhp))
				set_user_health(id, get_user_health(id)+los);
				Display_Fade(id, 1<<10, 1<<10 ,1<<14, 118, 253, 89, 230);
				ColorChat( id, TEAM_COLOR, "%s Wylosowales %i HP", prefix, los);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}		
	}
	cod_get_user_hud(id)
	return PLUGIN_CONTINUE
}
public MenuDoswiadczenie(id)
{
	new tytul[128];
	
	formatex(tytul, charsmax(tytul), "\w-==|\r Doswiadczenie\w |==-^nPosiadasz:\r %i\w Orderow", get_waluta );
	new menu = menu_create(tytul, "Doswiadczenie_Handler");
	
		
	formatex(tytul, charsmax(tytul), "Maly Zestaw Expa \d[ +%i EXP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_mze), get_pcvar_num(cvar_mze) );
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Sredni Zestaw Expa \d[ +%i EXP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_sze), get_pcvar_num(cvar_sze) );
	menu_additem(menu, tytul);	
	
	formatex(tytul, charsmax(tytul), "Duzy Zestaw Expa \d[ +%i EXP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_dze), get_pcvar_num(cvar_dze) );
	menu_additem(menu, tytul);	
	
	formatex(tytul, charsmax(tytul), "Losowy Exp \d[ +%i | %i EXP ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_min_lexp), get_pcvar_num(cvar_max_lexp), get_pcvar_num(cvar_lexp) );
	menu_additem(menu, tytul);		
	
	
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu);
	
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}
public Doswiadczenie_Handler(id, menu, key)
{
	if(key == MENU_EXIT)
	{
		Menu(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	
	new kasa = get_waluta;
	new exp = cod_get_user_xp(id);
	
	switch(key)
	{
		case 0:
		{
			if(kasa >= get_pcvar_num(cvar_mze) )
			{
				set_waluta(id, kasa - get_pcvar_num(cvar_mze));
				cod_set_user_xp(id, exp + get_pcvar_num(cvar_ile_mze))
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i EXP'a!", prefix, get_pcvar_num(cvar_ile_mze) );
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 1:
		{
			if(kasa >= get_pcvar_num(cvar_sze) )
			{
				set_waluta(id, kasa - get_pcvar_num(cvar_sze));
				cod_set_user_xp(id, exp + get_pcvar_num(cvar_ile_sze))
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i EXP'a!", prefix, get_pcvar_num(cvar_ile_sze) );
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}		
		case 2:
		{
			if(kasa >= get_pcvar_num(cvar_dze) )
			{
				set_waluta(id, kasa - get_pcvar_num(cvar_dze));
				cod_set_user_xp(id, exp + get_pcvar_num(cvar_ile_dze))
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i EXP'a!", prefix, get_pcvar_num(cvar_ile_dze) );
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}
		case 3:
		{
			if(kasa >= get_pcvar_num(cvar_lexp))
			{
				
				new losowy = random_num(get_pcvar_num(cvar_min_lexp), get_pcvar_num(cvar_max_lexp));
				set_waluta(id, kasa - get_pcvar_num(cvar_lexp));
				cod_set_user_xp(id, exp+losowy)
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i EXP'a!", prefix, losowy);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);
		}		
	}
	cod_get_user_hud(id)
	return PLUGIN_CONTINUE
}
public CzarnyRynek(id)	
{
	formatex(tytul, 124,"\w-==|\r Czarny Rynek\w |==-^nPosiadasz:\r %i\w Orderow ", get_waluta );
	new menu = menu_create(tytul, "CzarnyRynek_Handler" );	
	
	
	
	formatex(tytul, charsmax(tytul), "Rakieta \d[ +%i ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_rakiet), get_pcvar_num(cvar_rakiety))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Zestaw Granatow \d[ HE, FB, SB ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_zestaw))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Losowy Perk \yKoszt: \r%i Orderow", get_pcvar_num(cvar_perk))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "NoRecoil \d[ Brak Rozrzutu ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_recoil))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Plaszcz Ducha \d[ Redukcja niewidzialnosci o %i% ] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_ile_plaszcz), get_pcvar_num(cvar_plaszcz))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Nieskonczona Amunicja \yKoszt: \r%i Orderow", get_pcvar_num(cvar_noammo))
	menu_additem(menu, tytul);
	
	formatex(tytul, charsmax(tytul), "Radar \d[Widzisz Wrogow Na Radarze] \yKoszt: \r%i Orderow", get_pcvar_num(cvar_radar))
	menu_additem(menu, tytul);
	

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
	menu_display(id, menu);
	
	client_cmd(id, "spk misc/select");
	return PLUGIN_HANDLED;
}
public CzarnyRynek_Handler(id, menu, key)
{
	if(key == MENU_EXIT)
	{
		Menu(id)
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	
	new kasa = get_waluta;
	
	switch(key)
	{
		case 0:
		{
			if(kasa >= get_pcvar_num(cvar_rakiety))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_rakiety))
				ilosc_rakiet[id] += get_pcvar_num(cvar_ile_rakiet);
				ma_rakiete[id] = true;
				rakieta_gracza[id] = true;		
				ColorChat( id, TEAM_COLOR, "%s Kupiles %i Rakiet", prefix, get_pcvar_num(cvar_ile_rakiet));
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);		
		}
		case 1:
		{
			if(cod_get_user_class(id) == cod_get_classid("Gogus [MegaP]"))
			{
				ColorChat( id, TEAM_COLOR, "%s Zakaz kupowania granatow na tej klasie !", prefix);
				return COD_STOP;
			}
			if(kasa >= get_pcvar_num(cvar_zestaw))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_zestaw))
				give_item(id, "weapon_hegrenade");
				give_item(id, "weapon_flashbang");
				give_item(id, "weapon_flashbang");
				give_item(id, "weapon_smokegrenade");	
				ColorChat( id, TEAM_COLOR, "%s Kupiles Zestaw Granatow", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);			
		}
		case 2:
		{
			if(kasa >= get_pcvar_num(cvar_perk))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_perk))
				cod_set_user_perk(id, -1, -1, 1);
				ColorChat( id, TEAM_COLOR, "%s Kupiles Losowy Perk", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);	
		}
		case 3:
		{
			if(kasa >= get_pcvar_num(cvar_recoil))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_recoil))
				NoRecoil[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles NoRecoila [Na 1 Runde]", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);	
		}
		case 4:
		{
			if(kasa >= get_pcvar_num(cvar_plaszcz))
			{	
				set_waluta(id, kasa - get_pcvar_num(cvar_plaszcz))
				Niewidzialnosc[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles Placz Ducha (Redukcja Obrazen do 60%) [Na 1 Runde]", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orderow", prefix);	
		}
		case 5:
		{
			if(kasa >= get_pcvar_num(cvar_noammo))
			{
				set_waluta(id, kasa - get_pcvar_num(cvar_noammo))
				NoAmmo[id] = true;
				ColorChat( id, TEAM_COLOR, "%s Kupiles Nieskonczona Amunicje [Na 1 Runde]", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orederow", prefix);
		}
		case 6:
		{
			if(kasa >= get_pcvar_num(cvar_radar))
			{
				set_waluta(id, kasa - get_pcvar_num(cvar_radar))
				Radar[id] = true;
				set_task (2.0,"radar_scan",_,_,_,"b");
				ColorChat( id, TEAM_COLOR, "%s Kupiles Radar (Widzisz Wrogow Na Radarze) [Na 1 Runde]", prefix);
			}
			else
				ColorChat( id, TEAM_COLOR, "%s Niestety, masz za malo orederow", prefix);
		}		
	}
	cod_get_user_hud(id)
	return PLUGIN_CONTINUE
}
public messageScreenFade(msgtype, msgid, id)
{
	if(odpornosc_fb[id])    
		return PLUGIN_HANDLED;
	
	return PLUGIN_CONTINUE;
}
public TakeDamage(this, idinflictor, idattacker, Float:damage, damagebits)
{
	if(!is_user_connected(this) || !is_user_connected(idattacker))
		return HAM_IGNORED;
		
	if(odpornosc_he[this] && damagebits & DMG_HEGRENADE)
		return HAM_SUPERCEDE;	
		
	if(a_dmg[idattacker] && get_user_team(this) != get_user_team(idattacker) && damagebits & DMG_BULLET)
		cod_inflict_damage(idattacker, this, 5.0, 0.0, idinflictor, damagebits);
		
	return HAM_IGNORED;
}

public fwCmdStart_MultiJump(id, uc_handle)
{
	if(!is_user_alive(id) || !DodatkowySkok[id])
		return FMRES_IGNORED;

	new flags = pev(id, pev_flags);

	if((get_uc(uc_handle, UC_Buttons) & IN_JUMP) && !(flags & FL_ONGROUND) && !(pev(id, pev_oldbuttons) & IN_JUMP) && skoki[id])
	{
		skoki[id]--;
		new Float:velocity[3];
		pev(id, pev_velocity,velocity);
		velocity[2] = random_float(265.0,285.0);
		set_pev(id, pev_velocity,velocity);
	}
	else if(flags & FL_ONGROUND)
		skoki[id] = get_pcvar_num(cvar_ile_skokow);

	return FMRES_IGNORED;
}
stock Display_Fade(id,duration,holdtime,fadetype,red,green,blue,alpha)
{
	message_begin( MSG_ONE, g_msg_screenfade,{0,0,0},id );
	write_short( duration );
	write_short( holdtime );	
	write_short( fadetype );	
	write_byte ( red );		
	write_byte ( green );		
	write_byte ( blue );	
	write_byte ( alpha );	
	message_end();
}
public client_PreThink(id)
{
	if (!is_user_alive(id))
		return
	
	new button = get_user_button(id)
	
	if (button & IN_USE)
	{
		if(ma_rakiete[id])
		{
			if (!ilosc_rakiet[id])
			{
				client_print(id, print_center, "Wykorzystales juz wszystkie rakiety!");
				ma_rakiete[id] = false;
			}
			else
			{
				if(poprzednia_rakieta[id] + 5.0 > get_gametime())
				{
					client_print(id, print_center, "Rakiet mozesz uzywac co 5 sekundy!");
				}			
				else
				{
					poprzednia_rakieta[id] = floatround(get_gametime());
					ilosc_rakiet[id]--;
					
					new Float: Origin[3], Float: vAngle[3], Float: Velocity[3];
					
					entity_get_vector(id, EV_VEC_v_angle, vAngle);
					entity_get_vector(id, EV_VEC_origin , Origin);
					
					new Ent = create_entity("info_target");
					
					entity_set_string(Ent, EV_SZ_classname, "rocket2");
					entity_set_model(Ent, "models/rpgrocket.mdl");
					
					vAngle[0] *= -1.0;
					
					entity_set_origin(Ent, Origin);
					entity_set_vector(Ent, EV_VEC_angles, vAngle);
					
					entity_set_int(Ent, EV_INT_effects, 2);
					entity_set_int(Ent, EV_INT_solid, SOLID_BBOX);
					entity_set_int(Ent, EV_INT_movetype, MOVETYPE_FLY);
					entity_set_edict(Ent, EV_ENT_owner, id);
					
					VelocityByAim(id, 1000 , Velocity);
					entity_set_vector(Ent, EV_VEC_velocity ,Velocity);
				}
			}	
		}
	}
}
public DotykRakiety(ent)
{
	if (!is_valid_ent(ent))
		return;
	
	new attacker = entity_get_edict(ent, EV_ENT_owner);
	
	
	new Float:fOrigin[3];
	entity_get_vector(ent, EV_VEC_origin, fOrigin);
	
	new iOrigin[3];
	for(new i=0;i<3;i++)
		iOrigin[i] = floatround(fOrigin[i]);
	
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY, iOrigin);
	write_byte(TE_EXPLOSION);
	write_coord(iOrigin[0]);
	write_coord(iOrigin[1]);
	write_coord(iOrigin[2]);
	write_short(sprite_blast);
	write_byte(32);
	write_byte(20);
	write_byte(0);
	message_end();
	
	new entlist[33];
	new numfound = find_sphere_class(ent, "player", 190.0, entlist, 32);
	
	for (new i=0; i < numfound; i++)
	{
		new pid = entlist[i];
		
		if (!is_user_alive(pid) || get_user_team(attacker) == get_user_team(pid))
			continue;
			
		if (rakieta_gracza[attacker])
		{
			cod_inflict_damage(attacker, pid, 25.0, 0.2, ent, (1<<24));
		}		
	}
	remove_entity(ent);
}
public PreThink(id)
{	
	if(NoRecoil[id])
		set_pev(id, pev_punchangle, {0.0,0.0,0.0})
}
public UpdateClientData(id, sw, cd_handle)
{
	if(NoRecoil[id])
		set_cd(cd_handle, CD_PunchAngle, {0.0,0.0,0.0}) 	
}
public Invisible(id)
{
	if(Niewidzialnosc[id])
		set_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, get_pcvar_num(cvar_ile_plaszcz));
}

public WyszkolenieSanitarne(id)
{	
	if(!is_user_connected(id))
		return PLUGIN_CONTINUE;
		
	if(Regeneracja[id])
	{
		set_task(1.0, "WyszkolenieSanitarne", id+736);
		
		if(is_user_alive(id))
		{
			new cur_health = get_user_health(id);
			new max_health = (cod_get_user_health(id))+100;
			new new_health;
	
			//floatround(wartosc_regeneracji_gracza[id], floatround_floor)
	
			if(cur_health+1< max_health)
			{
				new_health = cur_health+1;
				set_user_health(id, new_health);
				message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
				write_short(1<<10)
				write_short(1<<10)
				write_short(0x0000)
				write_byte(0)
				write_byte(200)
				write_byte(0)
				write_byte(75)
				message_end()			
			}
			else
			{
				new_health = max_health;
			}		
		}
	}
	return PLUGIN_CONTINUE;
}
public CmdStart(id, uc_handle)
{
	if(!is_user_alive(id) || !NoAmmo[id])
		return FMRES_IGNORED;
	
	new buttons = get_uc(uc_handle, UC_Buttons);
	new oldbuttons = pev(id, pev_oldbuttons);
	new clip, ammo, weapon = get_user_weapon(id, clip, ammo);
	
	if(max_clip[weapon] == -1 || !ammo)
		return FMRES_IGNORED;
	
	if((buttons & IN_RELOAD && !(oldbuttons & IN_RELOAD) && !(buttons & IN_ATTACK)) || !clip)
	{
		cs_set_user_bpammo(id, weapon, ammo-(max_clip[weapon]-clip));
		new new_ammo = (max_clip[weapon] > ammo)? clip+ammo: max_clip[weapon]
		set_user_clip(id, new_ammo);
	}
	
	return FMRES_IGNORED;
}

stock set_user_clip(id, ammo)
{
	new weaponname[32], weaponid = -1, weapon = get_user_weapon(id, _, _);
	get_weaponname(weapon, weaponname, 31);
	while ((weaponid = engfunc(EngFunc_FindEntityByString, weaponid, "classname", weaponname)) != 0)
		if (pev(weaponid, pev_owner) == id) {
		set_pdata_int(weaponid, 51, ammo, 4);
		return weaponid;
	}
	return 0;
}
public radar_scan(id)
{
	new PlayerCoords[3];
                
	for (new id=1; id<=32; id++)
	{
		if((!is_user_alive(id))||(!Radar[id])) continue;
                        
		for (new i=1;i<=32;i++)
		{       
			if(!is_user_alive(i) || get_user_team(i) == get_user_team(id)) continue;
			
			get_user_origin(i, PlayerCoords)
                                
			message_begin(MSG_ONE_UNRELIABLE, g_msgHostageAdd, {0,0,0}, id)
			write_byte(id)
			write_byte(i)           
			write_coord(PlayerCoords[0])
			write_coord(PlayerCoords[1])
			write_coord(PlayerCoords[2])
			message_end()
                                
			message_begin(MSG_ONE_UNRELIABLE, g_msgHostageDel, {0,0,0}, id)
			write_byte(i)
			message_end()
		}
		emit_sound(id, CHAN_ITEM, sound_radar, 1.0, ATTN_NORM, 0, PITCH_NORM);
	}
}


