#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <halomod>

#define PLUGIN "HaloMod Weapon Models"
#define VERSION HALOVERSION
#define AUTHOR "Soccdoodcss"

#define WEAPONS 6
#define PWEAPONS 2

new const gVWeapModel[WEAPONS][] = {
	"models/v_famas_halo.mdl",
	"models/v_p90_halo.mdl",
	"models/v_deagle_halo.mdl",
	"models/v_m3_halo.mdl",
	"models/v_knife_halo.mdl",
	"models/v_hegrenade_halo.mdl"
}

new const gWWeapModel[WEAPONS][] = {
	"models/w_famas_halo.mdl",
	"models/w_p90_halo.mdl",
	"models/w_deagle_halo.mdl",
	"models/w_m3_halo.mdl",
	"models/w_knife_halo.mdl",
	"models/w_hegrenade_halo.mdl"
}

new const gPWeapModel[PWEAPONS][] = {
	"models/p_p90_halo.mdl",
	"models/p_hegrenade_halo.mdl"
}

new const gOVWeapModel[WEAPONS][] = {
	"models/v_famas.mdl",
	"models/v_p90.mdl",
	"models/v_deagle.mdl",
	"models/v_m3.mdl",
	"models/v_knife.mdl",
	"models/v_hegrenade.mdl"
}

new const gOWWeapModel[WEAPONS][] = {
	"models/w_famas.mdl",
	"models/w_p90.mdl",
	"models/w_deagle.mdl",
	"models/w_m3.mdl",
	"models/w_knife.mdl",
	"models/w_hegrenade.mdl"
}

new const gOPWeapModel[PWEAPONS][] = {
	"models/p_p90.mdl",
	"models/p_hegrenade.mdl"
}

public plugin_precache()
{
	new model[33]
	for(new x = 0; x < (WEAPONS*2); x++)
	{
		if(x<WEAPONS)
			format(model, 32, gVWeapModel[x])
		else
			format(model, 32, gWWeapModel[x-WEAPONS])
		
		
		precache_model(model)
	}
	
	for(new x = 0; x < PWEAPONS; x++)
		precache_model(gPWeapModel[x])
}

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon","onChangeWeapon","be","1=1")
	
	register_forward(FM_SetModel,"onSetModel",1)
}

public onChangeWeapon(id)
{
	if(!is_user_alive(id) || !is_halo_on())
		return PLUGIN_HANDLED
	
	new model[32]
	pev(id,pev_viewmodel2,model,31)
	
	new pmodel[32]
	pev(id,pev_weaponmodel2,pmodel,31)
	
	for(new x = 0 ; x < WEAPONS; x++)
	{
		if(equali(model,gOVWeapModel[x]))
			set_pev(id, pev_viewmodel2, gVWeapModel[x])
	}
	
	for(new x = 0 ; x < PWEAPONS; x++)
	{
		if(equali(pmodel,gOPWeapModel[x]))
			set_pev(id, pev_weaponmodel2, gPWeapModel[x])
		
	}
	
	return PLUGIN_HANDLED
}

public onSetModel(ent,model[])
{
	if(!pev_valid(ent) || !is_halo_on())
		return FMRES_HANDLED
	
	for(new x = 0;x < WEAPONS ; x++)
	{
		if(equali(model,gOWWeapModel[x]))
		{
			engfunc(EngFunc_SetModel,ent,gWWeapModel[x])
			return FMRES_SUPERCEDE
		}
	}
	return FMRES_HANDLED
}
