Animating Weapons for Counter-Strike Source/Testing Animations

From Wikibooks, open books for an open world
Jump to: navigation, search

You've made an animation, but it's improtant to ensure it looks correct in-game.

  • In the default folder, find mdldecompiler.qc and copy and paste it to the tocompile folder.
  • Replace the first line in the new mdldecompiler.qc with this:
$cd ".\"

This tells the compiler to look in the current directory for the SMD files.

Note:
The idle animation is not as long as the other animations. For this reason you will need to temporarily adjust the timing of the sounds so they do not play at a nonexistent frame.

Adjusting the Timing of the Sounds[edit]

  • Find a line that begins like this:
{ event 5004
  • After 5004 you will see a number. Change the number to a number from 0 to 15 for each line. A number from 0 to 15 is used because the idle animation goes from frame 0 to frame 15.
  • Save the QC file. Do not close it yet.

Copying and Pasting Animations[edit]

  • Count how many times $sequence is typed in QC file.
  • Subtract one (for the idle animation.)
  • Copy and paste idle.smd that many times.
  • Rename the SMD files to whatever word comes after $sequence in the QC file. (e.g. shoot1, reload, draw)
  • Save the QC file. Do not close it yet.

Converting the Textures to Targa Format[edit]

  • If your textures are already in TGA format skip this.
  • Open IrfanView.
  • Open each texture.
  • Go to File>Save as and save as a Targa (.TGA) file.
  • Put these Targa files in a folder called lr300.

Note:
If you are animating a different weapon make the folder name meaningful.

  • Make a .bat (text) file with the following code:
cd %sourcesdk%
cd ..\
cd .\counter-strike source\cstrike\materials\models\weapons\v_models\
start .\
  • Execute the batch file. Now you will see your materials folder for first person view models. Keep this folder open for later.

Converting the Textures to VTF Format[edit]

  • Find vtex.exe. Is located in %sourcesdk%\bin\ep1\bin\
  • Make a new text file somewhere (with .bat at the end) and write the complete location of vtex.exe in quotes in the first line of the batch file. Now edit it is similarly to the following:
cd .\
"C:\Program Files\Steam\steamapps\username\sourcesdk\bin\ep1\bin\vtex.exe" -shader VertexLitGeneric .\*.tga
  • Save it in the lr300 folder.
  • Move the lr300 folder to
\your username\sourcesdk_content\cstrike\materialsrc\models\weapons\v_models\
  • Double click the batch file and the window opened earlier should have a folder called lr300 with the textures and VMT files in it.

Finalizing the QC[edit]

  • Open the QC file if it is not open already.
  • Find all of the lines that begin with $hbox. Delete them.
  • There should still be a line that says $hboxset "default". Keep it. This lets the engine compile the hitboxes for you.
  • Find a line beginning with
$model "studio" "[something].smd"
  • Rename [something].smd to the gun's smd file.
  • Add a line after this line
$cdmaterials "models\weapons\v_models\hands\"

with the following text:

$cdmaterials "models\weapons\v_models\lr300\"
  • \lr300\ should be replaced with whatever folder name you gave the materials earlier.
  • Find all lines that begin with $attachment.
  • Replace the phrase in quotes (in the $attachment lines) with the name of the bone of the weapon. (In this tutorial it would be ValveBiped.Frame.)
  • Save the QC and close it.
  • Right click the QC and click Compile.
  • The QC should compile successfully.
Warning The QC may not compile successfully. Check any errors studiomdl.exe gives you and post them on the talk page for help.

Testing Animations in the Game[edit]

  • Open Counter-Strike Source
  • Create a server.
  • Buy the weapon you are animating to test it.
  • There are smoothing errors in certain lighting conditions; we will fix those later.
  • Turn on cheats using the console command sv_cheats 1.
  • Here are a few cheats you can play with:
    • cl_drawhud 0 - disables HUD, good for recording videos and taking pictures
    • give weapon_sg552 - give a weapon. sg552 can be replaced with other weapon names
    • impulse 101 - refill ammo and money
  • Take some pictures by pressing F5. The pictures will end up in cstrike\screenshots\map_name####.jpg
  • Share these pictures and get some feedback! The idle animation should be perfected before starting any other animation.

Adjusting the Origin of the Animations[edit]

  • You can make a minor adjustment to the model without editing the SMD files. It is called setting the origin.
  • To do this, open your QC file.
  • After the $cd line, add a new line.
  • Enter the following:
$origin x y z
  • Replace x y and z with numbers that depend on which way you want the model to be offset.
  • Refer to this picture to see how origins work. Changing Origins


Animating Weapons for Counter-Strike Source
Idle Animation Testing Animations Shoot Animation