/* Plugin generated by AMXX-Studio */

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

#define DMG_BULLET (1<<1)

#define SLASH 0
#define STAB 1

new gKnifeattack[ 33 ];
new bool: ma_klase[33];

new const nazwa[] = "Komandoska";
new const opis[] = "1/1 z noza (PPM)";
new const bronie = 1<<CSW_DEAGLE;
new const zdrowie = 40;
new const kondycja = 60;
new const inteligencja = 5;
new const wytrzymalosc = 0;


public plugin_init() 
{
	register_plugin(nazwa, "1.0", "Play");
	
	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
	
	RegisterHam( Ham_Weapon_PrimaryAttack, "weapon_knife", "ham_AttackSlash");
	RegisterHam( Ham_Weapon_SecondaryAttack, "weapon_knife", "ham_AttackStab");
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
}

public cod_class_enabled(id)
	ma_klase[id] = true;
	
public cod_class_disabled(id)
	ma_klase[id] = false;

public ham_AttackStab( entity )
{
	gKnifeattack[ pev( entity, pev_owner ) ] = STAB;
	return HAM_IGNORED;
}

public ham_AttackSlash( entity )
{
	gKnifeattack[ pev( entity, pev_owner ) ] = SLASH;
	return HAM_IGNORED; 
}

public TakeDamage(this, idinflictor, idattacker, Float:damage, damagebits)
{
	if(!is_user_connected(idattacker))
		return HAM_IGNORED;

	if(!ma_klase[idattacker])
		return HAM_IGNORED;

	if( get_user_weapon( idattacker ) == CSW_KNIFE && ( damagebits & ( DMG_NEVERGIB | DMG_BULLET ) ) )
	{
		if( gKnifeattack[ idattacker ] == STAB )
		{
			cs_set_user_armor( this, 0, CS_ARMOR_NONE )
			cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
		}
	}
	
	return HAM_IGNORED;
}