Importing CSS Weapons Into HL2: Difference between revisions
Line 104: | Line 104: | ||
$cd "C:\Documents and Settings\Administrator\Desktop\Decompiled Models" | $cd "C:\Documents and Settings\Administrator\Desktop\Decompiled Models" | ||
$modelname "weapons\ | $modelname "weapons\v_357.mdl" | ||
$model "studio" "ref.smd" | $model "studio" "ref.smd" | ||
$cdmaterials "models\weapons\V_models\SnuffyColt\" | $cdmaterials "models\weapons\V_models\SnuffyColt\" | ||
Line 143: | Line 143: | ||
Now we have to check its got in the game ok, to do this go back to the Half-Life model viewer and go to 'File, Load Model' and select the v_357.mdl found in the weapons folder as this is what we have compiled our custom weapon to replace. | Now we have to check its got in the game ok, to do this go back to the Half-Life model viewer and go to 'File, Load Model' and select the v_357.mdl found in the weapons folder as this is what we have compiled our custom weapon to replace. | ||
The model should load with textures but you'll notice that the hands are untextured and in a weird checkered pattern, this is because we haven't installed the CSS hand textures yet. To do this extract the hands materials found in counter strike source shared.gcf using GCFScape and place the 'hand' folder into your mod directory (C:\Program Files\Steam\SteamApps\sourcemods\MODNAME\materials\weapons\) now refresh Model Viewer by pressing F5 and viola! The Hands are textured. | The model should load with textures but you'll notice that the hands are untextured and in a weird checkered pattern, this is because we haven't installed the CSS hand textures yet. To do this extract the hands materials found in counter strike source shared.gcf using GCFScape and place the 'hand' folder into your mod directory (C:\Program Files\Steam\SteamApps\sourcemods\MODNAME\materials\models\weapons\hands) now refresh Model Viewer by pressing F5 and viola! The Hands are textured. | ||
------------------------------------------- | ------------------------------------------- |
Revision as of 02:07, 10 November 2007

For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

(There will be a video tutorial soon for implementing your own custom player models and importing weapons)
So here's the solution, I'll try to make it as informative as possible:
Requirements:
- Cannonfodder's MDL Decompiler
- Ability to Compile the Source SDK
Importing the Weapon
First things first is to get the necessary models you want to use - For this tutorial im going to use the v_pist_deagle.mdl from Counter-Strike.
First of all Install the MDL Decompiler to your sourcesdk/bin directory which can be found in C:\Program Files\Steam\SteamApps\USERNAME\sourcesdk\bin if you installed to Steam to the default location.
Open the Source SDK via the Steam Games Menu and select your mod in the drop down list and open the Half Life Model Viewer, this tool will become very useful for checking you have the model installed correctly. Now you can close the SDK menu.
Install or Extract your CSS model to your Mod location the same way that you would install a custom model for Counter-Strike and then open MDL Decompiler, once open you can select the model you want to decompile, in this case 'v_pist_deagle.mdl' located in the models/weapons directory and then select the Output directory eg. C:\Documents and Settings\Administrator\Desktop\Decompiled Models. Now select 'Extract' and you will recieve two messages telling you that 1, the Model is loaded and 2, the smds have been dumped in your output directory, all is well.
Go to your output directory and you will find your extracted files, one of these should be a .qc file named by default as mdldecompiler.qc. Open this file up and it should look something like this:
$cd "C:\Documents and Settings\Administrator\Desktop\Decompiled Models" $modelname "weapons\v_pist_deagle.mdl" $model "studio" "ref.smd" $cdmaterials "models\weapons\V_models\SnuffyColt\" $cdmaterials "models\weapons\v_models\hands\" $hboxset "default" $hbox 0 "Bone L hand" -2.514 -0.983 -1.390 0.161 1.207 1.380 $hbox 0 "Bone L thumb mid" -1.018 -0.737 -0.657 0.197 0.324 0.474 $hbox 0 "L wrist rotate" -2.124 -1.749 -1.530 6.668 1.282 1.464 $hbox 0 "Bone R lowarm" -10.248 -1.668 -1.773 0.000 1.423 1.222 $hbox 0 "Bone R hand" -4.925 -0.924 -1.077 0.000 1.279 1.506 $hbox 0 "Grip" 0.000 -4.447 -1.064 4.508 0.000 0.078 $hbox 0 "Slide" 0.000 -4.235 -1.004 4.558 0.000 0.000 // Model uses material "v_hands.vmt" // Model uses material "1911b_nogrip.vmt" // Model uses material "1911.vmt" $attachment "1" "Barrel" 0.00 -0.00 0.00 rotate 0.00 -0.00 0.00 $attachment "2" "Bullet" -0.90 0.26 0.00 rotate -90.00 0.00 0.00 $surfaceprop "default" $illumposition -2.167 3.767 -7.538 $sequence idle1 "idle1" ACT_VM_IDLE 1 fps 16.00 $sequence shoot1 "shoot1" ACT_VM_PRIMARYATTACK 1 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } } $sequence shoot2 "shoot2" ACT_VM_PRIMARYATTACK 1 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } } $sequence shoot_empty "shoot_empty" ACT_VM_DRYFIRE 1 fps 27.00 { { event 5001 0 "21" } } $sequence reload "reload" ACT_VM_RELOAD 1 fps 35.00 { { event 5004 8 "weapons/deagle/clipout.wav" } { event 5004 45 "weapons/deagle/clipin.wav" } { event 5004 69 "weapons/deagle/1911slideforward.wav" } } $sequence draw "draw" ACT_VM_DRAW 1 fps 50.00 { { event 5004 18 "weapons/deagle/1911slideback.wav" } { event 5004 33 "weapons/deagle/1911slideforward.wav" } }
There are a few things we need to do clean the file up a bit. We can delete all of the $hbox, $cd, and $surfaceprop lines as they are all generated by the decompiler. Once you have done this rename the $modelname "weapons\v_pist_deagle.mdl" line to what weapon you want it to replace in HL2 for example: $modelname "weapons\v_357.mdl". Ok, so now onto the more difficult parts. First of all we need to add rotate -90 in all of the $sequence lines like so:
$sequence draw "draw" ACT_VM_DRAW 1 rotate -90 fps 50.00 { { event 5004 18 "weapons/deagle/1911slideback.wav" } { event 5004 33 "weapons/deagle/1911slideforward.wav" } }
Repeat this for all of the $sequence lines and then we need to add a line to the sequences which include a firing sequence like this line for example:
$sequence shoot1 "shoot1" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } } $sequence shoot2 "shoot2" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } }
We need to add to this line a muzzle flash sequence, this is relatively simple and shouldnt take to long. There are a few different muzzle flashes available to us but for this gun were going to take the muzzle flash from the .357 and apply it to the deagle, the muzzle flash code looks like this:
{ event AE_MUZZLEFLASH 0 "357 MUZZLE" } }
We need to add this line at the bottom of each firing sequence:
$sequence shoot1 "shoot1" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } { event AE_MUZZLEFLASH 0 "357 MUZZLE" } } $sequence shoot2 "shoot2" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } { event AE_MUZZLEFLASH 0 "357 MUZZLE" } }
The .qc file is now ready to go and be compiled, for reference purposes your .qc file should now look this this:
$cd "C:\Documents and Settings\Administrator\Desktop\Decompiled Models" $modelname "weapons\v_357.mdl" $model "studio" "ref.smd" $cdmaterials "models\weapons\V_models\SnuffyColt\" $cdmaterials "models\weapons\v_models\hands\" // Model uses material "v_hands.vmt" // Model uses material "1911b_nogrip.vmt" // Model uses material "1911.vmt" $attachment "1" "Barrel" 0.00 -0.00 0.00 rotate 0.00 -0.00 0.00 $attachment "2" "Bullet" -0.90 0.26 0.00 rotate -90.00 0.00 0.00 $surfaceprop "default" $illumposition -2.167 3.767 -7.538 $sequence idle1 "idle1" ACT_VM_IDLE 1 rotate -90 fps 16.00 $sequence shoot1 "shoot1" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } { event AE_MUZZLEFLASH 0 "357 MUZZLE" } } $sequence shoot2 "shoot2" ACT_VM_PRIMARYATTACK 1 rotate -90 fps 27.00 { { event 5001 0 "1" } { event AE_CLIENT_EFFECT_ATTACH 0 "EjectBrass_9mm 2 100" } { event AE_MUZZLEFLASH 0 "357 MUZZLE" } } $sequence shoot_empty "shoot_empty" ACT_VM_DRYFIRE 1 rotate -90 fps 27.00 { { event 5001 0 "21" } } $sequence reload "reload" ACT_VM_RELOAD 1 rotate -90 fps 35.00 { { event 5004 8 "weapons/deagle/clipout.wav" } { event 5004 45 "weapons/deagle/clipin.wav" } { event 5004 69 "weapons/deagle/1911slideforward.wav" } } $sequence draw "draw" ACT_VM_DRAW 1 rotate -90 fps 50.00 { { event 5004 18 "weapons/deagle/1911slideback.wav" } { event 5004 33 "weapons/deagle/1911slideforward.wav" } }
To compile the .qc copy it to the sourcesdk/bin folder and open it with studiomdl.exe with should already be in the bin folder. A command prompt will appear and it will begin compiling the weapon into your mod.
Now we have to check its got in the game ok, to do this go back to the Half-Life model viewer and go to 'File, Load Model' and select the v_357.mdl found in the weapons folder as this is what we have compiled our custom weapon to replace.
The model should load with textures but you'll notice that the hands are untextured and in a weird checkered pattern, this is because we haven't installed the CSS hand textures yet. To do this extract the hands materials found in counter strike source shared.gcf using GCFScape and place the 'hand' folder into your mod directory (C:\Program Files\Steam\SteamApps\sourcemods\MODNAME\materials\models\weapons\hands) now refresh Model Viewer by pressing F5 and viola! The Hands are textured.
SECTION 2 - FINE TUNING THE MODEL
This section will explore fine tuning the model and getting rid of those pesky bugs!
Now that your model is in game you will have noticed some 'bugs' with the model.. One very annoying bug is that the weapon seems to be stuck on the left hand side, but there is a simple and easy fix for this:
First things first open your weapon script file eg. weapon_357.txt found in your Mods Script directory (C:\Program Files\Steam\SteamApps\sourcemods\MODNAME\scripts)
When you open it you will find something that looks like this:
// 357 WeaponData { // Weapon data is loaded by both the Game and Client DLLs. "printname" "#HL2_357Handgun" "viewmodel" "models/weapons/v_357.mdl" "playermodel" "models/weapons/w_357.mdl" "anim_prefix" "python" "bucket" "1" "bucket_position" "1" "clip_size" "6" "default_clip" "6" "primary_ammo" "357" "secondary_ammo" "None" "weight" "7" "item_flags" "0" "damage" "75" // Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds) SoundData { "empty" "Weapon_Pistol.Empty" "single_shot" "Weapon_357.Single" } // Weapon Sprite data is loaded by the Client DLL. TextureData { "weapon" { "font" "WeaponIcons" "character" "e" } "weapon_s" { "font" "WeaponIconsSelected" "character" "e" } "ammo" { "font" "WeaponIcons" "character" "q" } "crosshair" { "font" "Crosshairs" "character" "Q" } "autoaim" { "file" "sprites/crosshairs" "x" "0" "y" "48" "width" "24" "height" "24" } } }
There are a few quick changes we need to make, to fix the left hand model problem there are 2 Steps you need to take - The first step can be done in the script file but the other requires you to edit the SDK code. The first step you need to make is add a few lines to the script above:
Scroll down to where it says "item_flags" "0" and just below it add:
"BuiltRightHanded" "0" "AllowFlipping" "1"
This will allow the cl_righthand command to work (Set cl_righthand to 1). But before the cl_righthand command will be recognised by the game you must edit the Source Code; go to your Mods Src folder (C:\MODNAME\src\cl_dll) and open 'c_baseviewmodel.cpp' and scroll down to line 25 and find the line that looks like this:
#ifdef CSTRIKE_DLL ConVar cl_righthand( "cl_righthand", "1", FCVAR_ARCHIVE, "Use right-handed view models." ); #endif
And simply comment out the top and bottom lines like so:
// #ifdef CSTRIKE_DLL ConVar cl_righthand( "cl_righthand", "1", FCVAR_ARCHIVE, "Use right-handed view models." ); // #endif
And go to line 173 and comment lines like this:
// #ifdef CSTRIKE_DLL
// If cl_righthand is set, then we want them all right-handed.
CBaseCombatWeapon *pWeapon = m_hWeapon.Get();
if ( pWeapon )
{
const FileWeaponInfo_t *pInfo = &pWeapon->GetWpnData();
return pInfo->m_bAllowFlipping && pInfo->m_bBuiltRightHanded != cl_righthand.GetBool();
}
// #endif
This will allow the cl_righthand cvar to be used to change the weapon side. Now save and compile.
Ok, so the viewmodel bug is fixed.. but theres still one more issue that needs to be resolved. Thats the sound issues - as you probably found out the sounds are not the sounds of the Deagle but they are still the .357 sounds, there is a real easy way to fix this. Extract the games_sound_weapons.txt file from the CSS GCF (Its in the scripts folder) and Copy the text from inside the file. Open up the games_sound_weapons.txt from your mod and copy the text into the bottom of that file (DON'T OVERWRITE WHAT IS ALREADY THERE).
Now in your weapon_357.txt file you can change these lines:
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds) SoundData { "empty" "Weapon_Pistol.Empty" "single_shot" "Weapon_357.Single" }
Find the relative sounds from the games_sound_weapons.txt file and replace the above lines with the deagle sounds like so:
// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds) SoundData { "empty" "Default.ClipEmpty_Pistol" "single_shot" "Weapon_DEagle.Single" }
Make sure you've copied the sound directory from CSS GCF into your mod folder!
That should do it! It should all be working... It may not be 100% Bugless but im sure some more tweaking would fix that.
Enjoy! :D