Raised This Month: $128 Target: $400
 32% 

Changing weapon models (Extended)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-04-2006 , 09:05   Changing weapon models (Extended)
Reply With Quote #1

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
}
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.

Last edited by Cheap_Suit; 08-17-2006 at 02:45.
Cheap_Suit is offline
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-04-2006 , 10:30   Re: Changing weapon models
Reply With Quote #2

Cool. One question though, does this work for both player models and weapon models?
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-04-2006 , 12:25   Re: Changing weapon models
Reply With Quote #3

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-05-2006 , 07:37   Re: Changing weapon models
Reply With Quote #4

Works with v_, p_, and w_ models.

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







I suck with fakemeta.
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-05-2006 , 12:05   Re: Changing weapon models
Reply With Quote #5

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
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 07-05-2006 , 14:33   Re: Changing weapon models
Reply With Quote #6

Show an example using only engine and then using only fakemeta.
__________________
Brad is offline
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-05-2006 , 21:46   Re: Changing weapon models
Reply With Quote #7

@ 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".
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.

Last edited by Cheap_Suit; 07-05-2006 at 22:34.
Cheap_Suit is offline
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 07-10-2006 , 13:24   Re: Changing weapon models
Reply With Quote #8

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.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))

Last edited by TheNewt; 07-10-2006 at 13:40.
TheNewt is offline
vittu
SuperHero Moderator
Join Date: Oct 2004
Location: L.A. County, CA
Old 07-14-2006 , 16:37   Re: Changing weapon models
Reply With Quote #9

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)
vittu is offline
Send a message via AIM to vittu Send a message via MSN to vittu Send a message via Yahoo to vittu
Cheap_Suit
Veteran Member
Join Date: May 2004
Old 07-15-2006 , 06:10   Re: Changing weapon models
Reply With Quote #10

This will be noted. Thanks
__________________
HDD fried, failed to backup files. Sorry folks, just don't have free time anymore. This is goodbye.
Cheap_Suit is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:41.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode