#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <engine>
#include <fun>
#include <csx>
#include <xs>
#include <hamsandwich>
#include <codmod>
#include <ColorChat>

new const nazwa[] = "Miotacz [SuperVIP]";
new const opis[] = "Posiada miotacz ognia zamiast noza!";
new const bronie = 1<<CSW_M3;
new const zdrowie = 15;
new const kondycja = 20;
new const inteligencja = 10;
new const wytrzymalosc = 5;

new bool:ma_klase[33];

new wpn_ft
new sprite_fire
new sprite_burn
new sprite_xplo
new g_freezetime
new g_restarted
new Float:g_starttime
new cvar_enabled
new cvar_client_buy
new cvar_damage
new cvar_xplode_dmg
new cvar_cost
new cvar_fuelcost
new cvar_fueltank
new cvar_buyzone
new cvar_buytime
new cvar_damage_dis
new cvar_splash_dis
new g_buyzone[33]
new g_FuelTank[33]
new g_Activated[33]
new Float:g_Delay[33]
new g_hasFlamethrower[33]
new g_FireFlamethrower[33]
new g_BuyFuel[33]
new cvar_expcod

static PLUGIN_NAME[] 	= "Miotacz ognia for cod"
static PLUGIN_AUTHOR[] 	= "Cheap_Suit eited by Crew"
static PLUGIN_VERSION[] = "1.1"

public plugin_init()
{
	RegisterHam(Ham_Spawn, "player", "Spawn", 1);
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
	register_cvar("ft_version", PLUGIN_VERSION, FCVAR_SERVER)
	
	cvar_enabled 	= register_cvar("ft_enable", 		"1")
	cvar_fueltank 	= register_cvar("ft_fueltank", 		"50")
	cvar_damage	= register_cvar("ft_damage", 		"2")
	cvar_xplode_dmg = register_cvar("ft_xplode_dmg", 	"30")
	cvar_damage_dis	= register_cvar("ft_damage_dis", 	"100")
	cvar_splash_dis = register_cvar("ft_splash_dis", 	"40")
	cvar_expcod 	= register_cvar("cod_xpmiotacz", 	"20")
	
	register_event("DeathMsg",  	"Event_DeathMsg", 	"a")
	register_event("CurWeapon", 	"Event_CurWeapon", 	"be", 	"1=1")
	register_event("StatusIcon", 	"Event_BuyZone",  	"b", 	"2=buyzone")
	register_event("HLTV", 		"Event_NewRound", 	"a", 	"1=0", "2=0")
	register_event("TextMsg", 	"Event_WeaponDrop", 	"be", 	"2=#Weapon_Cannot_Be_Dropped")
	register_event("TextMsg", 	"Event_GameRestart", 	"a", 	"2=#Game_Commencing", 	"2=#Game_will_restart_in")
	register_logevent("LogEvent_RoundStart", 		 2, 	"0=World triggered",	"1=Round_Start")
	
	register_forward(FM_CmdStart,		"fw_CmdStart")
	register_forward(FM_PlayerPostThink, 	"fw_PlayerPostThink")
	register_forward(FM_UpdateClientData, 	"fw_UpdateClientData_Post", 1)
	
	register_think("flamethrower", "think_Flamethrower")
	register_touch("flamethrower", "player", "touch_Flamethrower")
	wpn_ft = custom_weapon_add("weapon_flamethrower", 0, "flamethrower")
	
	if(!get_pcvar_num(cvar_enabled)) pause("ad", PLUGIN_NAME)
}

public plugin_precache()
{
	precache_sound("flamethrower.wav")
	precache_sound("items/ammopickup2.wav")
	
	sprite_xplo = precache_model("sprites/zerogxplode.spr")
	sprite_fire = precache_model("sprites/explode1.spr")
	sprite_burn = precache_model("sprites/xfire.spr")
	
	precache_model("models/v_knife.mdl")
	precache_model("models/p_knife.mdl")
	precache_model("models/shield/v_shield_knife.mdl")
	precache_model("models/shield/p_shield_knife.mdl")
	precache_model("models/w_flamethrower.mdl")
	precache_model("models/v_flamethrower.mdl")
	precache_model("models/p_flamethrower.mdl")
}

public cmd_GiveFlamethrowers(id, level, cid) 
{
	if(!cmd_access(id, level, cid, 2))
		return PLUGIN_HANDLED
	
	new Arg1[64], target
	read_argv(1, Arg1, 63)
	
	new adminName[32]
	get_user_name(id, adminName, 31)
	
	new targetTeam
	new Players[32], iNum
	if(Arg1[0] == '@') 
	{
		if(equali(Arg1[1], "all")) 
		{
			targetTeam = 0
			get_players(Players, iNum, "a")
		} 
		else if(equali(Arg1[1], "t")) 
		{
			targetTeam = 1
			get_players(Players, iNum, "ae" , "terrorist")
			
		} 
		else if(equali(Arg1[1], "ct")) 
		{
			targetTeam = 2
			get_players(Players, iNum, "ae" , "ct")
		}
		
		for(new i = 0; i < iNum; ++i)
		{
			target = Players[i]
			
			g_hasFlamethrower[target] = 1
			g_FuelTank[target] = get_pcvar_num(cvar_fueltank)
			
			new temp[2], weaponID = get_user_weapon(target, temp[0], temp[1])
			if(weaponID == CSW_KNIFE) 
			{
				g_Activated[target] = true
				set_flamethrower_model(target)
			}
			
			client_cmd(target, "spk items/ammopickup2")
			client_print(target, print_chat, "You have been given a flamethrower (press 3 to use)")
		}
		
		switch(targetTeam)
		{
			case 0: client_print(0, print_chat, "Admin: %s has given everyone a flamethrower", adminName)
				case 1: client_print(0, print_chat, "Admin: %s has given all terrorist a flamethrower", adminName)
				case 2: client_print(0, print_chat, "Admin: %s has given all ct's a flamethrower", adminName)
			}
	}
	else
	{
		target = cmd_target(id, Arg1, 0)
		if(!is_user_connected(target) || !is_user_alive(target))
			return PLUGIN_HANDLED
		
		new targetName[32]
		get_user_name(target, targetName, 31)
		
		g_hasFlamethrower[target] = 1
		g_FuelTank[target] = get_pcvar_num(cvar_fueltank)
		
		new temp[2], weaponID = get_user_weapon(target, temp[0], temp[1])
		if(weaponID == CSW_KNIFE) 
		{
			g_Activated[target] = true
			set_flamethrower_model(target)
			entity_set_int(id, EV_INT_weaponanim, 9)
		}
		
		client_cmd(target, "spk items/ammopickup2")
		client_print(target, print_chat, "You have been given a flamethrower (press 3 to use)")
		client_print(target, print_chat, "Admin: %s has given you a flamethrower", adminName)
	}
	return PLUGIN_HANDLED
}

public cmd_BuyFlamethrower(id)
{
	if(!get_pcvar_num(cvar_client_buy))
		return PLUGIN_CONTINUE
	
	if(get_pcvar_num(cvar_buyzone))
	{
		if(!g_buyzone[id])
		{
			client_print(id, print_center, "You need to be in the buyzone")
			return PLUGIN_HANDLED
		} 
	}
	
	if(get_pcvar_num(cvar_buytime))
	{
		new Float:fBuyTime = get_cvar_float("mp_buytime") * 60
		if(!g_freezetime && (get_gametime() - g_starttime) > fBuyTime) 
		{
			client_print(id, print_center, "%d seconds have passed.^nYou can't buy anything now!", floatround(fBuyTime))
			return PLUGIN_HANDLED
		}
	}
	
	new iMoney = cs_get_user_money(id)
	new iCost = get_pcvar_num(cvar_cost)
	
	if(!is_user_alive(id)) 
		client_print(id, print_center, "You cant buy when your dead!")
	else if(g_hasFlamethrower[id])
		client_print(id, print_center, "You already own that weapon.")
	else if(iMoney < iCost)
		client_print(id, print_center, "Insufficient funds! ($%d)", iCost)
	else
	{
		g_hasFlamethrower[id] = 1
		g_FuelTank[id] = get_pcvar_num(cvar_fueltank)
		
		new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
		if(weaponID == CSW_KNIFE) 
		{
			g_Activated[id] = true
			set_flamethrower_model(id)
		}
		
		cs_set_user_money(id, iMoney - iCost)
		client_cmd(id, "spk items/ammopickup2")
		client_print(id, print_chat, "You bought a flamethrower (press 3 to use)")
	}
	return PLUGIN_HANDLED
}

public Event_BuyZone(id) {
	g_buyzone[id] = read_data(1)
}

public Event_GameRestart() {
	g_restarted = 1
}

public Event_NewRound() 
{
	if(g_restarted)
	{
		new Players[32], iNum = 0
		get_players(Players, iNum)
		for(new i = 0; i < iNum; i++) 
		{
			new id = Players[i]
			
			g_FuelTank[id] = 0
			g_Activated[id] = 0
			g_hasFlamethrower[id] = 0
			
			new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
			if(weaponID == CSW_KNIFE) set_knife_model(id)
			
			g_restarted = 0
		}
	}
	
	new flamethrowers = -1
	while((flamethrowers = find_ent_by_class(flamethrowers, "flamethrower")))
		remove_entity(flamethrowers)
	
	g_freezetime = 1
}

public LogEvent_RoundStart()
{
	g_freezetime = 0
	g_starttime = get_gametime()
}

public Event_WeaponDrop(id)
{
	if(!is_user_alive(id) || !g_Activated[id])
		return PLUGIN_CONTINUE
	
	client_print(id, print_center, "")
	return PLUGIN_HANDLED
}

public Event_DeathMsg() 
{ 
	new id = read_data(2)
	if(!is_user_connected(id) || !g_hasFlamethrower[id]) {
		return PLUGIN_CONTINUE
	}
	
	return PLUGIN_CONTINUE
}

public Event_CurWeapon(id)
{
	if(!is_user_alive(id) || !g_hasFlamethrower[id]) 
		return PLUGIN_CONTINUE
	
	new WeaponID = read_data(2)
	switch(WeaponID) 
	{
		case CSW_KNIFE:
		{
			set_task(0.3, "task_ActivateFlamethrower", id)
			set_flamethrower_model(id)
			entity_set_int(id, EV_INT_weaponanim, 9)
		}
		default: g_Activated[id] = 0
	}
	return PLUGIN_CONTINUE
}

public touch_Flamethrower(ent, id)
{
	if(!is_valid_ent(ent) || !is_user_alive(id)) 
		return PLUGIN_CONTINUE
	
	if(g_hasFlamethrower[id])
		return PLUGIN_CONTINUE
	
	if(has_shield(id))
		return PLUGIN_CONTINUE
	
	g_hasFlamethrower[id] = 1
	client_cmd(id, "spk items/ammopickup2")
	g_FuelTank[id] = entity_get_int(ent, EV_INT_iuser4)
	show_fuel_percentage(id)
	
	new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
	if(weaponID == CSW_KNIFE) 
	{
		g_Activated[id] = true
		set_flamethrower_model(id)
		entity_set_int(id, EV_INT_weaponanim, 9)
	}
	remove_entity(ent)
	
	return PLUGIN_CONTINUE
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle) 
{
	if(!g_hasFlamethrower[id] || !g_Activated[id])
		return FMRES_IGNORED
	
	set_cd(cd_handle, CD_ID, 0)
	return FMRES_HANDLED
}

public fw_CmdStart(id, uc_handle, seed) 
{
	if(!g_hasFlamethrower[id] || !g_Activated[id])
		return FMRES_IGNORED
	
	new buttons = get_uc(uc_handle, UC_Buttons)
	if(buttons & IN_ATTACK)
	{
		g_FireFlamethrower[id] = 1
		
		buttons &= ~IN_ATTACK
		set_uc(uc_handle, UC_Buttons, buttons)
	} else 
	g_FireFlamethrower[id] = 0
	
	return FMRES_HANDLED
}

public fw_PlayerPostThink(id)
{
	if(!is_user_connected(id) || !is_user_alive(id))
		return FMRES_IGNORED
	
	if(!g_hasFlamethrower[id] || !g_Activated[id])
		return FMRES_IGNORED
	
	if(entity_get_int(id, EV_INT_waterlevel) > 1)
		return FMRES_IGNORED
	
	if(has_shield(id))
	{
		return FMRES_IGNORED
	}
	
	if(g_BuyFuel[id])
	{
		if((g_Delay[id] + 0.2) < get_gametime())
		{
			buy_fuel(id)
			g_Delay[id] = get_gametime()
		}
	}
	
	if(g_FireFlamethrower[id])
	{
		if(g_FuelTank[id] > 0)
		{
			if((g_Delay[id] + 0.2) < get_gametime())
			{
				g_FuelTank[id] -= 1
				g_Delay[id] = get_gametime()
			}
			
			new Float:fOrigin[3], Float:fVelocity[3]
			entity_get_vector(id,EV_VEC_origin, fOrigin)
			VelocityByAim(id, 35, fVelocity)
			
			new Float:fTemp[3], iFireOrigin[3]
			xs_vec_add(fOrigin, fVelocity, fTemp)
			FVecIVec(fTemp, iFireOrigin)
			
			new Float:fFireVelocity[3], iFireVelocity[3]
			VelocityByAim(id, get_pcvar_num(cvar_damage_dis), fFireVelocity)
			FVecIVec(fFireVelocity, iFireVelocity)
			
			create_flames_n_sounds(id, iFireOrigin, iFireVelocity)
			
			new doDamage
			switch(get_cvar_num("mp_friendlyfire"))
			{
				case 0: doDamage = 0
					case 1: doDamage = 1
				}
			
			show_fuel_percentage(id)
			direct_damage(id, doDamage)
			indirect_damage(id, doDamage)
			custom_weapon_shot(wpn_ft, id)
		} else
		client_print(id, print_center, "Brak Benzyny")
	}
	return FMRES_IGNORED
}

public think_Flamethrower(ent)
{
	if(is_valid_ent(ent) && entity_get_float(ent, EV_FL_health) < 950.0) 
	{
		new Float:fOrigin[3], iOrigin[3]
		entity_get_vector(ent, EV_VEC_origin, fOrigin)
		FVecIVec(fOrigin, iOrigin)
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(99)
		write_short(ent)
		message_end()
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(3)
		write_coord(iOrigin[0])
		write_coord(iOrigin[1])
		write_coord(iOrigin[2])
		write_short(sprite_xplo)
		write_byte(50)
		write_byte(15)
		write_byte(0)
		message_end()
		
		RadiusDamage(fOrigin, get_pcvar_num(cvar_xplode_dmg), entity_get_int(ent, EV_INT_iuser4))
		remove_entity(ent)
	}
	if(is_valid_ent(ent)) entity_set_float(ent, EV_FL_nextthink, halflife_time() + 0.01)
}

public create_flames_n_sounds(id, origin[3], velocity[3])
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(120)
	write_coord(origin[0])
	write_coord(origin[1])
	write_coord(origin[2])
	write_coord(velocity[0])
	write_coord(velocity[1])
	write_coord(velocity[2] + 5)
	write_short(sprite_fire)
	write_byte(1)
	write_byte(10)
	write_byte(1)
	write_byte(5)
	message_end()
	
	emit_sound(id, CHAN_WEAPON, "flamethrower.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}

public direct_damage(id, doDamage)
{
	new ent, body
	get_user_aiming(id, ent, body, get_pcvar_num(cvar_damage_dis) + 500)
	
	if(ent > 0 && is_user_alive(ent))
	{
		if(!doDamage)
		{
			if(get_user_team(id) != get_user_team(ent)) 
			{
				damage_user(id, ent, get_pcvar_num(cvar_damage))
				custom_weapon_dmg(wpn_ft, id, ent, get_pcvar_num(cvar_damage))
			}
		}
		else
		{
			damage_user(id, ent, get_pcvar_num(cvar_damage))	
			custom_weapon_dmg(wpn_ft, id, ent, get_pcvar_num(cvar_damage))
		}
	}
}

public indirect_damage(id, doDamage)
{
	new Players[32], iNum
	get_players(Players, iNum, "a")
	for(new i = 0; i < iNum; ++i) if(id != Players[i])
{
	new target = Players[i]
	
	new Float:fOrigin[3], Float:fOrigin2[3]
	entity_get_vector(id,EV_VEC_origin, fOrigin)
	entity_get_vector(target, EV_VEC_origin, fOrigin2)
	
	new temp[3], Float:fAim[3]
	get_user_origin(id, temp, 3)
	IVecFVec(temp, fAim)
	
	new Float:fDistance = get_pcvar_num(cvar_damage_dis) + 500.0
	if(get_distance_f(fOrigin, fOrigin2) > fDistance)
		continue 
		
		new iDistance = get_distance_to_line(fOrigin, fOrigin2, fAim)
		if(iDistance > get_pcvar_num(cvar_splash_dis) || iDistance < 0 || !fm_is_ent_visible(id, target))
			continue 
		
		if(!doDamage)
		{
			if(get_user_team(id) != get_user_team(target))
			{
				damage_user(id, target, get_pcvar_num(cvar_damage))
				custom_weapon_dmg(wpn_ft, id, target, get_pcvar_num(cvar_damage))
			}
		}
		else 
		{
			damage_user(id, target, get_pcvar_num(cvar_damage) / 2)
			custom_weapon_dmg(wpn_ft, id, target, get_pcvar_num(cvar_damage) / 2)
		}
	}
}

public buy_fuel(id)
{
	if(get_pcvar_num(cvar_buyzone) && !g_buyzone[id])
		return PLUGIN_CONTINUE
	
	new Float:fBuyTime = get_cvar_float("mp_buytime") * 60
	if(get_pcvar_num(cvar_buytime) && !g_freezetime 
	&& (get_gametime() - g_starttime) > fBuyTime)
	return PLUGIN_CONTINUE
	
	if(g_FuelTank[id] >= get_pcvar_num(cvar_fueltank))
		return PLUGIN_CONTINUE
	
	new iMoney = cs_get_user_money(id)
	new iCost = get_pcvar_num(cvar_fuelcost)
	if(iMoney >= iCost)
	{
		g_FuelTank[id] += 1
		show_fuel_percentage(id)
		cs_set_user_money(id, iMoney - iCost)
		
		return PLUGIN_CONTINUE
	}	
	return PLUGIN_CONTINUE
}

public drop_flamethrower(id)
{
	new Float:fVelocity[3], Float:fOrigin[3]
	entity_get_vector(id, EV_VEC_origin, fOrigin)
	VelocityByAim(id, 34, fVelocity)
	
	fOrigin[0] += fVelocity[0]
	fOrigin[1] += fVelocity[1]
	
	VelocityByAim(id, 300, fVelocity)
	
	new ent = create_entity("info_target")
	if(is_valid_ent(ent))
	{
		entity_set_string(ent, EV_SZ_classname, "flamethrower")
		entity_set_model(ent, "models/w_flamethrower.mdl")
		entity_set_int(ent, EV_INT_movetype, MOVETYPE_TOSS)
		entity_set_int(ent, EV_INT_solid, SOLID_TRIGGER)
		entity_set_vector(ent, EV_VEC_origin, fOrigin)
		entity_set_vector(ent, EV_VEC_velocity, fVelocity)
		entity_set_int(ent, EV_INT_iuser4, g_FuelTank[id])
		entity_set_float(ent, EV_FL_takedamage, 1.0)
		entity_set_float(ent, EV_FL_health, 1000.0)
		entity_set_size(ent, Float:{-2.5, -2.5, -1.5}, Float:{2.5, 2.5, 1.5})
		entity_set_float(ent, EV_FL_nextthink, halflife_time() + 0.01)
	}
	
	g_FuelTank[id] = 0
	g_Activated[id] = 0
	g_hasFlamethrower[id] = 0
	
	if(has_shield(id))
		set_shield_model(id)
	else 
		set_knife_model(id)
	
	return PLUGIN_CONTINUE
}

public task_ActivateFlamethrower(id) 
{
	if(!is_user_connected(id) || !is_user_alive(id))
		return PLUGIN_CONTINUE
	
	new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
	if(weaponID == CSW_KNIFE) g_Activated[id] = 1
	
	return PLUGIN_CONTINUE
}

public show_fuel_percentage(id)
{
	set_hudmessage(255, 170, 0, 0.91, 0.95, _, _, 1.0, _, _, 4)
	show_hudmessage(id, "Benzyna: %d%%", get_percent(g_FuelTank[id], get_pcvar_num(cvar_fueltank)))
}

public set_flamethrower_model(id)
{
	entity_set_string(id, EV_SZ_viewmodel, "models/v_flamethrower.mdl")
	entity_set_string(id, EV_SZ_weaponmodel, "models/p_flamethrower.mdl")
}

public set_knife_model(id)
{
	entity_set_string(id, EV_SZ_viewmodel, "models/v_knife.mdl")
	entity_set_string(id, EV_SZ_weaponmodel, "models/p_knife.mdl")	
}

public set_shield_model(id)
{
	entity_set_string(id, EV_SZ_viewmodel, "models/shield/v_shield_knife.mdl")
	entity_set_string(id, EV_SZ_weaponmodel, "models/shield/p_shield_knife.mdl")
}

stock damage_user(id, victim, damage)
{
	new iHealth = get_user_health(victim)
	if(iHealth > damage) 
		fakedamage(victim, "weapon_flamethrower", float(damage), DMG_BURN)
	else
	{
		new iXp = get_pcvar_num(cvar_expcod);
		set_hudmessage(255, 212, 0, -1.0, 0.30, 0, 2.0, 2.0, 0.05, 0.05, 4)
		show_hudmessage(0, "+ %d", iXp);
		cod_set_user_xp(id,cod_get_user_xp(id) + iXp)
		
		user_silentkill(victim)
		make_deathmsg(id, victim, 0, "flamethrower")
		
		new iOrigin[3]
		get_user_origin(victim, iOrigin, 0)
		
		message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
		write_byte(17)
		write_coord(iOrigin[0])
		write_coord(iOrigin[1])
		write_coord(iOrigin[2] + 10)
		write_short(sprite_burn)
		write_byte(30)
		write_byte(40)
		message_end()
		
		if(get_user_team(id) != get_user_team(victim))
		{
			set_user_frags(id, get_user_frags(id) + 1)
			cs_set_user_money(id, cs_get_user_money(id) + 300)
		}
		else
		{
			set_user_frags(id, get_user_frags(id) - 1)
			cs_set_user_money(id, cs_get_user_money(id) - 300)
		}
		
		message_begin(MSG_ALL, get_user_msgid("ScoreInfo")) 
		write_byte(id) 
		write_short(get_user_frags(id)) 
		write_short(get_user_deaths(id)) 
		write_short(0) 
		write_short(get_user_team(id)) 
		message_end() 
		
		message_begin(MSG_ALL, get_user_msgid("ScoreInfo")) 
		write_byte(victim) 
		write_short(get_user_frags(victim))
		write_short(get_user_deaths(victim))
		write_short(0)
		write_short(get_user_team(victim))
		message_end()
	}
}

stock get_percent(value, tvalue) {       
	return floatround(floatmul(float(value) / float(tvalue) , 100.0))  
}

stock get_distance_to_line(Float:pos_start[3], Float:pos_end[3], Float:pos_object[3])  
{  
	new Float:vec_start_end[3], Float:vec_start_object[3], Float:vec_end_object[3], Float:vec_end_start[3]
	xs_vec_sub(pos_end, pos_start, vec_start_end) 		// vector from start to end 
	xs_vec_sub(pos_object, pos_start, vec_start_object) 	// vector from end to object 
	xs_vec_sub(pos_start, pos_end, vec_end_start) 		// vector from end to start 
	xs_vec_sub(pos_end, pos_object, vec_end_object) 		// vector object to end 
	
	new Float:len_start_object = getVecLen(vec_start_object) 
	new Float:angle_start = floatacos(xs_vec_dot(vec_start_end, vec_start_object) / (getVecLen(vec_start_end) * len_start_object), degrees)  
	new Float:angle_end = floatacos(xs_vec_dot(vec_end_start, vec_end_object) / (getVecLen(vec_end_start) * getVecLen(vec_end_object)), degrees)  
	
	if(angle_start <= 90.0 && angle_end <= 90.0) 
		return floatround(len_start_object * floatsin(angle_start, degrees)) 
	return -1  
}

stock Float:getVecLen(Float:Vec[3])
{ 
	new Float:VecNull[3] = {0.0, 0.0, 0.0}
	new Float:len = get_distance_f(Vec, VecNull)
	return len
}

stock bool:fm_is_ent_visible(index, entity) 
{
	new Float:origin[3], Float:view_ofs[3], Float:eyespos[3]
	pev(index, pev_origin, origin)
	pev(index, pev_view_ofs, view_ofs)
	xs_vec_add(origin, view_ofs, eyespos)
	
	new Float:entpos[3]
	pev(entity, pev_origin, entpos)
	engfunc(EngFunc_TraceLine, eyespos, entpos, 0, index)
	
	switch(pev(entity, pev_solid)) {
		case SOLID_BBOX..SOLID_BSP: return global_get(glb_trace_ent) == entity
		}
	
	new Float:fraction
	global_get(glb_trace_fraction, fraction)
	if(fraction == 1.0)
		return true
	
	return false
}

stock bool:has_shield(id)
{
	new modelName[32]
	entity_get_string(id, EV_SZ_viewmodel, modelName, 31)
	
	if(containi(modelName, "v_shield_") != -1)
		return true
	
	return false
}

public cod_class_enabled(id){       
        ColorChat(id, RED, "^x04Klasa^x03 %s^x04 By^x01 Sajjuk", nazwa); //Gdy gracz nie ma flagi wyświetli mu komunikat
        if(!(get_user_flags(id) & ADMIN_LEVEL_G)) //FLAGA
        {
                ColorChat(id, RED, "^x03[%s]^x04 Jest^x03 klasa premium", nazwa) //Znowu info ze przykładowa klasa jest PREMIUM 
                return COD_STOP;
        }
        ma_klase[id] = true;
	
	g_hasFlamethrower[id] = 1
	g_FuelTank[id] = get_pcvar_num(cvar_fueltank)
	
	new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
	if(weaponID == CSW_KNIFE) 
	{
		g_Activated[id] = true
		set_flamethrower_model(id)
	}
	
	client_cmd(id, "spk items/ammopickup2")
	client_print(id, print_chat, "Masz miotacz ognia nacisnij 3 aby uzyc")
	return COD_CONTINUE;
}

public cod_class_disabled(id){
	ma_klase[id] = false;
	g_hasFlamethrower[id] = 0
}

public Spawn(id)
{
	if(is_user_connected(id) && ma_klase[id])
	{
		g_hasFlamethrower[id] = 1
		g_FuelTank[id] = get_pcvar_num(cvar_fueltank)
		
		new temp[2], weaponID = get_user_weapon(id, temp[0], temp[1])
		if(weaponID == CSW_KNIFE) 
		{
			g_Activated[id] = true
			set_flamethrower_model(id)
		}
		
		client_cmd(id, "spk items/ammopickup2")
		client_print(id, print_chat, "Masz miotacz ognia nacisnij 3 aby uzyc")
	}
	
	return PLUGIN_CONTINUE;
	
}
