/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <codmod>
#include <ColorChat>
#include <fun>
#include <engine>
#include <fakemeta>
#include <hamsandwich>


#define DMG_BULLET (1<<1)


#define CZAS_GODMOD 1

new const nazwa[] = "Wyszkolony Kapral";
new const opis[] = "Ma 1 sekunde niesmiertelnosci. Zlote AK47 ,z niej + 5 Dmg ";
new const bronie    = (1<<CSW_DEAGLE)|(1<<CSW_AK47);
new const zdrowie = 0;
new const kondycja = 10;
new const inteligencja = 0;
new const wytrzymalosc = 0;

new bool:wykorzystal[33];
new bool:ma_klase[33];
new msg_bartime;

public plugin_init() {

register_plugin(nazwa, "1.0", "QTM_Peyote");
msg_bartime = get_user_msgid("BarTime");
register_event("ResetHUD", "ResetHUD", "abe");
register_event("CurWeapon", "CurWeapon", "be", "1=1")
register_forward(FM_SetModel, "fw_SetModel");
RegisterHam(Ham_TakeDamage, "player", "TakeDamage");


cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
}

public cod_class_enabled(id)
{
         ma_klase[id] = true;
         ResetHUD(id);
}

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

public cod_class_skill_used(id)
{
         if(!is_user_alive(id))
           return;
        
         if(wykorzystal[id])
         {
           ColorChat(id, GREEN, "[Wyszkolony Kapral] ^x01 Wykorzystales juz swoja niesmiertelnosc.");
           return;
         }
  
         wykorzystal[id] = true;
  
         set_user_godmode(id, 1);
         set_user_rendering(id, kRenderFxGlowShell, 255, 0, 0);
         set_task(CZAS_GODMOD.0, "WylaczGod", id);
  
         message_begin(MSG_ONE, msg_bartime, _, id)
         write_short(CZAS_GODMOD)
         message_end()
}

public WylaczGod(id)
{
         if(!is_user_connected(id)) return;
  
         set_user_godmode(id, 0);
         set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0);
}

public ResetHUD(id)
         wykorzystal[id] = false;


public plugin_precache()
{
        precache_model("models/cod/p_golden_ak47.mdl");
        precache_model("models/cod/v_golden_ak47.mdl");
}

public CurWeapon(id)
{
        new weapon = read_data(2);

        if(ma_klase[id])
        {
                if(weapon == CSW_AK47)
                {
                        set_pev(id, pev_viewmodel2, "models/cod/v_golden_ak47.mdl")
                        set_pev(id, pev_weaponmodel2, "models/cod/p_golden_ak47.mdl")
                }
        }
}

public fw_SetModel(entity, model[])
{
        if(!pev_valid(entity)) 
                return FMRES_IGNORED

        if(!equali(model, "models/w_ak47.mdl"))
                return FMRES_IGNORED;

        new entityowner = pev(entity, pev_owner);
        
        if(!ma_klase[entityowner])
                return FMRES_IGNORED;

        engfunc(EngFunc_SetModel, entity, "models/w_ak47.mdl")
        return FMRES_SUPERCEDE
}

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_AK47 && damagebits & DMG_BULLET)
		cod_inflict_damage(idattacker, this, 5.0, 0.0, idinflictor, damagebits);
		
	return HAM_IGNORED;
}
