#include <amxmodx>
#include <amxmisc>
#include <codmod>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <colorchat>
        
#define DMG_BULLET (1<<1)

new DEAGLE_MODEL[ 64 ] = "models/v_deagle_new.mdl"

new const nazwa[]   = "Zawodowy Deagler [VIP]";
new const opis[]    = "Dostaje Deagle z Zoom'em 1/5 z DEAGLE, posiada lekka grawitacje, Podwojny skok.";
new const bronie    = (1<<CSW_DEAGLE);
new const zdrowie   = 10;
new const kondycja  = 20;
new const inteligencja = 10;
new const wytrzymalosc = 10;
    
new skoki[33];
new bool:ma_klase[33];
new g_hasZoom[33];
new szClip, szAmmo

public plugin_init()
{
	register_plugin(nazwa, "1.0", "amxx.pl");

	cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);   
	RegisterHam(Ham_Spawn, "player", "fwSpawn_Grawitacja", 1);
	register_event( "CurWeapon", "event_cur_weapon", "be", "1=1" )

   
	register_forward(FM_CmdStart, "fwCmdStart_MultiJump");
	register_forward( FM_CmdStart, "forward_cmdstart" )
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
}

public plugin_precache()
{
	precache_model( DEAGLE_MODEL )
}

public cod_class_enabled(id)
{
	if(!(get_user_flags(id) & ADMIN_LEVEL_H))
	{
		ColorChat(id, GREEN, "[Forum] ^x01 Nie masz uprawnien do uzywania klasy ^x04Zawodowy Deagler");
		ColorChat(id, GREEN, "[Forum] ^x01 Jezeli chcesz miec dostep do klasy ^x04Zawodowy Deagler^x01 i kilku innych, zakup konto VIP");
	}

 	entity_set_float(id, EV_FL_gravity, 550.0/800.0);
	ma_klase[id] = true;
   
	return COD_CONTINUE;
}

public cod_class_disabled(id)
{

 	entity_set_float(id, EV_FL_gravity, 1.0);
	ma_klase[id] = false;

}

public fwSpawn_Grawitacja(id)
{
	if(ma_klase[id])
		entity_set_float(id, EV_FL_gravity, 550.0/800.0);
}


public fwCmdStart_MultiJump(id, uc_handle)
{
	if(!is_user_alive(id) || !ma_klase[id])
		return FMRES_IGNORED;

	new flags = pev(id, pev_flags);

	if((get_uc(uc_handle, UC_Buttons) & IN_JUMP) && !(flags & FL_ONGROUND) && !(pev(id, pev_oldbuttons) & IN_JUMP) && skoki[id])
	{
		skoki[id]--;
		new Float:velocity[3];
		pev(id, pev_velocity,velocity);
		velocity[2] = random_float(265.0,285.0);
		set_pev(id, pev_velocity,velocity);
	}
	else if(flags & FL_ONGROUND)
		skoki[id] = 1;

	return FMRES_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(!(damagebits & DMG_BULLET))
                return HAM_IGNORED;
                
        if(get_user_weapon(idattacker) == CSW_DEAGLE && random_num(1,5) == 1)
                cod_inflict_damage(idattacker, this, float(get_user_health(this))-damage+1.0, 0.0, idinflictor, damagebits);
        
        return HAM_IGNORED;
}

public forward_cmdstart( id, uc_handle, seed )
{
	new szWeapID = get_user_weapon( id, szClip, szAmmo )
	if( !is_user_alive( id ) ) 
		return PLUGIN_HANDLED
	
	if(!ma_klase[id])
		return PLUGIN_HANDLED

	if( ( get_uc( uc_handle, UC_Buttons ) & IN_ATTACK2 ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK2 ) )
	{
		if( szWeapID == CSW_DEAGLE && !g_hasZoom[ id ] )
		{
			g_hasZoom[ id ] = true
			cs_set_user_zoom( id, CS_SET_FIRST_ZOOM, 1 )
			emit_sound( id, CHAN_ITEM, "weapons/zoom.wav", 0.20, 2.40, 0, 100 )
		}

		else 
		{	if( g_hasZoom[ id ] )
			{
				g_hasZoom[ id ] = false
				cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
			}
		}

		return PLUGIN_HANDLED
	}
	
	if((get_uc(uc_handle, UC_Buttons) & IN_RELOAD) && !(pev(id, pev_oldbuttons) & IN_RELOAD))
	{
		if(szWeapID == CSW_DEAGLE && g_hasZoom[id])
		{
			g_hasZoom[id] = false
			cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
		}
	}

	return PLUGIN_HANDLED
}

public event_cur_weapon( id )
{
	new szWeapID = get_user_weapon( id, szClip, szAmmo )

	if ( szWeapID == CSW_DEAGLE && ma_klase[id])
	{
		set_pev( id, pev_viewmodel2, DEAGLE_MODEL )
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/
