GameBanana shows no ads to members. Sign up now!
Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Compiling a L4D viewmodel

A Tutorial for Left 4 Dead

A tutorial on how to compile weapon/view models for Left 4 Dead.

Allright, in this tutorial we're going to decompile, recompile and replace a default viewmodel with a custom one. Keep in mind, just like with custom materials, custom models will only work in single player or on non-dedicated servers. Don't blame me, this is Valve's doing. I'm going to compile a mini Uzi released by modderfreak for CS:S for the ... Uzi. Personally, when I'm working on something I like to know how everything works, that's why I'm going to add some explanations (in yellow) on some things, you don't have to read them to complete this tutorial but only if you want to know why something happens.
This tutorial is for intermediate to advanced users. If you have trouble compiling a CS model, you'll probably have a lot of trouble with some of these steps.

Things you should know

- You have to know the basics on how to compile a weapon model, assign vertices to bones, etc. I'm not going into too much detail here. If you do not I suggest you read a tutorial on compiling models for HL2/CS:S first. - It's a plus if you understand the content of qc and smd files and the way a skeleton works, if you don't then there might be a few steps you won't understand. - English. Once I start writing I don't stop so I'm sure this will become a wall of text. My apologies for that.

Tools you need

- Notepad++, an improved version of notepad ( Download link ) - mdldecompiler ( Download link ) - Milkshape 3D ( Website ) - Gibbed's vpk extractor ( Link ) - At least 1 game compatible with the Source SDK

1 Preparations

First things first, we're going to make some preparations.

1.1: Extracting the default models

Open Gibbed's Vpk Extractor, use it on the pak01_dir.vpk file in your left4dead folder and extract it to that folder as well. Now you have all the original models, materials, etc in their respective folders.

1.2: Editing whitelist.cfg

First of all we have to allow the game to look for custom stuff in the models folder. Open the file whitelist.cfg in your left4dead folder in notepad. Somewhere under the line: // Additional files/directories to allow Add this: "add" "models/*.ani" "add" "models/*.mdl" "add" "models/*.vtx" "add" "models/*.vvd" Free Image Hosting at www.ImageShack.us
This tells the game to look for custom ani, mdl, vtx and vvd files in the models folder. Save the file and close it.

1.3: Duplicating the arm model files

Go to your left4dead/models/v_models folder. Select the arm model files and copy them to the same folder. If you're not sure, these are the files you need to copy: v_arm_manager.mdl v_arm_manager.vtx v_arm_manager.vvd v_arm_namvet.mdl v_arm_namvet.vtx v_arm_namvet.vvd v_arm_teengirl.mdl v_arm_teengirl.vtx v_arm_teengirl.vvd v_arm_biker.mdl v_arm_biker.vtx v_arm_biker.vvd Now rename all of them, give them a logical name, I'm compiling an Uzi so I'm going to add _smg behind the name: for example v_arm_manager_smg.mdl. Do this for all of them. Explanation: But why are we doing this you might ask. Well, in older Valve games a viewmodel including the arms was 1 mdl file. Since the TF2 patches Valve seems to prefer to make the arms a seperate model to be used with all weapons and the weapon models as seperate mdl files. This way the arm model only needs to be loaded once. In order to get a compiled model to work correctly, we have to mess around with some bones further on in the tutorial. Say we have our compiled model with edited bone info ingame and we switch to a weapon which is still a default one, the game will appearantly keep the old skeleton information in mind and try to adjust the model of the new selected viewmodel to the skeleton info of the previous viewmodel. This causes serious errors in the arms when switching between weapons. Since we can't properly compile a viewmodel without changing some bone values we're going to do this the old fashioned way and use a set of arms for each custom viewmodel.

1.4 Editing the weapon_script file

Go to your left4dead/scripts folder and open the script file of the viewmodel you want to compile in notepad, in my case here weapon_smg.txt. Scroll down until you see this piece of text: "viewmodel" "models/v_models/v_smg.mdl" "CharacterViewmodelAddon" { "NamVet" "models/v_models/v_arm_namvet.mdl" "TeenGirl" "models/v_models/v_arm_teengirl.mdl" "Manager" "models/v_models/v_arm_manager.mdl" "Biker" "models/v_models/v_arm_biker.mdl" } Again we're going to do some renaming. Rename the arm model files to the same name you gave them in the last step. Now change the name of the weapon model to something logical as well. In my case I've changed this to: "viewmodel" "models/v_models/v_smg_custom.mdl" "CharacterViewmodelAddon" { "NamVet" "models/v_models/v_arm_namvet_smg.mdl" "TeenGirl" "models/v_models/v_arm_teengirl_smg.mdl" "Manager" "models/v_models/v_arm_manager_smg.mdl" "Biker" "models/v_models/v_arm_biker_smg.mdl" } Free Image Hosting at www.ImageShack.us This tells the game where to grab the viewmodel and which arm models to use. Save the file and close it.

1.5 Creating your compile folder

When you compile a model for a Source game, it automatically places that model in the correct folder. L4D doesn't have an SDK so we're going to have to make a folder for it in another game's directory. Create a v\_models directory in the model folder of the game of your choice. I'm using the Orangebox studiomdl so I'm using team fortress 2/tf/models/v\_models. You can do this in your HL2 or CS:S folder as well. Explanation: This is kind of important, the folder you compile your qc file to has to match the place of where the mdl will be in the models folder. If you open a mdl file with Notepad++, on the first line you'll see the folder to where the qc file was compiled. If this doesn't match the eventual location, for example you compiled it to models/spota but you eventually place the mdl file in left4dead/models/spotb then your viewmodel won't show up ingame and your console will be spammed with checksum error warnings.

1.6 Copying the animation models

Go to your left4dead/models/v\_models folder and look for the animation files, in my case anim\_v\_smg.mdl and anim\_v\_smg.ani. Copy them to the compile folder you made in step 1.5. We'll need them later.

2 Decompiling

Copy the mdl, vtx and vvd files from the model you want to replace somewhere. Open the mdl file with Notepad++, on the first line you'll something that looks like this: IDST1[NUL][NUL][NUL]£¸Ñ“v\_models\v\_smg.mdl Replace the 1 after IDST into a comma, IDST, Save the file and close it. Copy the vtx file, in this case v\_smg.vtx, rename the copy to the DirectX 8 file. In this case v\_smg.dx80.vtx. Now use mdldecompiler to decompile the mdl file. Have the 2 top boxes in mdldecompiler checked. If you want a very detailed description on how to decompile a L4D model then I refer you to a tutorial written by £cho ( Link ), just ignore the known issues. Now decompile the replacement model.

3 Combine the refs and prepare for compiling

3.1 Doing the Milkshape stuff

I assume you already know how to do this but here's the quick rundown. In Milkshape 3D import the ref file of the default model you decompiled, import triangles and skeleton. Go to the Joints tab, look which vertices are attached to which weapon bone and write it down. Now place the new model over the old one, assign the parts of the new model to the right bones and delete the old model. Export as smd, give it a new name, newref.smd for example. Copy the materials of your replacement model somewhere in left4dead/materials/models/.

3.2 Editing the qc file

Edit the $modelname line to the name that you wrote in the weapon script file. In my case this becomes: $modelname "v\_models\v\_smg\_custom.mdl" Change the $cdmaterials line(s) to whatever folder you placed the replacement model's materials in. Explanation: Notice the $includemodel line. This is why we had to place the animation files in the compile folder, when we compile this qc file, it will include the anim\_v\_weapon files we copied there earlier. Without those our viewmodel wouldn't have any animations.

4 Compiling and problem solving

If this wasn't a L4D model you'd be done by now, you could just compile the model and be done with it. If you were to compile it now, you'd probably get a warning in the compile log (bounding box out of range) and your weapon wouldn't be visible ingame. Sometimes people don't get the warning but the problem is still there. So lets fix that.

4.1 Fixing the weapon's position

There are 2 (well 3) animation smd files. Open anim_cancel.smd in Notepad. First you see the list of weapon bones, the first number is the ID, then comes the bone's name, then the ID of it's parent. Ignore it and scroll down. Then you'll see something like this: time 0 0 3.698241 0.000000 0.000000 0.000000 -0.000000 -0.015830 1 5.700890 -0.000000 0.000000 0.000000 -0.000000 0.495179 ... Explanation: This is the animation itself, in text form. time 0 means frame 0, this is the first frame of the animation. Under that is a number followed by 6 values. The number is the bone ID, the next 3 values are the X, Y and Z position of that bone, the last 3 values are the X, Y and Z rotation of that bone (also known as roll, pitch and yaw in the industry). So by changing these values we can edit the entire skeleton if we'd want to. The error is "bounding box out of range" which means that a bone(s) in the animation has a wrong position. We have to look for values that are out of place or look strange. You don't have to look, I'll tell you, it's always the same one for L4D viewmodels, bone 44 which is the main weapon bone. Free Image Hosting at www.ImageShack.us See how the second value is 1400+ while all the others are below 15? This is the reason why we can't see our viewmodel on the screen when we're ingame, the model is there but it's being rendered so far away from us that we can't see it. So lets fix that. Open the reference file in notepad, in my case v\_smg\_uzi\_reference.smd. You'll see something similar to the anim\_cancel.smd file. Go to the line of bone 44, it should look more like this: 44 0.000000 0.744264 2.049373 0.000000 -0.000000 0.000000 These look like more normal values. Replace the broken value in anim_cancel.smd by the value in the reference file. Do NOT replace the entire line, don't fix what ain't broken, only replace the broken value with the value in the reference smd file. Scroll down in the anim_cancel.smd file, to time 1, the second frame in the animation. Fix the broken value here as well. Now open cancel.smd, do the same fix here, replace the broken value in bone 44. Save both smd files and close them. Now if we compile the qc file and you've done everything I've written down right, then you should now be able to see your custom viewmodel ingame, but with some bugs. See how weird the hands are? They're all stiff and frozen. Lets fix that. Explanation: Why is this? If you open the model in HL Model Viewer and go to the Bones tab and look in the bones list you'll see why. A whole bunch of bones is missing, the finger bones. So obviously all fingers are now assigned to the hand bone which is why they don't move.

4.2 Fixing the finger bones problem

Right now when you compile your qc file, the finger bones won't be included, it's as if studiomdl "forgot" them. So we just have to let studiomdl "remember" them then. The easiest way to do this is through the qc file. We need a qc command that uses the finger bones, if they are used for something then studiomdl has no other choice than to include them. I decided to use the $bonemerge command. In your qc file, add this, preferably under the last $sequence command: $bonemerge "ValveBiped.Bip01_R_Finger42" $bonemerge "ValveBiped.Bip01_R_Finger32" $bonemerge "ValveBiped.Bip01_R_Finger22" $bonemerge "ValveBiped.Bip01_R_Finger12" $bonemerge "ValveBiped.Bip01_R_Finger02" $bonemerge "ValveBiped.Bip01_L_Finger42" $bonemerge "ValveBiped.Bip01_L_Finger32" $bonemerge "ValveBiped.Bip01_L_Finger22" $bonemerge "ValveBiped.Bip01_L_Finger12" $bonemerge "ValveBiped.Bip01_L_Finger02" Save and close it. Explanation: So what does this do? The $bonemerge command is sort of a signal that tells the gamecode the bone will be used for bone merging. I chose to use this command because it doesn't need any extra values that could screw things up. The tip finger bones don't have any attachments so no harm is done with this command. But why these 10 bones, there are more than just 10 finger bones, why not use the $bonemerge command on those too you may ask. Well, FingerX2 is the tip of that finger, because of the $bonemerge command studiomdl notices it and has no other choice but to include that bone. The tip of the finger bone doesn't just float, it has a parent bone, which has another parent bone, which links to the hand. By including the tip of the finger, studiomdl has no other choice but to include that bone's parent as well, and that bone's parent. So all we need to make studiomdl "remember" is the tip of the finger and then it will "remember" the entire finger. This is my final qc file. Free Image Hosting at www.ImageShack.us

4.3 Lets compile

Congratulations, you've fixed the problems that made compiling L4D models such a pain. Easy enough when you know how right. So just compile your qc file. In your compile folder, copy the newly created .dx90.vtx file, in my case v_smg_custom.dx90.vtx, and remove the dx90. from the filename, which makes for me v_smg_custom.vtx. Now copy all 6 files to your left4dead/models/v_models/ folder. If you've done everything as in this tutorial you should now have a working custom viewmodel ingame. Look at the tutorial's screenshots for my result. NOTE1: When you release a custom model, don't forget to add the arms and the weapon script file to your download. NOTE2: If you play online on a dedicated server with a custom viewmodel, the ams will be missing and the default model will be there. If you release a custom model, be sure to tell the people that they should backup their original weapon script file and switch it back in their scripts folder if they want to play on a dedicated server. Don't blame me for this, Valve had to put the viewmodel path in the same place as weapon damage and mag capacity... For a playable example check my SoulSlayer/Kimono M4 release Good luck.

Extra: compiling a world model

Compiling a w_ model doesn't require any fixes, just do the same preparation process and compile it as if you'd compile a HL2 w_ model. You may or may not have to rotate the physics model by 90° to match the weapon. A world model will appear in other player's hands, on their back or on the ground if they die. The world model doesn't replace the weapon you can pick up on the tables. This isn't a problem with the model, the game still takes the mdl from the vpk files for that.
Sign up to access this!
1-10 of 16
1
Pages
  • 1
  • 2
Go to page:
  • Campin Carl avatar
    Campin Carl Joined 13y ago
    Offline
    1,735 points Ranked 21,928th
    8 medals 1 rare
    • 6 years a member Medal icon
    • Reached 1,000 Points Medal icon
    • 1 post awarded Exemplary Feedback Medal icon
    • One month a member Medal icon
    • 6 months a member Medal icon
    • 1 year a member Medal icon
    11y
    Ok, I've managed to compile a V_ now, but please for the sake of others, fix those pictures. This is a very handy guide, but those 2 pictures seem crucial. Can you please fix the two broken pictures, so I have less guessing to do when doing my first L4D V compile.
    I'm never useful avatar
    Mantra
    I'm never useful
    URL to post:
  • I have a problem - Whenever i compile a model, install it an launch the game, I get an error saying MDL Cache: Failed load of .vtx data for v_rifle_custom I rnamed v_rifle_custom.dx90.vtx to v_rifle_custom.vtx like you said. If I get the rifle I just see my hands but no gun. Any help?
    Bananite
    URL to post:
  • Xezium avatar
    Xezium Joined 12y ago
    Offline
    12y
    How would I go about rotating the physics model 90 degrees to fix the world model exactly? :)
    Bananite
    URL to post:
  • The Church avatar
    The Church Joined 13y ago
    Offline
    408 points Ranked 49,889th
    12y
    OFF TOPIC : I can't get MDLdecompiler to install for some reason. Anyone know why? On Topic: Awesome- but you could give more explination how to fix the wees
    HNNNNNNNG
    URL to post:
  • StephanBotha avatar
    StephanBotha Joined 13y ago
    Offline
    100 points Ranked 78,507th
    12y
    Pros: Detailed. Cons: Will probably change once the SDK is out
    Bananite
    URL to post:
  • Realbout avatar
    Realbout Joined 14y ago
    Offline
    12y
    Oh. i fixed. the problem is not position or model error. i give vertex weights on older Milkshape version. it makes problem on the vtx weights Anyway. thanks for your help. i love you :)
    Bananite
    URL to post:
  • Snppls avatar
    Snppls Joined 13y ago
    Offline
    4,421 points Ranked 1,723rd
    12y
    Posted by Realbout I do that steps but my gun is invisible :( only hands wow jedi force what's the problem?
    2 possibilities. Or you did something wrong in step 4.1 while editing the smd files in notepad. Probably forgot to fix a value or changed something you shouldn't have. Or you compiled the model to a different folder or under a different name than the eventual result in the $modelname line in the qc file. Start up your game with the -console setting and start a map from the console. When you're ingame, pick up the weapon you compiled and look in the console. If your console gets spammed with "error checksum" then it's possibility 2. If not, you made a mistake in step 4.1
    Whatever...
    URL to post:
  • Realbout avatar
    Realbout Joined 14y ago
    Offline
    12y
    I do that steps but my gun is invisible :( only hands wow jedi force what's the problem?
    Bananite
    URL to post:
  • SinFuL avatar
    SinFuL Joined 13y ago
    Offline
    33,012 points Ranked 147th
    15 medals 2 rare
    • 6 years a member Medal icon
    • Submitted 50 Maps Medal icon
    • Reached 1,000 Points Medal icon
    • Reached 2,500 Points Medal icon
    • Reached 7,500 Points Medal icon
    • Reached 25,000 Points Medal icon
    12y
    Valve I beg of you to release the SDK already!
    This quote's a spy! avatar
    Mantra
    This quote's a spy!
    URL to post:
  • Snppls avatar
    Snppls Joined 13y ago
    Offline
    4,421 points Ranked 1,723rd
    12y
    Posted by JR-jester Any chance i could get the uzi :P ?
    Sorry no. I got permission to use it for the tutorial, not to release it.
    Whatever...
    URL to post:

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Key Authors
Snapples
Unknown

Submitter

Snppls avatar
Snppls Joined 13y ago
Offline
4,421 points Ranked 1,723rd
Snppls
Creator
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

Details

Difficulty Level
Advanced

Attributes

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • 1
  • 29.1k
  • 17
  • 12y
  • 8y

More Other/Misc Tutorials