#include <amxmodx>
#include <engine>
#include <hamsandwich>

/* ------------------------------------------ */
#define PLUGIN "[JB] DMG + Gold Bronie"
#define VERSION "v2.0"
#define AUTHOR "Skull"
/* ----------------------------------------- */

#define FLAGA_USERA ADMIN_LEVEL_B	/* TUTAJ ZMIENIAMY FLAGÊ DOSTÊPU */

new Wybor_Broni,
	Wybor_DMG_ALL,
	Wybor_DMG_Deagle,
	Wybor_DMG_AK47,
	Wybor_DMG_M4A1;

/* -------------------------------------------------------------------------------------- */
new const v_Bron_Deagle[] = "models/jb_DMG_Gold/v_deagle_v1.mdl";	/*  Tutaj zmieniamy sciezki do modeli */
new const v_Bron_AK[] = "models/jb_DMG_Gold/v_ak47_v4.mdl";	/*  Tutaj zmieniamy sciezki do modeli */
new const v_Bron_M4[] = "models/jb_DMG_Gold/v_m4a1_v1.mdl";	/*  Tutaj zmieniamy sciezki do modeli */

new const p_Bron_Deagle[] = "models/jb_DMG_Gold/p_deagle_v1.mdl";	/*  Tutaj zmieniamy sciezki do modeli */
new const p_Bron_AK[] = "models/jb_DMG_Gold/p_ak47_v4.mdl";	/* Tutaj zmieniamy sciezki do modeli */
new const p_Bron_M4[] = "models/jb_DMG_Gold/p_m4a1_v1.mdl";	/* Tutaj zmieniamy sciezki do modeli */
/* ------------------------------------------------------------------------------------- */

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR);

	Wybor_Broni = register_cvar("jb_wybor_broni", "0", FCVAR_SERVER);		/* Wybor Broni 0 - Deagle, AK47, M4a1 / 1 - Deagle / 2 - AK47 / 3 - M4a1 */
	Wybor_DMG_ALL = register_cvar("jb_ustawienia_obrazen_all", "1.5");		/* Ustawiasz obrazenia dla broni 1.0 - to normalne obrazenia, np. 1.5 - obrazenia wieksze o 50% a 2.0 - obrazenia wieksze o 100% */
	Wybor_DMG_Deagle = register_cvar("jb_ustawienia_obrazen_deagle", "1.5");	/* Ustawiasz obrazenia dla broni 1.0 - to normalne obrazenia, np. 1.5 - obrazenia wieksze o 50% a 2.0 - obrazenia wieksze o 100% */
	Wybor_DMG_AK47 = register_cvar("jb_ustawienia_obrazen_ak47", "1.5");		/* Ustawiasz obrazenia dla broni 1.0 - to normalne obrazenia, np. 1.5 - obrazenia wieksze o 50% a 2.0 - obrazenia wieksze o 100% */
	Wybor_DMG_M4A1 = register_cvar("jb_ustawienia_obrazen_m4a1", "1.5");		/* Ustawiasz obrazenia dla broni 1.0 - to normalne obrazenia, np. 1.5 - obrazenia wieksze o 50% a 2.0 - obrazenia wieksze o 100% */

	register_event("CurWeapon", "Event_CurWeapon", "be","1=1");
	RegisterHam(Ham_TakeDamage, "player", "TakeDamage");
}

public plugin_precache()
{
	precache_model(v_Bron_Deagle);
	precache_model(v_Bron_AK);
	precache_model(v_Bron_M4);

	precache_model(p_Bron_Deagle);
	precache_model(p_Bron_AK);
	precache_model(p_Bron_M4);
}

public Event_CurWeapon(id)
{
	new v_Wybor_Broni = get_pcvar_num(Wybor_Broni);

	if(get_user_flags(id) & FLAGA_USERA && get_user_team(id) == 2)
	{
		switch(v_Wybor_Broni)
		{
			case 0:
			{
				if(get_user_weapon(id) == CSW_DEAGLE)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_Deagle)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_Deagle)
				}
				if(get_user_weapon(id) == CSW_AK47)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_AK)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_AK)
				}
				if(get_user_weapon(id) == CSW_M4A1)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_M4)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_M4)
				}
			}
			case 1:
			{
				if(get_user_weapon(id) == CSW_DEAGLE)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_Deagle)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_Deagle)
				}
			}
			case 2:
			{
				if(get_user_weapon(id) == CSW_AK47)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_AK)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_AK)
				}
			}
			case 3:
			{
				if(get_user_weapon(id) == CSW_M4A1)
				{
					entity_set_string(id, EV_SZ_viewmodel, v_Bron_M4)
					entity_set_string(id, EV_SZ_weaponmodel, p_Bron_M4)
				}
			}
		}
	}
	return PLUGIN_CONTINUE;
}

public TakeDamage(victim, entity, attacker, Float:damage, damagebits)
{
	new v_Wybor_Broni = get_pcvar_num(Wybor_Broni);

	if(!is_user_connected(attacker) || !is_user_connected(victim))
		return HAM_IGNORED;

	switch(v_Wybor_Broni)
	{
		case 0:
		{
			if(get_user_flags(attacker) & FLAGA_USERA && get_user_team(attacker) == 2 && get_user_weapon(attacker) == CSW_DEAGLE || get_user_weapon(attacker) == CSW_AK47 || get_user_weapon(attacker) == CSW_M4A1)
			{
				if(get_pcvar_float(Wybor_DMG_ALL))
				{
					SetHamParamFloat(4, damage * get_pcvar_float(Wybor_DMG_ALL));
					return HAM_HANDLED;
				}
			}
		}
		case 1:
		{
			if(get_user_flags(attacker) & FLAGA_USERA && get_user_team(attacker) == 2 && get_user_weapon(attacker) == CSW_DEAGLE)
			{
				if(get_pcvar_float(Wybor_DMG_Deagle))
				{
					SetHamParamFloat(4, damage * get_pcvar_float(Wybor_DMG_Deagle));
					return HAM_HANDLED;
				}
			}
		}
		case 2:
		{
			if(get_user_flags(attacker) & FLAGA_USERA && get_user_team(attacker) == 2 && get_user_weapon(attacker) == CSW_AK47)
			{
				if(get_pcvar_float(Wybor_DMG_AK47))
				{
					SetHamParamFloat(4, damage * get_pcvar_float(Wybor_DMG_AK47));
					return HAM_HANDLED;
				}
			}
		}
		case 3:
		{
			if(get_user_flags(attacker) & FLAGA_USERA && get_user_team(attacker) == 2 && get_user_weapon(attacker) == CSW_AK47)
			{
				if(get_pcvar_float(Wybor_DMG_M4A1))
				{
					SetHamParamFloat(4, damage * get_pcvar_float(Wybor_DMG_M4A1));
					return HAM_HANDLED;
				}
			}
		}
	}
	return HAM_IGNORED;
}