by Hl2 world
Setting Up
Things your going to need for this tutorial.
1) GCFScape (Opens your GCF Files)
2) Cannonfodder's awesome MDL decompiling tool. (version 0.1a for this tutorial. Rotation is broken in 0.2a but if there is a fixed version get that.)
3) Chris Cookson's SMD import script for max.
4) Any SMD exporter that works with your version of max.
Install all that stuff as is explained in the instructions that come with them.
Getting the MDL Files
1) Close steam, you wont be able to open the GCF files otherwise.
2) Open counter-strike source share.GCF in your steam/steamapps/ directory. Go to cstrike/models/weapons/ and find an appropriate v_ model for the weapon you want to replace and export the files into a temporary directory somewhere. It really dosn't matter where.
3) After you export the files make SURE you close GCFScape. Open Steam up and make sure its running fine. If you leave GCFScape open valve thinks the GCF file you have open is corrupt and bad things happen. ;)
4) Open the MDLDecompiler and select the MDL you want to export. Then define the path you want to export the smd's into. I usualy make a directory inside of the directory where the MDL is and call it "source files". Select that directory from the decompiler and click Extract.
Setting Up for Compile
You should now have the SMD files and a nice little QC generated for you.
1) Create a batch file in your smd folder and call it something like compile.bat. Here's an example batch file.
@"c:\program files\valve\steam\steamapps_SteamUserName\sourcesdk\bin\studiomdl.exe" -game "YourGameDIR_" mdldecompiler.qc pause
if you are using steam installed in its default path change SteamUserName to your steam user name and YourGameDIR to your mod's directory (where your gameinfo.txt is). Follow my Static Models tutorial to create a mod directory system.
2) Remember, since we are replacing a weapon in CS:S your animations will be fairly limited. For the tutorial i'm just going to show you how to get your weapon into the animations. Open the mdldecompiler.qc file with notepad in your source directory with all the SMD files. You should see something like this.
$cd "...Path where you exported to..." $modelname "weapons\vpistdeagle.mdl" $body "studio" "deaglereference.smd" $body "hands" "handsreference.smd" $cdmaterials "models\weapons\Vmodels\pistdeagle\" $cdmaterials "models\weapons\vmodels\hands\" $attachment "1" "vweapon.DeagleParent" 0.00 2.75 6.50 rotate 0.00 0.00 0.00 $attachment "2" "vweapon.DeagleParent" 0.00 2.90 0.00 rotate -10.00 -180.00 0.00 $surfaceprop "default" $sequence idle1 "idle1" ACTVMIDLE 1 $sequence shoot1 "shoot1" ACTVMPRIMARYATTACK 1 $sequence shoot2 "shoot2" ACTVMPRIMARYATTACK 1 $sequence shootempty "shootempty" ACTVMDRYFIRE 1 $sequence reload "reload" ACTVMRELOAD 1 $sequence draw "draw" ACTVM_DRAW 1
3) During decompilation the QC file looses its "Event triggers". These are the frames that trigger events to happen like a shell flying out or a muzzle flash. Also during recompilation the model gets rotated 90 degrees on the Y axis so we'll have to fix that too. Go back through the $sequence lines and change them to something like this.
$sequence idle1 "idle1" ACTVMIDLE 1 rotate -90 $sequence shoot1 "shoot1" ACTVMPRIMARYATTACK 1 rotate -90 { event 5001 1 7 } $sequence shoot2 "shoot2" ACTVMPRIMARYATTACK 1 rotate -90 { event 5001 1 5 } $sequence shootempty "shootempty" ACTVMDRYFIRE 1 rotate -90 $sequence reload "reload" ACTVMRELOAD 1 rotate -90 $sequence draw "draw" ACTVMDRAW 1 rotate -90
This rotates all of the animations -90 degrees. { event 5001 1 7 } tells the engine to place a muzzle flash at attachment 1 and draw it from frame 0 to frame 7. However long you think looks best is up to you. The events are the same as hl1 so if you look up the old SDK documentation you'll find a list there I'm sure. (Thanks for the info Prall)
4) You probobly won't want to put your textures in the same place as the original weapons textures so make your own directory in models\weapons\v_models\ and call it whatever you like. Make sure you change the $cdmaterials line. Example:
$cdmaterials "models\weapons\Vmodels\pistdeagle\"
to
$cdmaterials "models\weapons\Vmodels\pistmyweapon\"
and compile the textures just like you would for a static model.
5) Backup your WeaponName_Reference.SMD and open 3d studio max.
Importing and Exporting the SMD
1) If you install the SMD importer script as told to you by the instructions you should be able to go to the utils tab click on the MAXScript button. Click on Run Script and find where you put the SMD importer script. There will be a drop down box under the "Utilities" text. Click the down arrow, select "Half-Life SMD Importer" and the little window opens up under the drop down box. Click Import SMD and select WeaponName_Reference.SMD. Don't mess with the hands SMD unless you want to replace them. I wont cover that.
2) You should now have JUST the weapon model and all the bones in max. Click File->Merge and open your model file for the weapon you want to use. Set your model up just like you would a static, textures and everything. Click on the weapon model you are replacing and hit alt-x. This sets the model to a transparent see-through mode. Make sure you have edged faces enabled so its easier to see. Rotate, Scale, and Position your model in the right place according to the old weapon model. Delete the old one once you are sure your new model is just right. Make sure your model is one big object. It can't be in pieces.
3) Apply a physique modifier to your model. Click "attach to node" like you would a static model and assign it to the vweapon.WeaponNameParent bone. If you can't attach the parent bone to your weapon please refer to the section below (Weapon Fixes). When the Physique initialization dialog comes up set "Vertex link assignments" to "Rigid". Then set "Blending between links" to "No blending". Click on Link settings near the top of the window and uncheck "Continuity". If you don't you'll have all these nasty curved bones. Click initialize.
4) If you your weapon has moving parts assign them to the correct bones, just check the names. I'm not going to cover assigning verts to bones in depth here. I may write another tutorial later on. For now click the plus next to Physique in the modify tab. Select the Vertex setting and then select all of the verts on the model. Click assign to link, click on the green +, and click on the parent bone. If you get lost, again, read the static models tutorial.
5) Make sure you have all your textures applied and everything is setup. Also make sure you dont have any hidden objects or something that isn't included in your physiqued model or things will get screwy. Go to file->Export and export as a reference over the same SMD you imported. You backed up your file right? ;)
6) Run the batch file you created eariler. It should compile no problems. If it has errors you probably need to look at your model and make sure your textures are assigned correctly (as a multi/sub-obj) and your model is fully physiqued.
7) Just to check the model open hlmv and select the newly created MDL. Select Options->Viewmodel mode to see how your model is going to look in game. Usually my models are a little further back in hlmv than they will be in hl2. So this is just to test your model slightly to see if its going to show up in game. The true test is accualy loading it into CS:S.
Weapon Fixes (ex. p28)
Oldfaq pointed out there was a problem while importing the p28. This is caused by the joints not being connected together so max dosn't have a bone to assign the model to. I dont know how many other weapons this affects but here's the fix if you run into the problem.
1) Go to the Create tab, click on the systems button (the icon that looks like gears) and click bones.
2) Click on vweapon.p228Parent, drag the bone out untill you get a simple short bone like the one in the picture below, and click again.
3) In the physique modifier click attach to node and click on vweapon.p228Parent. Export the SMD and compile. That should fix it!

Replacing the old MDL file
Go to YourGameDIR/models/weapons/ and copy the newly created MDL. It should be named the same as the MDL you want to replace in CS. Go to where you installed steam and put the mdl file in
SteamApps_SteamUserName_\counter-strike source\cstrike\Models\weapons
put your compiled textures in whatever you changed your $cdmaterials path too. For example:
$cdmaterials "models\weapons\Vmodels\pistmyweapon\"
so create
SteamApps_UserName\counter-strike source\cstrike\materials\models\weapons\vmodels\pist_myweapon\
and put your VTF and VMT files there.
Load up CS:S and enjoy!












