/* Plugin generated by AMXX-Studio */

#include amxmodx
#include amxmisc
#include zombieplague
#include fakemeta
#include hamsandwich

#define PLUGIN "[ZP]Tomahawk"
#define VERSION "0.1"
#define AUTHOR "Barney/Rayman"

new const tomahawk_model[][] = {"models/v_tomahawk.mdl","models/p_tomahawk.mdl"}

new const knife_sounds[][] =
{
	"weapons/tomahawk_draw.wav",
	"weapons/tomahawk_slash1_hit.wav",
	"weapons/tomahawk_slash2_hit.wav",
	"weapons/tomahawk_stab_hit.wav",
	"weapons/tomahawk_stab_hit.wav",
	"weapons/tomahawk_wall.wav",
	"weapons/tomahawk_slash1.wav",
	"weapons/tomahawk_slash2.wav",
	"weapons/tomahawk_stab_miss.wav"
}

new const oldknife_sounds[][] =
{
	"weapons/knife_deploy1.wav",
	"weapons/knife_hit1.wav",
	"weapons/knife_hit2.wav",
	"weapons/knife_hit3.wav",
	"weapons/knife_hit4.wav",
	"weapons/knife_hitwall1.wav",
	"weapons/knife_slash1.wav",
	"weapons/knife_slash2.wav",
	"weapons/knife_stab.wav"
}


new g_knife,bool:g_tomahawk[33]

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	g_knife = zp_register_extra_item("Tomahawk knife",10,ZP_TEAM_HUMAN)
	register_event("CurWeapon","ev_curweapon","be","1=1")
	register_forward(FM_EmitSound, "fw_EmitSound")
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
	RegisterHam(Ham_Spawn,"player","spawn_post",1)
	
}

public plugin_precache(){
	for(new i = 0; i < sizeof tomahawk_model; i++)
		precache_model(tomahawk_model[i])
	for(new i = 0; i < sizeof knife_sounds; i++)
		precache_sound(knife_sounds[i])
}

public fw_EmitSound(id, channel, const sound[])
{
	if(is_user_alive(id) && is_user_connected(id) && g_tomahawk[id]){
	for(new i = 0; i < sizeof knife_sounds; i++)
	{
		if(equal(sound, oldknife_sounds[i]))
		{
			emit_sound(id, channel, knife_sounds[i], 1.0, ATTN_NORM, 0, PITCH_NORM)
			return FMRES_SUPERCEDE
		}
	}
	}
			
	return FMRES_IGNORED
}

public zp_extra_item_selected(chelovek,itemid){
	if(itemid == g_knife){
	if(get_user_weapon(chelovek) == CSW_KNIFE){
	set_pev(chelovek,pev_viewmodel2,tomahawk_model[0])
	set_pev(chelovek,pev_weaponmodel2,tomahawk_model[1])
	}
	g_tomahawk[chelovek]=true
	}
}
public ev_curweapon(chelovek){
	if(read_data(2) == CSW_KNIFE && g_tomahawk[chelovek]){
	if(is_user_alive(chelovek) && !zp_get_user_zombie(chelovek) && !zp_get_user_nemesis(chelovek) && !zp_get_user_survivor(chelovek)){
	set_pev(chelovek,pev_viewmodel2,tomahawk_model[0])
	set_pev(chelovek,pev_weaponmodel2,tomahawk_model[1])
	}
	}
}

public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
	if (victim != attacker && is_user_connected(attacker))
	{
		if(get_user_weapon(attacker) == CSW_KNIFE)
		{
			if(g_tomahawk[attacker])
				SetHamParamFloat(4, damage * 4.0)
		}
	}
}

public spawn_post(chelovek){
	g_tomahawk[chelovek] = false
}
