Note if this example is in your plugin: If its 80%> of your whole script, I suggest you dont post it as a plugin.
This is a small example on changing weapon models for Counter-Strike. With this example you can change all 3 types of the model: view, player, and world. I have written one with Engine and Fakemeta for people who are not familiar with Fakemeta yet, and one only on fakemeta for L33T coders.
I hope this helps, so people dont need to keep posting about this ;).
Engine and Fakemeta
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
new VIEW_MODEL[] = "models/v_<model name>.mdl"
new PLAYER_MODEL[] = "models/p_<model name>.mdl"
new WORLD_MODEL[] = "models/w_<model name>.mdl"
new OLDWORLD_MODEL[] = "models/w_<model name>.mdl" // the world model you want replaced
new PLUGIN_NAME[] = "Custom Weapon Model"
new PLUGIN_AUTHOR[] = "Cheap_Suit"
new PLUGIN_VERSION[] = "1.0"
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_event("CurWeapon", "Event_CurWeapon", "be","1=1")
register_forward(FM_SetModel, "fw_SetModel")
}
public plugin_precache()
{
precache_model(VIEW_MODEL)
precache_model(PLAYER_MODEL)
precache_model(WORLD_MODEL)
}
public Event_CurWeapon(id)
{
// might not work for other mods
new weaponID = read_data(2)
// eg, if weapon is not ak then continue
if(weaponID != CSW_AK47)
return PLUGIN_CONTINUE
// this set's the view model (what you see when holding the gun)
entity_set_string(id, EV_SZ_viewmodel, VIEW_MODEL)
// this set's the player model (what you see when people holding the gun)
entity_set_string(id, EV_SZ_weaponmodel, PLAYER_MODEL)
return PLUGIN_CONTINUE
}
public fw_SetModel(entity, model[])
{
// check if its a valid entity or else we'll get errors
if(!is_valid_ent(entity))
return FMRES_IGNORED
// checks if it's the model we want to change
if(!equali(model, OLDWORLD_MODEL))
return FMRES_IGNORED
new className[33]
entity_get_string(entity, EV_SZ_classname, className, 32)
// dropped weapons map weapons c4 + grenades
if(equal(className, "weaponbox") || equal(className, "armoury_entity") || equal(className, "grenade"))
{
// set's the world model (what you see on the ground)
entity_set_model(entity, WORLD_MODEL)
return FMRES_SUPERCEDE
}
return FMRES_IGNORED
}
Code:
public Event_CurWeapon(id)
{
// might not work for other mods
new weaponID = read_data(2)
// eg, if weapon is not ak then continue
if(weaponID != CSW_AK47)
return PLUGIN_CONTINUE
// this set's the view model (what you see when holding the gun)
set_pev(id, pev_viewmodel, engfunc(EngFunc_AllocString, VIEW_MODEL))
// this set's the player model (what you see when people holding the gun)
set_pev(id, pev_weaponmodel, engfunc(EngFunc_AllocString, PLAYER_MODEL))
return PLUGIN_CONTINUE
}
public fw_SetModel(entity, model[])
{
// check if its a valid entity or else we get errors
if(!pev_valid(entity))
return FMRES_IGNORED
// checks if its the model we want to change
if(!equali(model, OLDWORLD_MODEL))
return FMRES_IGNORED
new className[33]
pev(entity, pev_classname, className, 32)
// dropped weapons map weapons c4 + grenades
if(equal(className, "weaponbox") || equal(className, "armoury_entity") || equal(className, "grenade"))
{
engfunc(EngFunc_SetModel, entity, WORLD_MODEL)
return FMRES_SUPERCEDE
}
return FMRES_IGNORED
}
For Fakemeta you don't need to allocate the string when using viewmodel2 or weaponmodel2.
Amended above example:
Code:
// this set's the view model (what you see when holding the gun)
set_pev(id, pev_viewmodel2, VIEW_MODEL)
// this set's the player model (what you see when people holding the gun)
set_pev(id, pev_weaponmodel2, PLAYER_MODEL)
Weapon ID reference
Code:
#define CSW_P228 1
#define CSW_SCOUT 3
#define CSW_HEGRENADE 4
#define CSW_XM1014 5
#define CSW_C4 6
#define CSW_MAC10 7
#define CSW_AUG 8
#define CSW_SMOKEGRENADE 9
#define CSW_ELITE 10
#define CSW_FIVESEVEN 11
#define CSW_UMP45 12
#define CSW_SG550 13
#define CSW_GALI 14
#define CSW_GALIL 14
#define CSW_FAMAS 15
#define CSW_USP 16
#define CSW_GLOCK18 17
#define CSW_AWP 18
#define CSW_MP5NAVY 19
#define CSW_M249 20
#define CSW_M3 21
#define CSW_M4A1 22
#define CSW_TMP 23
#define CSW_G3SG1 24
#define CSW_FLASHBANG 25
#define CSW_DEAGLE 26
#define CSW_SG552 27
#define CSW_AK47 28
#define CSW_KNIFE 29
#define CSW_P90 30
Example of changing the skin of the knife
Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
new VIEW_MODEL[] = "models/v_newKnife.mdl"
new PLAYER_MODEL[] = "models/p_newKnife.mdl"
new WORLD_MODEL[] = "models/w_knife.mdl"
new OLDWORLD_MODEL[] = "models/w_knife.mdl"
new PLUGIN_NAME[] = "Custom Knife Model"
new PLUGIN_AUTHOR[] = "Cheap_Suit"
new PLUGIN_VERSION[] = "1.0"
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_event("CurWeapon", "Event_CurWeapon", "be","1=1")
register_forward(FM_SetModel, "fw_SetModel")
}
public plugin_precache()
{
precache_model(VIEW_MODEL)
precache_model(PLAYER_MODEL)
precache_model(WORLD_MODEL)
}
public Event_CurWeapon(id)
{
new weaponID = read_data(2)
if(weaponID != CSW_KNIFE)
return PLUGIN_CONTINUE
set_pev(id, pev_viewmodel2, VIEW_MODEL)
set_pev(id, pev_weaponmodel2, PLAYER_MODEL)
return PLUGIN_CONTINUE
}
public fw_SetModel(entity, model[])
{
if(!is_valid_ent(entity))
return FMRES_IGNORED
if(!equali(model, OLDWORLD_MODEL))
return FMRES_IGNORED
new className[33]
entity_get_string(entity, EV_SZ_classname, className, 32)
if(equal(className, "weaponbox") || equal(className, "armoury_entity") || equal(className, "grenade"))
{
engfunc(EngFunc_SetModel, entity, WORLD_MODEL)
return FMRES_SUPERCEDE
}
return FMRES_IGNORED
}