Page 1 of 1

Giving a model a weapon

Posted: Fri Aug 14, 2026 9:24 pm
by Archive-Poster

Code: Select all

// Create the weapon entity
new iEntWeapon = create_entity( "info_target" );

// Set the entity's class
entity_set_string( iEntWeapon, EV_SZ_classname, "weaponbox" );

// Set it to follow (so it will follow its owner)
entity_set_int( iEntWeapon, EV_INT_movetype, MOVETYPE_FOLLOW );

// Make the weapon solid
entity_set_int( iEntWeapon, EV_INT_solid, SOLID_NOT );

// Set the owner of the weapon to be the entity you want to have the weapon
entity_set_edict( iEntWeapon, EV_ENT_aiment, iEntOwner );

// Assign the weapon entity a model
entity_set_model( iEntWeapon, "models/p_m4a1.mdl" );
I put a list of the models in this array so you guys can use this to give it a random weapon or something (BUT YOU MUST change the model's sequence to match the weapon).

Code: Select all

new szWeaponModels[31][32] =
    {
        "models/p_knife.mdl",            // 0
        "models/p_deagle.mdl",            // 1
        "models/p_glock18.mdl",            // 2
        "models/p_p228.mdl",            // 3
        "models/p_usp.mdl",                // 4
        "models/p_flashbang.mdl",        // 5
        "models/p_hegrenade.mdl",        // 6
        "models/p_smokegrenade.mdl",    // 7
        "models/p_xm1014.mdl",            // 8  CT T         
        "models/p_m3.mdl",                // 9  CT T         
        "models/p_m3super90.mdl",        // 10 CT T        
        "models/p_awp.mdl",                // 11 CT T         
        "models/p_m249.mdl",            // 12 CT T         
        "models/p_scout.mdl",            // 13 CT T         
        "models/p_ump45.mdl",            // 14 CT T         
        "models/p_mp5.mdl",                // 15 CT T         
        "models/p_p90.mdl",                // 16 CT T         
        "models/p_c4.mdl",                // 17              
        "models/p_elite.mdl",            // 18                  
        "models/p_galil.mdl",            // 19 T         
        "models/p_ak47.mdl",            // 20 T         
        "models/p_sg552.mdl",            // 21 T         
        "models/p_g3sg1.mdl",            // 22 T         
        "models/p_mac10.mdl",            // 23 T         
        "models/p_shield.mdl",            // 24             
        "models/p_fiveseven.mdl",        // 25                  
        "models/p_famas.mdl",            // 26 CT           
        "models/p_aug.mdl",                // 27 CT               
        "models/p_m4a1.mdl",            // 28 CT            
        "models/p_sg550.mdl",            // 29 CT           
        "models/p_tmp.mdl"                // 30 CT        
    };
I'm posting this because I was trying to figure this out for a long time, then I found a resource on google that talked about MOVETYPE_FOLLOW and it explained the above. So enjoy

Re: Giving a model a weapon

Posted: Fri Aug 14, 2026 9:30 pm
by Archive-Poster
Could this be used to let someone buy the rocket launcher from single player half-life, from a custom menu like the warcraft 3 shopmenu, or is this just replacing the weapon model the player sees?

Re: Giving a model a weapon

Posted: Fri Aug 14, 2026 9:31 pm
by Archive-Poster
you have to make sure the model's sequence is correct. I think I used 4 to hold the m4a1 and ak, etc... mp5...

Only some weapons look correct, you'll have to play with it.

And yes it works for dod...

And no this doesn't allow to add a rocket launcher.

Re: Giving a model a weapon

Posted: Fri Aug 14, 2026 9:32 pm
by Archive-Poster
Actually, if you change your model, and make plugin fires rocket when that model is enabled, sure, why not? ;)

Re: Giving a model a weapon

Posted: Fri Aug 14, 2026 9:32 pm
by Archive-Poster
Well yea you could make someone hold a rocket launcher. What I'm saying is that the code provided above won't have the functionality to shoot it. You'd just be "holding" a non-functioning rocket launcher.

Re: Giving a model a weapon

Posted: Fri Aug 14, 2026 9:33 pm
by Archive-Poster
how would you go about making the animations work? this is something i've always had problems with...
I would imagine you would have to change the entity ints (check the engine const include file). I think anim_frame and anim_rate, or something like that...

You would have to register a think to the model + change those ints in that think.