Tutorials on weapon addition

I’ve been following this old tutorial here: http://www.quake3hut.co.uk/q3coding/more!/new%20weapons.htm

But i have noticed that there’s no step regarding adding a first-person view model. Do you guys have any links to more complete tutorials, or any insight on this?

Q3 uses the weapon item model (in bg_items list) for item, holding in third person, and holding in first person. It’s animated in first person using “theWeaponName_hands.md3” or falls back to models/weapons2/shotgun/shotgun_hands.md3 (most of the Q3 weapons use this one). So no step for first person model is directly needed, it should just work.

If you want to use a separate model for item/third-person and first person, I would add support for separate first person model like this (untested);

  • Add handle to weaponInfo_t in cg_local.h
qhandle_t viewModel;
  • Load view model using trap_R_RegisterModel in CG_RegisterWeapon (maybe weaponName_view.md3, I copy-edited code for flash, barrel, and hands at top of CG_RegisterWeapon)
	strcpy( path, item->world_model[0] );
	COM_StripExtension(path, path, sizeof(path));
	strcat( path, "_view.md3" );
	weaponInfo->viewModel = trap_R_RegisterModel( path );
  • Then use handle in CG_AddPlayerWeapon if first person.
	// in CG_AddPlayerWeapon near the top;
	// if first person, and there is a first person model; use it
	// (if view model does not exist, the item model is used)
	if (ps && weapon->viewModel)
		gun.hModel = weapon->viewModel;
		gun.hModel = weapon->weaponModel;
	if (!gun.hModel) {

You may want to add separate first person barrel and flash models as well.

1 Like

What do you mean by “it’s animated using”? Is the animation inside the md3 file suffixed by _hands automatically played in the first person view? Any frame names or something? How do i control bobbing animation and shooting animation?

Also, i could not find any bg_items list. Where is it in ioq3 codebase?

Also, where’s the bobbing code at?

The hands models has a MD3 tag (tag_weapon) that the weapon gets attached to. The hands model is animated (moves the weapon axis/position). There is a function that convert torso animation frame to hands frame, CG_MapTorsoToWeaponFrame in cg_weapons.c.

You will want a way to search the code base if you plan of modding. git grep [string], Code::Blocks, Visual Studio, etc allow this. Sorry, it’s bg_itemlist not bg_items. It’s at the top of bg_misc.c (it’s pointed out in the tutorial you linked, without mentioning the name). Bobbing is in cg_view.c in CG_OffsetFirstPersonView.

Thanks for the info, @zturtleman! Do all weapons have frames for view and frames for torso? Or if there’s none, CG_MapTorsoToWeaponFrame will create?

Weapon models have 1 frame.

The hand model frame is set based on torso frame. Hence all models/players/*/animation.cfg files have the following warnings for four animations (the number of frames must not change because it will mess up first person hand model frame).

134	6	0	15		// TORSO_ATTACK		(MUST NOT CHANGE -- hand animation is synced to this)
140	6	0	15		// TORSO_ATTACK2	(MUST NOT CHANGE -- hand animation is synced to this)

146	5	0	20		// TORSO_DROP		(MUST NOT CHANGE -- hand animation is synced to this)
151	4	0	20		// TORSO_RAISE		(MUST NOT CHANGE -- hand animation is synced to this)

CG_MapTorsoToWeaponFrame finds which frame the hands model should use based on torso frame number, it doesn’t create anything. The hands model is expected to have all the required frames.

Look at CG_MapTorsoToWeaponFrame to figure out the order it wants and/or open models/weapons2/shotgun/shotgun_hands.md3 and look at it.

Third person attaches model to the player torso model, hands model is not used. Instead of hands model, torso is used for positioning.

1 Like

If the weapon models have only one frame, how is it “synced” with player’s animation.cfg?

Required frames? Isn’t only 1?

weapon md3: 1 frame
hands md3: ~15 frames (i don’t remember how many)

1 Like

Ah, finally i understand it. Thanks :slight_smile:

A happy cat