AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Giving a model a weapon (https://forums.alliedmods.net/showthread.php?t=7553)

Geesu 11-12-2004 08:21

Giving a model a weapon
 
Code:
// 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:
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

Peli 11-12-2004 13:00

GJ Pimp Daddy. Would the same thing work with DoD? Using a DoD gun model I mean. :)

PM 11-12-2004 13:09

Added into helpful / useful stuff

XxAvalanchexX 11-12-2004 16:15

So this means that the gun appears in the right spot in the player's hands. But what you said about model animation, what do you mean?

GamerXR72 11-12-2004 16:33

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?

Geesu 11-14-2004 19:14

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.

LynX 11-15-2004 06:40

Actually, if you change your model, and make plugin fires rocket when that model is enabled, sure, why not? :oops:

Geesu 11-15-2004 09:03

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.

[DoD]GoldenEagle 07-23-2006 01:21

Re: Giving a model a weapon
 
Do you have to make a new...

Code:



entity_set_model( iEntWeapon, "models/p_m4a1.mdl" );

Such as...

Code:


// Assign the weapon entity a model
entity_set_model( iEntWeapon, "models/p_mp5.mdl" );


Major_victory 08-02-2006 14:52

Re: Giving a model a weapon
 
how would you go about making the animations work? this is something i've always had problems with...


All times are GMT -4. The time now is 17:30.

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