I'll just suggest untested method, because I haven't got time to test it, but decided to share it. Any modifications will be done later, I just want to show the idea. You may use an enum and a const to loop and register the weapons by their "weapon_" name, then to set the model for each weapon by the const and a loop.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "x"
enum _:WeaponParts
{
_wname[32],
_vmodel[32],
_pmodel[32]
}
new const WeaponsToLoop[][WeaponParts]=
{
{"weapon_knife", KNIFE_VIEW, KNIFE_PLAYER},
{"weapon_c4", C4_VIEW, C4_PLAYER},
{"weapon_hegrenade", HE_VIEW, HE_PLAYER},
{"weapon_smokegrenade", SE_VIEW, SE_PLAYER},
{"weapon_flashbang", FL_VIEW, FL_PLAYER}
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
for(new i = 0; i < sizeof(WeaponsToLoop) - 1; i++)
{
RegisterHam(Ham_Item_Deploy, WeaponsToLoop[i][_wname], "fwReplaceModels", 0)
}
}
public fwReplaceModels(ent)
{
new id = get_pdata_cbase( ent, 41, 4 )
set_task(0.1, "chat", id)
}
public chat(id)
{
new weapon,clip,ammo,item
weapon = get_user_weapon(id, clip, ammo)
switch(weapon)
{
case CSW_KNIFE: item = 0
case CSW_C4: item = 1
case CSW_HEGRENADE: item = 2
case CSW_FLASHBANG: item = 3
case CSW_SMOKEGRENADE: item = 4
}
entity_set_string(id, EV_SZ_viewmodel, WeaponsToLoop[item][_vmodel])
entity_set_string(id, EV_SZ_weaponmodel, WeaponsToLoop[item][_pmodel])
}
EDIT: The code is edited to the optimal way. So, look. In Ham_Item_Deploy, get_user_weapon is called before the change and actually in the moment of change it takes the index of the previous weapon. So, I made it with task, which to take the weapon index 0.1 sec after the change. Here you go, this worked on a test with a chat command, so it should work with this function, too.
__________________