AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Changing weapon models (Extended) (https://forums.alliedmods.net/showthread.php?t=40822)

Cheap_Suit 07-04-2006 08:05

Changing weapon models (Extended)
 
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
}

Only Fakemeta

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
}

Note: Using viewmodel2 and weaponmodel2.

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
}


TheNewt 07-04-2006 09:30

Re: Changing weapon models
 
Cool. One question though, does this work for both player models and weapon models?

Hawk552 07-04-2006 11:25

Re: Changing weapon models
 
I'd like to know why you include both engine and fakemeta. You should probably use one or the other. If I were you, I'd use fakemeta though.

Cheap_Suit 07-05-2006 06:37

Re: Changing weapon models
 
Works with v_, p_, and w_ models.

@Hawk552
I used fakemeta for FM_SetModel, and engine to simplify the example.







I suck with fakemeta.

Hawk552 07-05-2006 11:05

Re: Changing weapon models
 
Quote:

Originally Posted by Cheap_Suit
Works with v_, p_, and w_ models.

@Hawk552
I used fakemeta for FM_SetModel, and engine to simplify the example.







I suck with fakemeta.

I figured... use pev and pev_viewmodel / pev_weaponmodel

Brad 07-05-2006 13:33

Re: Changing weapon models
 
Show an example using only engine and then using only fakemeta. :up:

Cheap_Suit 07-05-2006 20:46

Re: Changing weapon models
 
@ Hawk552
Done.

@ Brad
Dont know if engine has a forward like FM_SetModel. You can probably try hooking it in server_frame or pfn_spawn.

@ RapHero2000
Model isn't found. Most probably you have v_<model name>.mdl
You must use the actual model name eg. "v_custom_m4a1.mdl".

TheNewt 07-10-2006 12:24

Re: Changing weapon models
 
I tried making this so that it only showed the model when a player has 'purchased' the model through a menu, but when I try to give the player a weapon at the begining of the round (resethud) it crashes the server... If I give the gun to the player as soon as he/she buys it, and doesn't die, then the next round the model loads, but not immediatly... It does show the model when I drop the weapon to the ground... I'm so confused...

-Edit: Fixed it.

vittu 07-14-2006 15:37

Re: Changing weapon models
 
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)


Cheap_Suit 07-15-2006 05:10

Re: Changing weapon models
 
This will be noted. Thanks


All times are GMT -4. The time now is 13:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.