#include <amxmodx>
#include <codmod>
#include <fakemeta>
#include <fun>
#include <cstrike>
#include <hamsandwich>

#define DMG_HEGRENADE (1<<24)

new const nazwa[]   = "Gogus [MegaP]";
new const opis[]    = "Brak rozrzutu, 1/1 z HE";
new const bronie    = 1<<CSW_M4A1 | 1<<CSW_AK47 | 1<<CSW_HEGRENADE;
new const zdrowie   = 12;
new const kondycja  = 5;
new const inteligencja = 9;
new const wytrzymalosc = 2;


new bool: ma_klase[33];

public plugin_init()
{	
	register_plugin(nazwa, "1.0", "Play");
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);    
	register_forward(FM_PlayerPreThink, "PreThink");
	register_forward(FM_UpdateClientData, "UpdateClientData", 1)
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
	
}
public cod_class_enabled(id)
{
	if(!(get_user_flags(id) & ADMIN_LEVEL_G))
	{
		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)
{
	ma_klase[id] = false;
}

public PreThink(id)
{
	if(ma_klase[id])
		set_pev(id, pev_punchangle, {0.0,0.0,0.0})
}

public UpdateClientData(id, sw, cd_handle)
{
	if(ma_klase[id])
		set_cd(cd_handle, CD_PunchAngle, {0.0,0.0,0.0})   
}
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, 1) == 1)
	{	
		cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
	}
	return HAM_IGNORED;

}

