Left 4 Dead 2

Left 4 Dead 2

263 ratings
Creating Weapon Mods. (With Prefab)
By мяFunreal
This guide explains how to create Weapons, Melees, Items, ect. using your own animations in excruciating detail.
Contains two Prefabs.
6
2
6
3
2
2
   
Award
Favorite
Favorited
Unfavorite
Foreword
Before I begin, I'd like to mention that steam sometimes deletes images on it's own.
I'm sorry if at some point I mention an image and there is none.
Let me know if that happens, because I myself can't babysit this page every day to check.




I know the guide is really, really lucifer damned long, but it has to be for all the info to fit.
The actual work takes just less than two days. So you could pump out a mod over the weekend.
Actual time differs if you put real good attention to detail into the animations.

This guide covers how to:
  • Fixing decompiled valve guns, in order to animate them
  • Make animations for whatever gun model you got
  • Making View and Worldmodels
  • Hud icons
  • Sounds (As separate video tutorial)

If you want to use existing animations I would reccommend you check this guide instead:
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=1946053787

You need:
Tool
Usage
Blender 2.8 or newer[www.blender.org]
Previous builds can be found here[download.blender.org]. I use 2.8
Modeling and animating
Blender Source Plugins[steamreview.org]
Import/Export valve model formats to Blender.
Contains the blender save file with IK rig to animate guns on.
Also has a "Hud Icon Render" prefab in it.
This is a set of QC files for viewmodels all pre-made by me.
Just a few edits required to make it work.
L4D2 authoring tools, from Steam tools library.
Has software required to compile models, test models outside of the game, and pack addons for shipping.
Optional GCFScape[nemstools.github.io]
Unpacking VPK files, to get the original models to decompile.
(Crowbar can do this too)
Unpacking VPK files, to get the original models to decompile.
Decompiling models.
UI for Compiling models.
UI for Packing addons.
UI for Publishing addons.
Any text editor.
Reccomended: Notepad++[notepad-plus-plus.org]
Editing QC files, used for compiling models.
Has Syntax Highlighting, to make QC editing even easier.
VTFEdit[nemstools.github.io]
Turning textures into a format L4D2 uses.

If you need to edit textures you can use photoshop, gimp or paint-net with the vtf plugins.
Getting original weapon files
In this guide i will be making a pistol mod, but every weapon acts exactly the same.
(Yes, every weapon. Even melee, medkit, cola, gnome, gascans...)
Just follow along and actually pay attention to learn how to edit any weapon.

1.0
First, we need the viewmodel and worldmodel of the weapon we want to edit.
L4D2 has multiple location where to look for models, plus multiple subfolders of those locations.

Head to the game folders. You can do this by right clicking the game in your library, Select "properties" and in the "Local Files" tab click on "Browse Local Files"


Open the "Update" folder and the Pak01_Dir.vpk using GCFScape or Crowbar.
Gun Worldmodels are in "models\w_models\weapons"
Gun Viewmodels are in "models\v_models"
The melee and gnome models are in "models\weapons\melee"
The css knife is along the guns in w_models and v_models

Carryable physics props are bit different. They're in;
props_equipment/oxygentank01.mdl
props_junk/explosive_box001.mdl
props_junk/gascan001a.mdl
props_junk/propanecanister001a.mdl

Most weapons have straight forward names. But some have odd names, so here's the odd ones to help you get the model you want.
Weapon
Model names
Pistols
v_pistola
v_dual_pistola
w_pistol_a
w_pistol_a_dual
w_pistol_b
Wood Pumpshotgun
v_pumpshotgun
w_shotgun
Chrome Pumpshotgun
v_shotgun_chrome
w_pumpshotgun_a
Autoshotgun (Benelli M4)
v_autoshotgun
w_autoshot_m4super
Rifle (M16A2)
v_rifle
w_rifle_m16a2
Desert rifle (Scar)
v_desert_rifle
w_desert_rifle
SMG
v_smg
w_smg_uzi
Silenced SMG
v_silenced_smg
w_smg_a
Hunting Rifle
v_huntingrifle
w_sniper_mini14
Css Knife
v_knife_t
w_knife_t

Not all items are in "Update" though.
If you can't find the item you need, check DLC3, then DLC2, DLC1 and lastly left4dead2.
If any model gets an update, it will be in the update folder.
But I don't know if or when that ever happens. So it's best to check one after another


Extract the World and Viewmodels by selecting them and dragging the files out of GCFScape or Crowbar into a folder of your choice.



You need the MDL, VTX, VVD.
Optional are PHY for worldmodel collisions, which you don't really need.
Because online gameplay forces the original collisions onto clients.


1.1
Decompile the models with crowbar.

Red part is for all models.
Green parts is only required or Viewmodels but you can still decompile the anims for worldmodels and delete them afterwards.
Worldmodels also have physics meshes which you could edit, but playing online ignores them. So I am not ticking the "Physics mesh SMD file".

You'll get a folder with all the source content.
Fixing Viewmodel Setup
This step is only required if you want to re-animate original valve weapons.
If you plan on making your own animations, skip to step 3.0

It is very possible that the weapon will look messed up, because parts are scattered all around.
Which makes it impossible to animate, or even just rig your weapon to this bone set.


2.0
Select the armature of the weapon, and import the decompiled idle sequence.
Doesn't have to be idle. Any animation which has the gun "put together" works

2.1
In Pose Mode, use the outliner on the right hand side to select the weapon bone.


Move this bone to the side.


Add all body bones to the selection aswell.


Clear all transforms on the selected bones.


The gun will now seem to be put pack together. But do not leave pose mode yet!


2.2
Move and rotate the gun bone so it is pointing forwards, away from all the body bones.


2.3
Check all angles to make sure the weapon is actually straight.
This SMG, even though being only rotated 90° on all axis from the ref pose is still skewed.
Probably a problem caused when this gun was animated.


Rotate the gun until the gun itself looks straight.
Or at least as straight as you want it, because you'll animate this later.

2.4
Leave pose mode and go to the mesh object's modifier tab.
Apply the Armature modifier it has.


Now that this model is put pack together, delete all the bones.
You can export this model now, so you can import it into the prefab on the next step.
Rigging Viewmodel
3.0
Open the Blender save file from the downloadable prefab.
You'll see that I have already loaded the AK47.


The AK47 is a placeholder, and scaling guide. So you have an idea of how big your gun should be.

3.1
Import your weapon model into this blend file.
They will probably land in the Arm Collection. Just move them out of there.



3.2
Move and scale your model(s) until the grip is about the same size as the AK47's grip.
If you fixed an original valve weapon in the previous section, it already is the right size.


You could also import the original viewmodel with "make new Armature", delete that imported armature and just use the original mesh itself to scale your gun against.

3.3
Delete the AK47 mesh, or your imported original gun mesh ,should you have imported it.
From now on, the only gun model we need is the one you'll animate.

In object mode, select your scaled meshes and apply all transforms.


3.4
Now you can move all the weapon bones to where you want them to be on your gun.
In armature edit mode!

Note:
"Weapon.A.Shell", "Weapon.A:Flashlight" and "Weapon.A.Muzzle" are optional for attachments. You can decide to what bone the attachment is supposed to be attached to. This allows you to have a pump-mounted flashlight on a shotgun, for example. Just re-parent the "Weapon.A:Flashlight" to the bolt, or whatever pump bone you made yourself. Then move the attachment bone to where you want it to be. Melee weapons also have more attachments for the melee blur and where the "blade" is. Every melee weapon seems to be differently set up on where the Blur attachments are. You can either make bones for those attachments, as seen in this image, or you can manually compare your viewmodel to the original and fennagle the attachments in HLMV until they fit.

You can also add bones if you need more, or delete bones you do not need.
You must never edit arm bones under any circumstance. Only edit weapon bones.


Once all your weapon bones are where you want em, you can start rigging the gun.

3.5 - Blender 2.8
Select your mesh object
Hold "Shift" and drag your mesh onto the armature.
Let go of the mouse, but keep holding shift.
A "Set Parent To" window will appear. You can now let go of Shift.
Pick "With Empty Groups".


3.5 - Blender 2.9
Select your mesh object
Hold "Shift" and click on the armature in 3d View, Object mode.
Press Ctrl & P
Pick "With Empty Groups".

3.6
Now that your gun mesh has all bones, you can start rigging it.
If you fixed and imported a valve gun, you might have leftover bones in this list. Delete them.
Select mesh that you want to rig to a bone. Start with the movable parts and do the body last.
Once mesh is selected, press the "Assign" button to rig it.
Make sure the weight is set to 1.0


Once something is rigged, press H to hide it from view and continue rigging all other loose parts.
After a while you'll only have pieces left that will be rigged to the main gun bone.


Press A to select everything you got left and rig that to the weapon bone.
Doing it like this assures that nothing will ever be rigged to two bones at once.

After you have rigged everything, you can enter pose mode on the armature and move bones.
You'll now find out if all the parts are properly rigged. Nothing should stretch.
I had to rig the trigger bone because i forgot it in the previous image.


3.7
Now you can check if the materials of your gun have sensical names.
Just make sure they do not have any file endings or folder setups like "desktop/myjunk/gun.tga"


3.8
Now you can export the rigged weapon as SMD in the same folder as where your QC file is.
First select the folder to export to, then press the Export button.
═══════════════════════════
Animation setup & Base Pose
Note:
  • I hope you know how to animate, because I'm not going to teach you the basics.
  • In my prefab the clip bone is not a child of the gun bone, to make reload animating easier.
    The clip bone instead uses a "Child of" Constraint to make it seem like a child.
  • The thumbroot bones are IK'ed to the thumb. Rotating the thumb rotates the thumbroot.
  • The forearm twist bones are not IK'ed because I prefer to have more precise control over them.
  • You can do more than one version of an animation, except idle. But you can do fidgeting instead.
  • The camera can be animated, but only rotation. Most people dislike it though. If you do want to animate the camera, rotate the ValveBiped.Camera bone. Or add your own and animate that, making sure to also add a "Copy Rotation" constraint to the blender camera found in the prefab , to actually visualize camera rotation properly.

4.0
Go to the Animation tab and change the Dope Sheet to Action Editor.
This allows us to save all animations in the same Blender save file, as different actions.


Make a new action called idle.


The Octahedral bones on the hands are the hands IK bones. Move them and everything follows.
The balls that are children of it are the Elbow helper bones.
You could change the parenting if you prefer them not to be parented to eachother.


Make a simple one-frame sequence of where and how you want the gun to be held.
Use the camera and the FOV helpers to decide where you want the gun.
I play in FOV 85 so I make my gun visible in that FOV, but also make it visible enough in FOV 51


Don't forget that some players use very large FOV.
Everything leaving the screen, like hands and clips during reload, should move way out of frame.


Notice how the very left only has some keyframes?
We need at least one keyframe for every single bone.
Select all bones by Pressing A and then keyframe all bones by pressing i.
Missing keyframes can break the animations.


All our animations will be based on this current pose.
For now though, add a "child of" bone constrain to the hand and clip bone.
This allows you to only move the weapon bone and have the clip and hand follow automatically.

Select the right hand IK bone, go to the bone modifier tab and add the "Child Of" constrain.


Select the armature and then the weapon bone. The hand will move away, which is normal.


Pressing the "Set Inverse" button once will bring the hand back.


Moving the weapon bone now, will cause the hand(s) to follow.


You can now do this for the left hand too. I won't because the left hand is never used.
Idle
4.1
Now you can make the idle animation based on this base position.
Use about 60 or 120 frames with some idlenoise.
Most importantly is that the first and last frame of all looping sequences must be identical.

That'll do.


By the way, you can change framerate over here. In case you wanna animate on 60 FPS.
Higher framerate only means the animation itself is smoother ingame.
the game already does some smoothing of it's own, but it may be a bit wonky.


Run
4.2
Now that the Idlenoise is done, we can do the running animation.
Remember where you made the "Idle" action? Make a new "Run" action.

The "New Action" button duplicates the currently used action.
Which is neat, because the run animation is basically just a more moving idle animation.


Good enough for this guide.


Note: You can use two sets of running. Forward and backwards.
Maybe you can even do more for sideways movement, but I have never attempted it
Lookpose
4.3
Lookpose is the blending sequence you see when you look up and down.
They are optional, but a nice touch.

Make a new action called lookpose. It is only three frames.
Frame 0 is "looking down"
Frame 1 is the default idle base pose you already got.
Frame 2 is "looking up"
I reccomend to only add very slight movement. Too much movement will look very strange.

Personally, I slap the cursor to the shoulder to use it as pivot and rotate the gun at 0.5°.

Framecount info for upcoming anims.
From now on, this guide must be used to check how many frames your animations need.
All remaining animations must have the correct amount of frames and respective FPS.
Except for helping_hand_loop and item_loop
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=1483047118

Look for the gun you are animating. I am making a Deagle, so i'm looking for Pistol / Deagle.
The next animation I want to do is Fire and Fire_layer
The non_layer sequence acts as a timer, while the _layer sequence is what you see.



That guide there says the Fire and Fire_Layer sequence both are using 30 frames at 30 FPS.
So, make a new action in blender called Fire with exactly 30 frames, and setting the FPS to 30.

Technically, it does not have to be exactly 30 Frames at 30 FPS.
The Framecount must only match relative to the FPS.
So 30 Frames at 30FPS. 60 Frames at 60FPS, 1337 Frames at 1337 FPS.
If you increase the framecount 4.5 times, you also need to increase the fps 4.5 times.

Also, some weapons have the _layer with more frames than the non_layer sequence.
You should always base your animation lengh on the framecount of the non_layer sequence.
Unless there is no non_layer, like the sniper rifles melee_layer, which has no melee sequence.


For some reason, the "non _layer" $sequence acts as a timer.
The "_layer" $sequences are what you actually see in the game.

Example:
You reload the gun. The game triggers the "reload" and "reload_layer" sequences to play at once.
You can see "reload_layer" moving the gun, while the "reload" runs in the background.
When the "reload" sequence ends, your input is unlocked and you can fire again.

No matter if "reload_layer" is still playing or not. If "reload" ends, you can dispense bullets again.
If "reload" ends before "reload_layer" you can cancel the visible animation and shoot again.
If "reloay_layer" stops moving before "reload" is done, you have to wait until you can shoot.

Usually, both the non_layer and _layer sequences have the same amout of frames.

Some people make long anims on purpose, making use of the ability that you can interrupt them.
You'll have to pay attention to the animations you're porting, to avoid porting them wrong.
Traditionally, nothing can be skipped. But some weapons were specifically designed for this.

Example:
Lt.Rocky has made a weapon mod that replaced the M60 with a minigun.
The "fire" sequence is 30 frames at 30 fps, which is default. (1 second)
The fire_layer sequence a whopping 176 frames at 40 fps. (4.4 seconds)
He animated the barrels to spin out for 3.4 seconds after the firing anim "would" be over.
This allows you to shoot the gun while the barrel is still winding down.

Another example:
Some people make reload anims where the animation can be interrupted after inserting the magazine, just like some video games to it nowadays.

So for those types of animations you have to pay attention to when you want it to actually stop.
Which can be done easily by loading the animation in blender, checking which frame your "end frame" should be, and then just using it for the calculations instead of the full frame count of the animation.

However, if a $sequence is immediately followed by another sequence, the _layer will automatically be cut of when the non_layer ends.
For example, the pipebomb item pickup non_layer is 30 frames, but the _layer has 50.
Since the item pickup is immediately followed by item_loop, you won't ever see the frames 31 to 50 of the _layer. In which case you only need to use frames 0-30 and don't pay any attention to the fact that the _layer has more frames.


In blender, you need to add a keyframe exactly on the end frame.
SMD's export until the last keyframe is reached, even if your "End" marker is several frames back.

So a sequence with 120 frames must have at least a keyframe on 0 and one on 120.
Also every single bone needs a keyframe. Even if they are not moved at all, like the spine.
For those just make frame 0 have a keyframe for all bones.
Fire
4.4
Firing the gun is pretty straight forward.
Move the gun backwards a few frames into the animation, pose the trigger, hammer, slide...
Whatever needs to be moved.

I forgot to pose the trigger when making this gif. But you get the point.
Reload
4.5
Now, for the reload animation there's rather annoying thing to deal with.
That "Child of" constraint on the clip that we added.
We had added it because we want the clip to follow the gun when it moves, but we also want to be able to move the gun in one hand without having the magazine move in the other hand while we reload. So that means we need to keyframe the influence of that constraint aswell.

This assumes you're using my prefab where the clip bone is not a child of the weapon bone.
I prefer animating this way because it gives me more freedom.
But if you prefer it the other way, reparent the bones.


First make a new "Reload" action.
Animate until the keyframe where the magazine would come falling out.
Make a keyframe for the clip bone, without actually moving it by pressing i.

Head to the Bone Constraint tab of the Clip bone, hover over the "Influence" slider and press i.
The slider should turn yellow.


Move over a few frames and move the clip out of view.
On that frame set the Influence of the "Child of" on the clip to 0 aswell.

This allows the clip to "fall out" and lose influence of the "Child of" constraint on it's way down.
That in turn allows you to move the gun in the right hand and not have the clip magically move.

At this point you can do whatever with the left hand.
If you want you can set up a "Child Of" constraint on the left hand IK so it follows the clip aswell.
I do it to make animating the hand easier by just moving the clip.


As you had seen in the image above, the "Child of" influence does back to 1 later.
This forces the clip to move back where it belongs.


Now you gotta slightly move the clip on those few keyframes to fix clipping issues.


And now decorate the animation with more hand movement.
Try to keep inertia in mind when inserting the magazine.
Melee
4.6 Melee
The only important thing to know about the melee shove is that valve coded L4d2 so that the animation and the infected actually being shoved happen on the same frame.

That means the melee animation should start with the fist being extended almost immediately, otherwise the infected is already falling backwards before the fist hits them.
I recommend animating on 2x the framecount and FPS to allow some more precision on when the hand is in the "Punch" position.

Or just make it like Valve and start the animation with the fist already being extended all the way.
Which turns the entire animation into "recovering from punching".

I have made two melee animations. We'll discuss this later on. You only need to do one.
Helping Hand / Item Extend
Note
These animations are relatively optional.
"Helping Hand" is used when you look at incapacitated players.
"Item Extend" is used when you look at things to interact with. Like ammo, items or buttons.

These animations are identical, except for the pose of the hand.
Helping Hand is palm up, while Item Extend is palm down.
You could also just use the same set for both to save some time.

A lot of people would argue they these animations are stupid and useless, so I'll show how to make them, but also how you can avoid them entirely.

If you do not want them, just don't make any animations for it.
We'll edit the QC file to fit this decision later on. Because you can't just delete the sequences.

4.7

These animations consist of three parts: hand extend, idle loop and hand retract.
You can make a single animation in blender and use the "frame X Y" in the qc to separate them.
You don't have to do it this way, but this allows you to keep a single animation SMD.

Check the "Animation Lookup Guide", to see how many frames the anims need.


20 frames for extending, any amount of frames for loop, and 20 frames for retracting the hand.

Make a 20 frame animation of the hand extending.


I want a 60 frame loop sequence, so I duplicate the keyframe of 20 and move it to 80.
Then add some noise in between.


Tip:
The Start and End frame setting allows you to pick which frames blender will play.
Which allows you to test just the looping part of the animation.


The retract is also 20 frames long. You could duplicate and reverse the extend frames for it.


Now you have one animation where the hands extend, does one "loop" and retract again.
Fidgets
4.8
You have the ability to create fidget animations that randomly play.

We can not have specific triggers like "Reloading a full gun checks the mag" like in HL2:MMod, "Pressing G to inspect the gun" like CS:GO, or "Idling for a minute to just fool around with the gun" like FarCry 2.

We only got random things that play whenever. They could even play right as you are shooting the gun and there won't be any transition between fidget and your input like Firing or Melee.
It'll just snap to the triggered animation instantly, which will look weird if your gun moves too much.

Do something quaint, if at all. Or just hope players will opt to not use the gun for the time being.
Exporting Animations
You can now export the sequences one after another.

Select any of your actions


Go to the same spot where you exported the gun mesh.
Blender notices you're in pose mode and will export the selected action instead.


Alternatively
You can use a batch export script to automatically export all animations you have in your scene.
Go to the scripting tab, make a new script with the following content and then press the "Run script" button to export all animations in blender.
############################################# # batch exports all Actions into its own # file for Blender Source Tool usage. # Just hit the "Run Script" button to export # by: Davi (Debiddo) Gooz, free to use ############################################# import bpy import os for a in bpy.data.actions: bpy.context.object.animation_data.action = bpy.data.actions.get(a.name) bpy.ops.export_scene.smd()
═══════════════════════════
QC Edits (Using Prefab)
I've provided a prefab QC for all weapon viewmodels, which you can get Here[github.com].

This prefab allows you to easily edit just a few lines instead of a lot of lines.
If you follow this section using this prefab, you could later skip to "Sound & Particle Events"
If you do not want the prefab, go to "Base Viewmodel QC Edits"

5.00
Download bones.qci from the githup repo and put it into the folder your source files are.
Download the QC file of the weapon you're making and put it onto that same folder.


5.01 - Base QC Edits
Open the QC file and edit the lines in the red boxes.
"CustomMeshHere" should be the gun model you had exported earlier in step 3.8
"Models/Weapons/Whatever" is the location of where the materials and textures should be.


$CDMaterials "Models/Weapons/Whatever" means the materials and textures are in "Materials/Models/Weapons/Whatever"!

5.02 - Adding Animations 1
Scroll down to the $animation lines.
The strings in the red blocks are the animations you exported.
I already gave them basic names, but if you exported with different names, change them now.

Make sure you use the correct names, and if you decided to animate on twice the FPS, change the FPS settings in these few lines aswell.


5.03 - - Adding Animations 2
Once you set up the FPS and animation file names, duplicate the entire $animation block.
Then swap the prefix from A_ to AL_.

In Notepad++; click on the top left a_, press Shift+Alt and click the bottom most a_.
Now you selected the whole column and can edit all this text at once.



You can see i changed the helping hand and item hand setup, while also adding another melee and additional fidget animations.

5.04.1 - Adding Helping Hand
The Helping hand and item extend animation in these prefabs have a different setup than explained in this guide previously.

In this guide you made one animation where the hand extends, plays the loop anim and retracts.
But in the QC i set it up to have one anim be extend and retract, while the loop is another smd.


You can easily change this by swapping the used animations and "limiting" which part of the animation is used for extending hands, looping and retracting hands.
The _Ext are extending hands, while _Ret are the retracting hands.

In the screenshot, you can see that a_it_ext, a_it_ret and a_it_idle use the same animation.
Yet the extending hand uses frames 0-20, retracting uses 80-100 and the idle uses 20-80.


5.04.2- Not using Helping Hand
If you don't want any helping hand animations:
Comment out all hh_ and it_ animations.


Add the this line above the helping hands:
$weightlist empty { "ValveBiped.ValveBiped" 0 }
Every "root" bone needs to be defined with a weight of 0.
If you added a bone that has no parents at all, it also needs to be listed!

Then make every helping hand animation use this weightlist, while using a_look_mid as anim.

5.05 - Adding Extra Animations
If you want extra anims you can copy the original sequences below all other sequences, change the sequence name and make it use the other $animations.


Note: Activity Weights
The number behind the activity name is the activities "Weight".


It determines the chances of this sequence playing.
The actual calculation is done like so:
The game looks at all sequences of the same activity and adds up the total weight of them.

In my case two melee activities. One uses weight of 3, the other uses 2. The total sum is 5
Now it compares the weight of every individual activity against the total sum.
The sequence with the weight of 3 has a "3 in Sum" chance to play. Being 3/5.
The other only has a 2/5 chance to play.

You could use this to make an incredibly rare animation by making the default use a weight of 99.
So the default has a 99/100 chance to play, while the extra anim has a 1/100 chance.

5.06 - Adding Fidget Animations
For the fidgets, add the following block of text below the original sequences:
$weightlist empty { "ValveBiped.ValveBiped" 0 } $sequence fidget00 a_look_mid weightlist empty ACT_VM_FIDGET 100 numframes 120 fps 1 $sequence fidget00_layer a_look_mid weightlist empty ACT_VM_FIDGET_LAYER 100 numframes 120 fps 1 $sequence fidget01 a_fidget1 ACT_VM_FIDGET 2 $sequence fidget01_layer al_fidget1 subtract a_idle 0 delta ACT_VM_FIDGET_LAYER 2


Let me explain what these lines do:
Fidget_00 and its _Layer are empty.
They are invisible and are needed to balance how often the other fidgets could play.

Balancing works like this:
Thanks to "NumFrames 120 FPS 1" this Fidged_00 plays all 120 frames at one fps.
So that When it does play, it makes sure no other fidgets can play for 120 seconds.

Fidget00 has a weight of 100
Fidget01 has a weight of 2
Fidget02 has a weight of 3

Total sum of all weights being 105
Fidget00 has a 100/105 chance to play. If it does play, no other fidget can play for 2 mins.
After Fidget00 is "done playing" the game rolls dice again to see which fidget will be played next.

If it picks Fidget00 again, thanks to the heavy weight, another two minutes of no fidgeting.
Until eventually it picks one of the Fidget01 or Fidget02 to play, then it rolls dice again.

Pretty simple.



All that's left in this qc now is the attachments, and then the events.
So, look at the next section.
Attachments (Using Prefabs)
5.07.1
Next are $attachments.

These things handle where the muzzle flash happens, where to put the flashlight/laser and where the shell ejection particle appears.

If you decided to use the attachment bones in blender ("Weapon.A.Shell", "Weapon.A:Flashlight" and "Weapon.A.Muzzle") you can swap the existing attachments with the following:
$attachment "shell" "Weapon.A.Shell" 0 0 0 rotate 0 0 0 //$attachment "forwardnode" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 //$attachment "muzzlesmoke" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "attach_shell_eject" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "attach_muzzle" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "muzzle_flash" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "flashlight" "Weapon.A:Flashlight" 0 0 0 rotate 0 0 0 $attachment "attach_camera" "ValveBiped.attach_camera" 0 0 0 rotate 0 0 -90
Some weapons have a Forwardnode. It should be in the same spot as the muzzleflash.
If you don't want any camera movement, you may aswell just remove the camera attachment.

Here's what those attachments do, by the way:
Attach_muzzle
Forwardnode
Where bullet tracers spawn.
Attach_shell_eject (old)
muzzlesmoke (new)
Smoke that appears after rapid firing. Either end of barrel or in the chamber.
Muzzle_flash
Muzzleflash lights
Flashlight
Flashlight and laser
Shell
Ejection port for spent shells.
Attach_muzzle, Attach_shell_eject, Muzzle_flash, and Forwardnode should use the same data.
Together all of them form the full muzzleflash.
But you can move the Muzzle_flash way out of view behind the camera to "delete" it, like silenced weapons should do.

5.07.2
Melee weapons are a bit different with attachments. The bat and katana got their "Blur" attachments in wildly different locations. On the Baseball bat it even moves because its rigged to the clip bone.
So it's generally best to compare the location and rotation with the original weapon.
But generally, having the blur a good chunck away from the hand is a good idea, while the blade (somehow) is hovering quite a bit away from the actual blade.
Make sure the rotation is about the same aswell, else the particle might be buggy.


5.07.3
Molotov and Pipebomb have attachments for the fuse and fire particles.
Should you not want to use them, you must not remove the attachments for them.
Missing attachments cause the particles to spawn at map center and overlay onto everything.

Instead, move the attachment behind the camera.
$attachment "fuse" "ValveBiped.ValveBiped" 0.00 0.00 -100.00 rotate 0 0 0 $attachment "Wick" "ValveBiped.ValveBiped" 0.00 0.00 -100.00 rotate 0 0 0


Now, after having read this section, you can skip right to "Sound & Particle Events"
Base Viewmodel QC Edits (wo/ Prefab)
These "wo/ Prefab" sections are for when you do not use the qc base prefab i've provided.

6.01
Open the viewmodel QC in Notepad ++
You will be greeted by a $modelname at the very top.


$Modelname decides the name and location of the model that we will compile.
We need to open the model in HLMV later on, which requires us to use a custom $modelname.
Duplicate the $modelname line, add a // in front of one and change the other to a unique name.


This causes the original one to be ignored because it's a comment, and instead compile a mdl of whatever name you have chosen.

Reason
HLMV is a tool used to inspect models. We'll need it to check animations, do the attachments and check materials without actually loading the game.
However, HLMV is programmed to always load models from the pak01_dir.vpk, if found.
That means you'll never see your custom gun because it's in the pak01_dir.vpk.

You must change this back when you want to compile for the game, else your gun mod breaks!

6.02
The next part is $bodygroup. That one is your model.
Models compile with $bodygroup, $body or $model. I use $model because it requires less space.

Swap the $bodygroup section with a single $model line for each of your smd's.


"MrFunreal" is an internally saved name, which serves absolutely no useful purpose here.
I use it as a watermark, because it's saved in the model. So I'll find it if someone steals my mod.

BODY and CLIP are the smd files i want to compile. The .smd ending is not needed.
If you happen to have a .smd and .dmx of same name, it will use the dmx.

6.03
Next parts are $surfaceprop, $contents and $illumposition. Do not edit those.
$Surfaceprop decides the surface properties (material) of the model.
Viewmodels never interact with anything, so surfaceprop is useless. Worldmodels use it though.

Skip to $cdmaterials. This is where the materials and textures will be saved.
This folder setup is within the materials folder.

$cdmaterials "models\v_models\Weapons\pistol\" means textures are actually in
"materials\models\v_models\Weapons\pistol\"

You can change this is you want, or put your textures in that same folder.
I like adding my own folder.
Make sure the line ends with a / or \


6.04.1
Next are $attachments.

These things handle where the muzzle flash happens, where to put the flashlight/laser and where the shell ejection particle appears.

If you decided to use the attachment bones in blender ("Weapon.A.Shell", "Weapon.A:Flashlight" and "Weapon.A.Muzzle") you can swap the existing attachments with the following:
$attachment "shell" "Weapon.A.Shell" 0 0 0 rotate 0 0 0 //$attachment "forwardnode" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 //$attachment "muzzlesmoke" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "attach_shell_eject" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "attach_muzzle" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "muzzle_flash" "Weapon.A.Muzzle" 0 0 0 rotate 0 0 0 $attachment "flashlight" "Weapon.A:Flashlight" 0 0 0 rotate 0 0 0 $attachment "attach_camera" "ValveBiped.attach_camera" 0 0 0 rotate 0 0 -90
Some weapons have a Forwardnode. It should be in the same spot as the muzzleflash.
If you don't want any camera movement, you may aswell just remove the camera attachment.

Here's what those attachments do, by the way:
Attach_muzzle
Forwardnode
Where bullet tracers spawn.
Attach_shell_eject (old)
muzzlesmoke (new)
Smoke that appears after rapid firing. Either end of barrel or in the chamber.
Muzzle_flash
Muzzleflash lights
Flashlight
Flashlight and laser
Shell
Ejection port for spent shells.
Attach_muzzle, Attach_shell_eject, Muzzle_flash, and Forwardnode should use the same data.
Together all of them form the full muzzleflash.
But you can move the Muzzle_flash way out of view behind the camera to "delete" it, liek silenced weapons should do.

6.04.2
Melee weapons are a bit different with attachments. The bat and katana got their "Blur" attachments in wildly different locations. On the Baseball bat it even moves because its rigged to the clip bone.
So it's generally best to compare the location and rotation with the original weapon.
But generally, having the blur a good chunck away from the hand is a good idea, while the blade (somehow) is hovering quite a bit away from the actual blade.
Make sure the rotation is about the same aswell, else the particle might be buggy.


6.04.3
Molotov and Pipebomb have attachments for the fuse and fire particles.
Should you not want to use them, you must not remove the attachments for them.
Missing attachments cause the particles to spawn at map center and overlay onto everything.

Instead, move the attachment behind the camera.
$attachment "fuse" "ValveBiped.ValveBiped" 0.00 0.00 -100.00 rotate 0 0 0 $attachment "Wick" "ValveBiped.ValveBiped" 0.00 0.00 -100.00 rotate 0 0 0

6.05
next are $cbox, $bbox, $definebones, $bonemerge, maybe $jigglebones, $weightlists, and finally $animations and $sequences.

$cbox and $bbox must not be changed.

$definebones must never change order. Different order will break the player arms.
If you want custom $definebones, add $UnlockDefinebones above the list of $definebones.
This allows you to alter the bone values, without altering its order.

If you do use $UnlockDefinebones, you should define your $model line with the custom model at the very end of the QC file. Because this will alter the reference pose of the model.
If anyone decompiles your model, it will look bad and has to be put back together.
So just define your custom model at the very end of the qc.

Except attachments, because they will figure out what bone they will actually end up being attached to and sort themselves out.
Adding Animations to QC (wo/ Prefab)
6.07
If you are compiling your own animations, you can now edit the $animations and $sequences.

Scroll down to where you either have $weightlist or a few $animation lines.
You will most likely have a block of $weightlist and a few "corrective animations".



Delete all of that.
The next lines you will need are whatever the first $sequence is.
For pistols it should be "Idle", most guns use "Look_poses", some items use "Vaims".


FYI:
The IKchain lines are doing the IK in L4D2.
They help the hands follow the guns. However, the Knee part decides where the elbows go.
From my experience, it is a good idea to comment the Knee part of the ikchains.
This will force the compiler to not "make up" locations of the elbows.


Because:


6.08
Now we will set up our own $animations.
Add the following lines before the first $sequence
$animation "a_idle" anims\idle loop ikrule rhand touch "weapon" usesource ikrule lhand touch "weapon" usesource $animation "look_down" anims/lookpose frames 0 0 subtract a_idle 0 $animation "look_mid" anims/lookpose frames 1 1 subtract a_idle 0 $animation "look_up" anims/lookpose frames 2 2 subtract a_idle 0 $animation "a_run" anims/run.smd loop

"A_idle" is the idle sequence you exported.
The Look animations all load the "lookpose" animation, while appointing frame 0 as being the "look down" pose, frame 1 is the natural pose and frame 2 is looking up.
"a_run" defines the running animation.

The "anims/..." part loads the actual animation smd files.
If you called your idle action "idlenoise" then your a_idle would need to load "anims/idlenoise".
or if your looking action was "look" swap "anims/lookpose" for "anims/look"

The Ikrule and everything afterwards on the a_idle handles the Inverse Kinetics in L4D2.
That causes the hands to follow the bone you tell it to follow.
in the setup above, it tells the Rhand to touch (and therefore follow) the "weapon" bone, while the Lhand touches the weapon bone aswell.

Should you not have a hand follow the gun, use "release" instead.
For example, my left hand never touches the gun, unless reloading.
I will swap ikrule lhand touch "weapon" usesource for ikrule lhand release.



Should you have decided to change the framerate on the animations, you can add a "fps" setting to the $animation to force it to run at the fps you want.
In the picture above you can see the a_run $animation being forced to play at 60 fps.
Not having a fps setting makes it play at 30 by default

6.09
This step serves two purposes: It prevents a bug, and future proofs your animations.

Bug prevention:
If your non_layer and _layer sequences use the same "anim/animation.smd" file, they can break.
For some reason, one of them may just not work. So we avoid this issue entirely with this step.

Here's a video showing what that bug would look like. (Warning, I curse because I was annoyed!)
lol

Future proofing:
We are going to subtract the animations in order to blend them, because it looks better.
However, blending animations causes them to break when they're decompiled.

Which means anyone wanting to port your gun to another slot can't do that.
But also, If you wanted to fix something on your mod and you lose the source files, you'll need to decompile your own mod. If you didn't "future proof" your anims, you couldn't recompile your own animations anymore. This happened to me three four times now.

There's multiple ways of dealing with this step.
But i'm only going to show the way that also preserves the animations for future use.

Duplicate every animation file and rename the copies to use the _layer suffix.


Create a block of $animation files defining every smd file as an animation using the a_ prefix.
And then copy all of it and make the copy use the _layer.smd files using the al_ prefix.


The $animation lines with the a_ prefix are for non_layer $sequences.
The ones with the al_prefix are for the _layer $sequences

Some weapons may not have a non_layer sequence for some animations.
The military sniper rifle only has melee_layer, without the melee sequence.
In those cases you should still have an a_ and al_ $animation. The a_ animation acts as backup.

Note:
In this guide, you will see me still use the same a_anim for the non_layer and the _layer.
This is because this step here was written after the trest of the guide was made.
Just assume that all non_layer sequences use a_anim and the _layers use al_anim.
Sorry for the confustion.

6.10
Now that the $animation lines are done, set up the Idle_layer and the look_poses.
On the pistol it's idle and idle_layer. The pistols are the only ones where it's like this.
Just check on your qc which sequence has the run anims and which one has the look anims.


Make sure your $animations are used the same way as on this image.
The second a_run is the "walking backwards" animation. so you could make a second one for it.
It's important that the lookposes in the $sequence are up, mid and down. In that order.
Else your lookposes are flipped.

6.11
Now we can start modifying all the $sequences to make use of your $animations or smd's.

First, check if any $sequences have a huge block of Ikrule lines.
If they have em, delete them.


If you changed the fps in the $animation, delete the fps setting here.
If you haven't changed the fps in the $animation, keep this fps setting in the $sequence.
If you are using smd's and you need different fps, edit the fps setting here in the $sequence.


Swap the used animation.smd in the $sequences for the $animations you had made.
The "Deploy" shoud use a_deploy, and "Deploy_layer" should use al_deploy.
But this image was done before the previous step, so the $animation names are different here.



It's possible a lot of _layer $sequences have this combo of subtract, delta and a comment in it.
They're useless for our anims and need to be deleted.


Instead, all _layer sequences (except maybe helping hands) need this:
subtract a_idle 0 delta ikrule rhand touch "weapon" usesource ikrule lhand touch "weapon" usesource
Of course your ikrules must be the same as the one you had used on the idle.
Unless the left hand is being moved like in reload, melee and helping hand.
In those cases the lhand must release.
My own left hand ikrule is always using release, except during reload, where I make it follow the clip, because this is a one handed gun and makign the left hand follow any bone is useless.



If any $sequences still use weightlists, delete those lines from the $sequence.


Do not give the non_layer sequences subtract a_idle 0 delta.
This will break the non_layer anims which renders them unrecoverable when decompiled!
Handling Helping Hand (wo/ Prefab)
6.12.1
Once all other sequences are updated, you'll have to handle the hand extending sequences.
If you want to keep the hand sequences, do this step.
If you don't want to use them, do step 6.12.2 instead.

Note: Somehow the left hand thumbroot breaks on helping hand sequences if you're NOT using "subtract a_idle 0 delta" on them. I have no clue how or why. But if your left thumbroot breaks on hand extends, just disable the left hands thumb root bone's IK constrain, export the helping hand animations and enable it again.


Helping Hand animations are a bit finnicky.
The extends must use fadeout 0, while the retracts must use fadein 0
So what i do is use fadein .3 fadeout 0 for extend, and fadein 0 fadeout 0.3 for retract.
This has to be done because using any tipe of fade from extend/retrade to the loop will cause it to fade to the idle sequence and then to the loop, making a very messy transition.


Also:
The extending hands just don't work with subtract a_idle 0 delta.
Thats why i'm using a longer fadein for the extend and a longer fadeout for retract.

Remember when I mentioned you can make one sequence that has extend, loop and retract in it?
If you want to "take it apart" you'll have to use the "Frame" option just like lookposes do.
You saw this in step 6.09 already, but now it is relevant.


As you can see, i got three $animation lines that all use the same .smd.
"Extend" is told to only use the frames 0 to 20.
"Loop" uses 20 to 80, also using "loop" which helps smoothen the loop.
"Retract" is told to use 80 to 10.

Because I have my $animations contain the "frame X Y" lines, I don't have to use them here.
If you do not use the $animation lines, and use the smd files in these sequences, you'll have to add these frame definitions here instead.


6.12.2
Should you not want to use the helping hand sequences at all, you must not delete them.
But you can "disable" them in a way so you can't actually see them.

Replace the entire helping hand section, all 12 sequences, with this:
$weightlist empty { "ValveBiped.ValveBiped" 0 } $sequence "helping_hand_extend" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_EXTEND" 1 $sequence "helping_hand_extend_layer" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_EXTEND_LAYER" 1 $sequence "helping_hand_loop" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_LOOP" 1 $sequence "helping_hand_loop_layer" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_LOOP_LAYER" 1 $sequence "helping_hand_retract" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_RETRACT" 1 $sequence "helping_hand_retract_layer" CLIP weightlist empty activity "ACT_VM_HELPINGHAND_RETRACT_LAYER" 1 $sequence "item_extend" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_EXTEND" 1 $sequence "item_extend_layer" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_EXTEND_LAYER" 1 $sequence "item_loop" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_LOOP" 1 $sequence "item_loop_layer" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_LOOP_LAYER" 1 $sequence "item_retract" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_RETRACT" 1 $sequence "item_retract_layer" CLIP weightlist empty activity "ACT_VM_ITEMPICKUP_RETRACT_LAYER" 1
Except you have to change the "CLIP" with whatever smd you are using for the $model line.



WARNING:
Some items have different sequence and activity names.
the Health Kit for example uses itempickup_extendr and ACT_VM_ITEMPICKUP_RETRACT_ because they got typos and valve never noticed or bothered to fix.
Adding Extra Animations (wo/ Prefab)
6.13 - Optional
Earlier I had mentioned what we have the ability to add more than one version of an animation.
I have a second melee animation, which i want to use.

To add extra animations, copy the original sequence lines to the very bottom of the qc.
Change the $sequence name by adding a 2, 3 or whatever to the sequence name.


Do you see that "1" after the activity name?


That is the "Weight" of this sequence. It determines the chances of this sequence playing.
The actual calculation is done like so:
The game looks at all sequences of the same activity.
It sums up the total weight of all the activities of same name.
In my case two melee activities. One uses 1, the other uses 2. The total sum is 3
It compares the weight of the activity against the sum.
The sequence with a weight of 2 has a 2 in 3 chance to play, while the other has a 1 in 3 chance.

This means you could make one have a weight of 99 and one with a weight of 1, to make it rare.
Adding Fidget Animations (wo/ Prefab)
6.14 - Optional
Simmilarly to adding extra versions of animations, you can add animations that randomly play.
At the very bottom of your QC (or at least after the helping hand stuff) add the following lines:
$weightlist empty { "ValveBiped.ValveBiped" 0 } $sequence fidget00 CLIP weightlist empty activity ACT_VM_FIDGET 100 numframes 120 fps 1 $sequence fidget00_layer CLIP weightlist empty activity ACT_VM_FIDGET_LAYER 100 numframes 120 fps 1 $sequence fidget01 a_fidget activity ACT_VM_FIDGET 2 $sequence fidget01_layer a_fidget subtract a_idle 0 delta activity ACT_VM_FIDGET_LAYER 2 $sequence fidget02 a_fidget2 activity ACT_VM_FIDGET 3 $sequence fidget02_layer a_fidget2 subtract a_idle 0 delta activity ACT_VM_FIDGET_LAYER 3

If you have decided to omit the helping hand sequences, you already have the empty weightlist and do not need to add another one.

Swap the CLIP for whatever smd you're using in the $model line.

Let's talk about what these things do for a second.
the Fidget00 and Fidget00_layer are "empty" fidgets.
They are invisible and only needed to balance how often the other fidgets could play.

In the previous section i talked about the activity weights.
The Fidget00 sequences got a weight of 100, to offset the Fidget02 and Fidget03.
Giving the actual fidget sequences a 2/105 and a 3/105 chance of playing, respectively.

The "Numframes 120" at the end of the Fidget00 sequences artificially generate a 120 frame long sequence, without actually having a sequence of that many frames.
The FPS 1 behind this forces the sequence to play one frame a second.

Both Numframes 100 and FPS 1 together means that if the Fidget00 sequences play, (which have a 100/105 chance to play) they would play for 120 seconds.
Because they have 120 frames, playing one of these frames every second.

So how this works is basically like this:
The fidget00 has a 100/105 chance to play. If it does play, no other fidget can play for 2 mins.
After Fidget00 is "done playing" the game rolls dice again to see which fidget will be played next.

You'll want to walk a line of "look at my nice fidget animation" and "this guy's got adhd and can't stand still for a single minute"
Sound & Particle Events
Before you do this, it would advise you to do a first test compile, should you not be entirely sure if you like the animation timing.
If you wouldn't like the timing, you'd have to redo the animation and adjust the timing on the events aswell. So i'd do these dead last.

6.15
By now you probably noticed the "event" lines. on some _layer sequences.


These decide which frame triggers a sound.
On frame 10 it plays "Pistol_Silver.ClipOut".
On frame 34 it plays "Pistol_Silver.ClipIn".
On frame 36 it plays "Pistol_Silver.ClipLocked".

They're very straight forward. Pick a frame and what sound to play.

For a full list of all possible sound events, refer to the Soundevents section in this guide:
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=1483047118

To easily figure out on what frame you should play a sound, you can look at your dope sheet in blender, so look at what frame something happens.

As an example, in this reload animation, the clip bone starts moving on frame 8.


On the insert, i'm using the scrubber to determine when i should play that sound.
Frame 49 will do.


Check all _layer anims that need a sound event and time them.
For example, my reload_empty_layer will use:


Warning:
Keep in mind the timing of the sound event itself.
It is entirely possible that the actual sound you want may play later than the frame you picked.
One upsetting example is the MP5 "Bolt Back" sound. It plays "Bolt Back" and "Bolt Forward".
This stupid little timing difference can cause you to get the sound too late, so you may need to set the triggering frame to a lower number.

Note for melee weapons:
Long story short, for melee weapons you should add the blur attachment events, and whatever sound or particle event, to both the non_layer and _layer sequence.
Thanks to some tomfoolery, it switches where the events should be used, based entirely on the activity name.
But we'll make it easy by just adding the events to both the sequences. Less of a headache.

6.16
Sound events are not the only thing you can have.
You also got shell ejection particle and muzzle flash events triggered the same way.


Info on usable particles is also on the "Animation Lookup Guide"
═══════════════════════════
Viewmodel Compile for HLMV
Before you compile anything, I recommend you to add a "custom content" folder to your game.
This allows you to keep your custom mod stuff apart from the vanilla files.
Which is nice for when you want to flush out all the months old mod files, like textures or these temporary compiles, by just deleting the folder's content.

Here's a guide on how to make this folder:
https://gtm.steamproxy.vip/sharedfiles/filedetails/?id=1507939076

7.0
Open Crowbar.
Head to the "Set up Games" tab and make sure that all the locations for at least the gameinfo, model compiler and the packer tool are set.
Authoring tools must be required for you to even have these tools in the first place.


Check that your $Modelname line uses anything but the default model name.
In my prefab i'm using "!/TEMP.mdl", but you can use whatever you want.


Drag your QC onto crowbar. it should open the Compile tab by default.
Make sure the "Output to" is set to "Game's 'models' folder" and that you are compiling for L4D2.


The compile is done when it tells you it's done.
I'm telling you, because a lot of people ask when it's done.


Here's some common errors you might get:
Error
Reason(s)
ERROR: 'EXCEPTION_ACCESS_VIOLATION' (assert: 1)
• Having too many verticies.
• Armature of mesh and physics mesh do not match in orientation
• Using $removemodel in $lod setup
• Misusing ""FixupLoop"" in a sequence. The numbers are Pre- and then Post- animation. So numbers should be for example -5 and -5. Not 5 and 115.
• Using Perl script generated smd for the proportion trick, which doesn't contain bone location information. Might happen when you want to delete the mesh lines for smaller filesize but also delete the bone information aswell.
• Using N-gon geometry. N-Gon's are faces with many vertices, but no triangles in it. Like an octagon.
ERROR: Too many bones used in model, used X, max numbers Y
Too many bones. No way to fix without deleting bones.
ERROR: Too many materials used, max 32
Self explanatory, isn't it?
ERROR: X - mismatched IK rule
A $sequence with ikrules uses an $animation that has different ikrules.
Fix it by giving both the $sequence and the $animation the same ikrules
ERROR: X - mismatched number of IK rules: "Y" "Z"
A $sequence uses an $animation. One of them has one ikrule while the other has two.
Fix it by giving both the same amount of ikrules. even ifyou jsut will use "Release" on one of them.
Could not load file '$sequence'
• Missing a " somewhere, making the compiler look for a file, thinking $sequence is a filename.
• Event names do not have " and space between it and the }. Example: { event 5004 1 CedaJar.HelpingHandExtend}"
Animation (mostly IK bones) export completely broken
No idea why, but you can fix it by Baking the animation with all checkboxes in "Pose - Animation - Bake Action".
Export the baked animation.
After exporting undo the bake so you get your IK setup back.
No actual fix next to this hotfix has been found. Sometimes blender just breaks.
I got a google spreadsheet with even more errors right here[docs.google.com].
These here are just a few common ones seen on viewmodels.
Model Inspection in HLMV
8
If the compile was successful, load the Authoring tools, and through it the model viewer.


Click on "File - Load model" and find your model with a custom name.



8.1
Click on "File - Load weapon" to load in a set of viewmodel arms.
Yes i know, sounds backwards. They just never bothered renaming the button since HL:S
Head to "Models - Weapons - Arms" and load any of the player's arms.


Note:
Should you get an error about a folder not existing, it's because HLMV is stupid. it can't load any model that is in a pak01_dir.vpk unless you have that folder loosely. Open crowbar's "Set up Games" tab and pess the "Create 'models' folder tree" button.
Warning
This will also read your loaded addons and create subfolders for the models inside addons. Which means if you got a campaign with custom models, you'll have those cluttering your HLMV. You can avoid this by renaming your addons folder before pressing this button, and then changing the name back.

You'll get something that looks like this. A gun without textures and some animation.


You could press this "Normal Mapping" button to turn on normal maps. You'll need it later anyways.


8.2
For now, if the model is not broken looking, open the Sequence tab.


The top sequence is what you usually see first.
Change it to something like deploy_layer. You'll probably see the animation looking weird, like this.


That's because we blended all animations.
To see them properly, you have to arrange the sequence setup like this:

My first sequence is idle. For you it's probably idle_layer.
Pick whatever $sequence blends a_run and a_idle
Second sequence is the one you want to see.
The slider on the right side moved to right and the box checked.

You can also enter "Viewmodel mode" to get snapped into fov camera.


The actual FOV number setting is in the render tab.
The HUD also covers most of the gun though.


Personally I enter Viewmodel mode, click and hold RMB on the middle of the window and drag my mouse down, to zoom out of FOV.

Of course the FOV here is now no longer what you actually see in L4D2 because you zoomed out, but the FOV Helpers in blender gave you enough of an idea what you'll see in L4D2

Now you can cycle through your animations, check if there's anything weird going on.

This slider here is a Speed slider. Allows you to play at any slower speed you want.


The slider down there is a frame scrubber. It allows you to inspect any frame without it moving.
Whatever sequence has that dot on the right side is the one being affected by the sliders.


Viewmodel Compile for L4D2
9.1
Once you've made sure all sequences look okay in HLMV, you can either compile for use ingame,
or do the animation events first, if you had skipped them.

To compile them to use ingame, you first have to swap the $modelname to the original.
You must do this. I repeat. You must.
You must. You must. You must.
You have no idea how many people just don't do this and wonder why their mod's broken.


Then, in the compile tab, set output to "Work Folder" and make a folder somewhere near the qc.
That folder will be your addon, which will then be turned into a vpk.
All your materials, models and other content goes in there.


Press the Compile button.
It will compile the model and automatically create all required subfolders inside your addon.


9.2
Go to that folder you had compiled for and drag it onto Crowbar's "Pack" tab.
Set the "Output to" folder to l4d2's addons folder and press the pack button on the bottom left.
It'll pack your addon directly into l4d2.


After packing, you can start the game and look at the weapon ingame.
Make sure you do not have any addon enabled that replaces the same weapon.

Your addon will not yet show up in the addon menu, because it does not have an addoninfo.txt.
We will make one later, at the very end, before we ship it.

9.3
Now you can test the gun ingame.
Play every animation you can.
Deploy, Fire, Reload, Melee, Item pickup (by looking at an item you do not carry),
Shoot rochelle in her stupid face until she's downed to test the helping hand aswell.
Tip: use nb_stop 1 in the console to stop the bots from trying to help rochelle up.

For the fidget animations you either have to wait for them to play, or temporarily decrease the fidget00's numframes to 1. or increase it's fps to 120. Whatever.

Textures will still be broken, but that doesn't really matter at this moment.
You can skip to making them right now if you want, but I prefer doing them after the worldmodel.



Now you are at the point where you can either adjust your animations or just continue with the worldmodel.

But you might also have some bugs.
Most common bug are your screen turning 90° clockwise, or your hands going all over the place.

If your camera is turning 90°, there's two easy fixes:
  • Deleting the "attach_camera" attachment. This is the easiest fix if you do not want to have any camera rotation in the first place.
  • Rotating the "attach_camera" attachment itself so that it fits. The correct orientation for the attachment in HLMV is "Red line in looking direction, blue line upwards, green line will point left."


    If you want to rotate the attachment, use the "rotation" box until the helper is aligned correctly.
    The copy the content of the "Qc string" box into your qc, replacing the existing attachment.

If the hands go all bonkers it is 99% because you made new $definebone lines with crowbar.
Making new lines creates a different order. That different order causes your glitch.
To get the default back, decompile the original valve gun into a random folder and copy the $definebones from its qc file into yours.
═══════════════════════════
Making Worldmodel
10.1
Now that the viewmodel, the hard part, is done. We can Speedrun Worldmodel%.

In blender, import the decompiled worldmodel. Making sure to use "Make new Armature".


10.2
Duplicate your viewmodel mesh(es) and position them over the original weapon.
Select them, press Shift & D, then move your mouse. Click LMB to place.

Now apply all transforms on the Worldmodel meshes.


Rename your mew meshes to something sensical. I like adding the w_ prefix.

10.3
We have the option to make some parts of the weapon movable.
The clip, the bolt (or slide on a pistol) and the bullets inside the clip.
Although the bullet only works if you got a single bullet in the clip, because it just moves deeper into the clip. If you have an entire clip with visible bullets, it does not work. Like on my gun.


If you want to have these moving parts, you'll need to re-rig your weapon to those bones.

First, Drag your duplicated gun mesh(es) over the armature of the worldmodel to parent them to that armature. just like we did in step 3.5.

Blender 2.8
Select your mesh object
Hold "Shift" and drag your mesh onto the armature.
Let go of the mouse, but keep holding shift.
A "Set Parent To" window will appear. You can now let go of Shift.
Pick "With Empty Groups".

Blender 2.9
Select your mesh object
Hold "Shift" and click on the armature in 3d View, Object mode.
Press Ctrl & P
Pick "With Empty Groups".

You will now have all the viewmodel bones and the worldmodel bones in the vertex groups.
This is on purpose. We'll use this to pick what we already rigged and just rig it to another bone.

i already deleted all but the weapon bones from this view, to make it easier for me.

Interlude:
This section explains how the bolt, slide and pump move during fire and reload.
If you do not care about that, skip to 10.5 and rig the bolt entirely to the weapon bone instead.


The bolt is rigged to two bones at different weights.
that's an ingenious design to make all weapon animations move the bolt by X units back, but the weapon weights determine how far it actually does move.

Explanation of how exactly this works:
If a mesh is rigged to a single bone, that one bone decides all the movement. If a mesh is rigged to two bones, the mesh will be influenced by both bones at once. Whatever bone has more weight, has a larger influence. If the pistol's slide is 50/50 rigged to bolt and weapon bone, the slide mesh will move perfectly in between those two bones and only move half of the distance the bolt bone moves, because the weapon bone is telling it to stay. Yet if the slide is rigged 80% to the bolt and 20% to the weapon bone, then the bolt bone has a bigger say in how much the slide will move.

10.4
In the model's edit mode, find the bone the slide or bolt is rigged to and click "select".


Now the entire slide that you had already rigged is selected again.
Saves time on trying to select all that mesh manually.
Set the Weight slider to .5 for now and rig it with 0.5 weight to weapon and bolt.

It moves here because I made a pose. Which was pretty much useless, as you'll see later.

After rigging the slide, hide it from view for now.

Select the clip and rig it to the clip bone with a weight of 1.
You can rig a bullet to the bullet bone, but it may look odd if you can see into the clip.
in which case you'd need to just not rig the bullets. Which in return makes you see the bullets when taking the magazine out. But to be fair, who pays attention to that one bullet on third person?

After rigging the clip, hide that one too from view.


Now rig all that remaining stuff to the weapon bone.
Then, delete all leftover viewmodel bones from the vertex groups.


10.5
Export the Worldmodel.

Open the worldmodel QC file.
Now we'll do pretty much what we already did with the viewmodel.
Make up a new modelname, copy the cdmaterials from the viewmodel into the worldmodel.
Swap the bodygroup for your model and swap the $sequence to use your model aswell.


There might be a collisionmodel section. I'm not going to make a new one because i don't care.
You can delete the entire collisionmodel section if you don't wanna make a new one.



Worldmodel Attachments
11
Now we gotta compile this for HLMV to inspect it and do the attachments.
Make sure the crowbar's output is now set to "Game's 'models' Folder" agian.

Compile the model, load the worldmodel in HLMV and open the Attachments tab.then

We got three possible attachments.
Not having a flashlight attachment will not show a flashlight and laser.
it will not "stop the laser from making the gun accurate" because there's no laser.
I got a bunch of these comments before.


Move and rotate the attachments how you want them.
Attachment name
Arrangement
Shell
Left Ejection
Blue up-ish, Red left, Green Backward-ish
Shell
Right Ejection
Blue up-ish, Red right, Green Forward-ish
Flashlight
Blue Forward, Red Left, Green Up
Muzzle_Flash
Blue Right, Red Forward, Green Up

After an attachment is set up how you want, copy the "QC string" content into your Qc file.

Worldmodel Tesing in HLMV
12
Load any survivor from the "Survivors" folder. (except teenangst and biker _light)


Load the worldmodel "As Weapon"


Depending on what weapon you have, you'll need to load different animations on the player.
The first sequence must be any of the idles for that gun type.


The second sequence can be the "shoot" while the third can be "reload".


Just like the viewmodel animations, use TheDot™️ and Slider©️ on the right side to pick anims.
The Scrubber® on the bottom can now help you to inspect any frames.
Like checking if the slide moves enough during reload or firing.


Damnit℠
Gotta re-weight the slide.


If this happens to you aswell, go back into blender and adjust the weight balance on the slide.
If it should move more, select the slide and increase the weight of the bolt bone.
If it should move less, select the slide and increase the weight of the weapon bone.

Good enough. I used .5 on the bolt and .6 and the weapon bone.


Now also check if the clip works fine.
You don't have any impact on this. so basically just check if it looks good or not.
Finishing Worldmodel
13
Like the viewmodel, swap the $modelname line on the qc to compile for the actual gun ingame.


Then compile it into your addon "Work folder" aswell.


Followed by packing the addon once more to look at it ingame.


Commence look ingame.


You can bind the following things to keys:
bind "m" "sb_takecontrol"
bind "j" "upgrade_add LASER_SIGHT"
bind "9" "incrementvar r_drawvgui 0 1 1"

Look at any bot, press M to swap to that bot.
Use the "Give" command to give yourself the weapon you want.
Melee weapons are bound to maps. Some maps don't allow katanas or whatever.
TUMTaRA allows all melee weapons

Press J to get the laser
Look back at another bot to swap to them.

Use a sniper rifle, press 9 to toggle the hud and zoom onto the gun in the bot's hand to look at whatever you just did in blender for the last thirty minutes.

Note:
Unfortunately, everyone holds every gun slightly different.
If a gun fitts into Francis' hands nicely, they might not fit nick at all.
Compare how they hold the same weapon for a second.

═══════════════════════════
Making the Textures
Textures consist of two parts.
The textures themselves, which is "what you see" and materials, which define "how you see it".

First, we need the textures themselves.
You have either gotten a model that has some .tga, png or whatever textures, or you made textures yourself in substance painter or whatever.

14.1 - PBR Conversion and other Edits
If you have PBR textures, Open photoshop, load the diffuse and multiply the AO over it.
Source 1 does not separate them like that.


Source 1 also inverts the Green channel on normal maps, compared to PBR and most other uses.

Roughness could be used as envmap mask.
Either as alpha channel in the normal, or standalone.
I use it as alpha of normal mask, which then doubles as phong mask by default.
Envmap masks handle how the (primitive) world reflections are visible.
It can be used to make some parts more reflective and other parts less. Like a dirty mirror, or stratches in the metal that show bare metal under the paint.


Roughness could also be used as phong exponent texture by making the red channel about 125 solid grey, green remains and blue turns black because that's unused.
Phong handles how light bouncess of the model. Very nice for metal.


Here's what I would do with the pbr textures:
PBR Texture
Use in source as
Base Color
Diffuse
Mixed AO
Diffuse (Multiplied over Base Color)
Height
Unused
Metallic
Unused - Could be used as mask to help making envmap masks or phong exponent masks
Normal
Normalmap (Invert G)
Normal OpenGL
Normalmap (Invert G)
Roughness
Envmapmask, Phong Mask or phong Exponent Texture

I can't go into detail here. This guide is long enough as it is.
If you want to learn more about how the envmaps masks and phong stuff works, you can read up on it on the Valve Developr Community wiki.
Envmapmask
Phong

If you are manually editing textures like this, you might aswell just export all materials difectly as a VTF from photoshop or gimp.
In which case you can skip step 14.3 and go to 14.4.

14.2
Go to the folder that will be turned into your addon.
Create the entire material setup jut like the $cdmaterials line you have


I will repeat myself once again.
Materials and textures go in the Materials folder. NOT the model folder.

14.3
Once you have textures that will do the job, convert all of them into VTF using VTFEdit.
It's best to place all textures in the same folder for this.

Load VTFEdit, click on "Tools" and then "Convert Folder"


In the window that pops up, pick "To VTF" and turn "Create VMT files" off.
We will need vmt files, but this will just create too many, for every texture that doesn't need one.
Pick where the textures are, and the new folder we made to place the converted textures there.


14.4
Make a text file with this content:
vertexlitgeneric { $basetexture }
Call it any name that one of your materials in blender has, with a vmt file ending.

Every material needs it's own VMT.


Now we have basic, empty materials.
Change the $basetexture to load the location and file name of the VTF this specific VMT is for.

Location is already inside the Materials folder. Just copy whatever your cdmaterials uses and append the texture name.

You can add normal maps, envmaps and all the other junk you want.


For now though, edit every VMT you have to load at least the required basetexture and normal map, if you have them.


Making the textures look good is up to you.
To have textures show up in HLMV, copy the materials folder from your addon into your "Mods" folder you made in l4d2, before step 7.0


Melee weapon Blood textures
14.5
Melee weapons can have blood overlays.
You can actually make a blood texture of your own or do it like valve, giving every melee the same "generic" blood texture to use.

Simple
Paste this into every VMT file of your melee weapon before the final } to get easy cheesy blood.
$detail "models/infected/hunter/hunter_01_detail" $detailscale "1.75" $detailblendfactor .001 $detailblendmode 0 $detailAmount 0 Proxies { BloodyHands { resultVar $detailAmount } Equals { srcVar1 $detailAmount resultVar $detailblendfactor } }

Accurate Blood
To get a Blood texture that is "accurate" to your melee weapon, you must create an image with the hex color #757575 (RGB 125) where the blood can be any color you want.
The base grey will be overlaid onto your weapon.


How you get that texture is up to you.
You can either use Substance Painter, if you got it, or just paste blood images from google onto your weapon.


Then paste this into your VMT files:
$detail "BLOOD TEXTURE PATH HERE" //Blood texture $detailscale "1" $detailblendfactor .001 $detailblendmode 0 $detailAmount 0 Proxies { BloodyHands { resultVar $detailAmount } Equals { srcVar1 $detailAmount resultVar $detailblendfactor }

Yea and that's pretty much it.
If you feel that your blood texture is too weak or barely visible, you can use photoshop or gimp to overlay the image onto itself numerous times until the blood get nice and dark.

Hud Icon
15.01
The Blender IK & HUD prefab[drive.google.com] comes with a "Render.Blend" file, which is the prefab i made for you to easily create HUD imaged.

Open the "Render" blend file.


Import your weapon SMD file(s).


Delete the armature and and glocks. The glocks are just a visual helper of how it should be.
Then position your weapon to use as much of the camera as you can.
Scale the model if you have to. It doesn't matter.


If you have multiple models, merge them together really quick. it just makes this a bit faster.

15.02
Remove all materials.


Note - Passes and Performance:
This save is set up to rendner with GPU (Graphics card) with 600 AO passes.
Blender 3.0 doesn't have specifically AO passes anymore.
You may add more passes, or use less passes for rendering time.


The Performance setting further below sets how many threads blender is allowed to use.
set it to "Auto Detect" or lower it a lot if you think your pc can't handle it at 24 threads.
Or if you got more or less threads and you want to adjust how many blender uses.


Render dimension:
This setting here are the render dimensions. Change it if you want.
We'll edit the image in Photoshop or Gimp anyways.


Original HUD icons will be about 64x64 pixels or 124x64.
As you can see, my 1080 are a little bit bigger.

That's because we're going to super sample the hud icon, which will make them look nicer,
especially on large screens.
You can change the 100% to 50% to make it smaller if you want. I just like to make it large so i can include this render on workshop images.

15.03
Press F12 to render and wait for it to finish.
Once finished, Save it as uncompressed PNG.




15.04
Go back to the game files, open the update pak01_dir.vpk and export the weapons hud files.
They're in "materials/vgui/hud".
Export them to the same folders within your weapon mod folder.


15.05
Open the VTF in photoshop and upscale it , till the shorter side is 512.
So either 512x512 or 1024x512.
Or smaller, who cares. That's just how i do it.
Making a larger hud icon will increase file size by quite alot. expecially if BGRA8888 is used.
If you don't want large filesize, keep default image resolution.



15.06
Import your render and position it so that the gun fits over the original.
Make sure nothing touches the image's edges.


15.07
Duplicate the render and make the duplicate solid white.
Then add a solid black background, and merge the white gun and black background.


Copy this into the alpha channel.


15.08
Now it is up to you if you want to have the shading of this image, or make it a solid color.
L4D2 uses solid color by default, personally though, I prefer shaded.

If you want it solid color, turn the RGB channel fully white.

If you want shading, enable the other render layer in the RGB channel.
You might have to use the levels tool to make it brighter.


Whatever you choose, save it as VTF without mipmaps.
I prefer BGRA8888 because it's not compressed, which means white actually exports as white.
DXT5 compression turns it blue-ish.

Note:
Sometimes the Photoshop plugin just doesn't save the alpha channel.
In which case you need to open the exported VTF again and add the alpha channel back in.
idfk why, it just does that.
If you exported with DXT5, you'll also notice that the compression turned the vtf blue.
So you'll have to replace that one too.

15.09
If you used larger resolution, Open the VMT file and add this:
$basetexturetransform "center .5 .5 scale X Y rotate 0 translate .5 .5"
This line tells the game to transform the $Basetexture. Scale, rotation and location.

We're using this to downsize the HUD image.
Because unlike models, HUD textures will break if you just make the texture bigger.
If we downsize the texture with the VMT, the texture itself will still have high resolution and look good, but still fitts into the place it needs to fit.

As you may see the Scale uses X and Y. We gotta replace those.
Use the calculator to divide the current VTF scale by the original.
Replace the X and Y by the result.



The "Translate" at the end moves the image horizontally and vertically.
.5 .5 usually works very well, but sometimes you need to nudge it a bit more like .7 .5.

15.10
Anyhow. Save it, pack it up, test ingame.
Sounds
16.01
If you want to make custom sounds, i would recommend you to pack them into a separate mod.
Most people seem to prefer using whatever sound they want.
So you're bound to have someone steal your mod and just reupload it without sounds.

I've made a video guide about this already and i cannot be asked to make a text version.
The video is about making "any" soundmod, but the same thing applies for gun sounds.

Just be aware that most firing sounds are in the left4dead2 folder, while the new "TLS" reload sounds are all in the Update folder.
The dlc1, 2 and 3 also have some sounds, like m60 and golf club sounds, that you could use.
It's best to first check the update folder, then dlc3, dlc2, dlc1 and lastly, left4dead2.
Use the newest available sound for the mod.

Final Testing and Packing
Last thing is to test the weapon a whole bunch ingame.
Make sure everything works the way you want it.


Yah.


One last time, before you are fully finished.
Open the folder that will be your addon.
Create an addoninfo.txt with the following content:
"AddonInfo" { addonversion "1" //Max 31 chars. Allows decimals addontitle "title goes here" //Max 127 chars. addonauthor "author name goes here" //Max 119 chars. addonDescription "description goes here" //Max 1023 chars. // These are the tags shown in the game's addon menu, by which you can filter by. addonContent_Campaign 0 addonContent_Map 0 addonContent_Skin 0 addonContent_weapon 1 addonContent_BossInfected 0 addonContent_CommonInfected 0 addonContent_Survivor 0 addonContent_Sound 0 addonContent_Music 0 addonContent_Script 0 addonContent_prop 0 }


There's also an addonimage.jpg. It would show a thumbnail in the addon menu and that's it.
This file is really weird because it was implemented by people who didn't think this through.
I honestly wouldn't bother making one.

The addonimage.jpeg only works if it is square and when installed manually in the addons folder.
People who download your mod through the workshop will see the workshop thumbnail instead, However, the workshop thumbnail only shows if it is rectangular.
Yet at the same time, rectangular workshop thumbnails look ugly as hell on the workshop.

Just look at this. Valve built it so that the ugly rectangular workshop icons with the black bars work ingame, while the super nice square one on the right won't work, even though the image space inside the game was originally square and still is.




If you still want an addonimage, load any square image into vtfedit to compress it with the default dxt5 compression, but then export it as a jpeg named addonimage.jpeg.
═══════════════════════════
Final words.
It took me a span of two days to write this guide, making the mod you saw at the same time.
I made a thing, took a screenshot and documented it here.
Which implies you should take about the same time if you follow it closely.

Should you need help with making a gun mod, join the "Dead 4 Mods" Discord Server[discord.gg].
There's a few members, including me, who can help you out.
Please for the love of Lucifer, do not join just DM me for help.

I have my own Discord Server[discord.gg] if you'd like to hop in and chat.
I sometimes post WIP images of what i'm doing, but it's mostly memes.

I also got Paypal[paypal.me] for don't-ations.
90 Comments
мяFunreal  [author] 19 Aug @ 1:58pm 
Yes. this works for every single weapon in the game.
Y-17 19 Aug @ 1:56pm 
Does this all work the same for grenade replacements (pipebomb, molotov, bilejar)?
мяFunreal  [author] 1 Aug @ 9:22am 
it's the same process for every game, except the model location and bone setup are different.
If you want a guide on just replacing generic models, i got a whole different guide on making props.

If you specifically want to make tf2 weapons, its the same as this, but you first need to find out whatever mdl your gun is that you want to replace, and then make your own ik setup and jank because i got none for tf2 and i won't make one either.
lordjaga1773 1 Aug @ 6:57am 
how i can replace animations and models from another game like tf2?
мяFunreal  [author] 15 Jul @ 2:55am 
Well it is a L4D2 guide, is it not?
But the basic procedures of decompiling the weapon, importing, rigging, animating, exporting and compiling is the same process.

Except css doesn't have helping hand anims and the weapon is set up differently.
Meaning you can not use the prefab. But if you are able to adapt this info, you'll figure out how to make guns for css
HostID ツ 6 Jul @ 7:52am 
Ok thank you
мяFunreal  [author] 6 Jul @ 2:43am 
the same idea works for all games, but the viewmodel prefab is only for l4d2. Gmod has different bones.
HostID ツ 5 Jul @ 7:03pm 
Hi! Firstly, thank you for the amazing tutorial and secondly, do this only work correctly for L4D2? I've been trying this tutorial on Gmod and the thumb is all f*cked up (It's like all twisted) so I've been wondering why and can't find an answer. Thank you in advance
мяFunreal  [author] 3 Jul @ 9:44am 
Of course. You open blender saves with blender.
DOOMGUY 3 Jul @ 8:49am 
By using Blender itself?