#include <amxmodx>
#include <codmod>
#include <fakemeta>
#include <engine>
#include <hamsandwich>

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


new const nazwa[] = "Jessi [P]";
new const opis[] = "1/1 AWP | 50% niewidzialnosci podczas kucania | 1/3 z HE";
new const bronie = 1<<CSW_HEGRENADE | 1<<CSW_AWP | 1<<CSW_FAMAS
new const zdrowie = 0;
new const kondycja = 0;
new const inteligencja = 0;
new const wytrzymalosc = 0;

new bool:ma_klase[33];


public plugin_init()
{

	register_plugin(nazwa, "1.0", "Play");	
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
	register_forward(FM_PlayerPreThink, "fwPrethink_Niewidzialnosc", 1);

}
public cod_class_enabled(id)
{
	if(!(get_user_flags(id) & ADMIN_LEVEL_C))
	{
		client_print(id, print_center, "[%s], Nie masz uprawnien, aby uzywac tej klasy.", nazwa);
		return COD_STOP;
	}
	ma_klase[id] = true;
	return PLUGIN_CONTINUE;
}

public cod_class_disabled(id)
{
	set_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 255);
	ma_klase[id] = false;
}
public fwPrethink_Niewidzialnosc(id)
{
	if(!ma_klase[id])
		return;

	new button = get_user_button(id);
	if( button & IN_DUCK )
	{
		set_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 138);
	}
	else
	{
		set_rendering(id,kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 255);
	}
}
public TakeDamage(this, idinflictor, idattacker, Float:damage, damagebits)
{
	if(!is_user_connected(idattacker))
		return HAM_IGNORED;
        
	if(!ma_klase[idattacker])
		return HAM_IGNORED;
		
	if(damagebits & DMG_HEGRENADE && random_num(1, 3) == 1)
	{	
		cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
	}		
						
	if(get_user_team(this) != get_user_team(idattacker) && get_user_weapon(idattacker) == CSW_AWP && damagebits & DMG_BULLET)
		cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);	

	return HAM_IGNORED;
}
