Category:Tutorials
This is my first tutorial ever so bear with me, I decided to write this after seeing so many people asking 'How do I use CSS weapons in my Mod?' and the basic reply was always, Extract them from the GCF and rename them to the HL2 weapons. This is a really bad way to do it and will make it extremly buggy.
Also check out my latest Video tutorial on Importing CSS Player Models into HL2
So heres the solution, Ill try to make it as informative as possible:
Requirements:
Cannonfodders MDL Decompiler - Download For Free Ability to Compile the Source SDK View Tutorial
SECTION 1 - 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 change here, the first thing we can do is delete all of the $hbox lines, 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 relativly simple and shouldnt take to long. There are a few different muzzle flashs avaible 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_pist_deagle.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 wierd checquered pattern, this is because we havnt 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 voila! 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 23 (I think) 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
Now scroll down to the C_BaseViewModel::ShouldFlipViewModel() function, somewhere near line 161. Here you will find another set of "#ifdef CSTRIKE_DLL" and "#endif" commands. Comment these out as well. 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.
Tutorial Written By Joshua Marshall
Subcategories
This category has the following 7 subcategories, out of 7 total.
C
- Choreography creation (9 P)
D
M
P
- Portal 2 Tutorials (61 P)
- Portal level design (empty)
S
- SDKNuts Tutorials (100 P)
W
- Weapons programming (42 P)
Pages in category "Tutorials"
The following 200 pages are in this category, out of 437 total.
(previous page) (next page)A
- Accessing Other Entities
- Adapting PBR Textures to Source
- Add Mod Content to Hammer
- Adding a Camera Bone to a Viewmodel
- Adding a Dynamic Scope
- Adding a dynamic sky to your mod
- Adding a new weapon to your mod
- Adding a Scope
- Adding a Weapon Drop System
- Adding an experience system
- Adding an inventory
- Adding chapters to your mod
- Adding class based health differences
- Adding Convars to the Multiplayer Advanced Tab
- Adding Headlights to the Buggy
- Adding Light
- Adding Mesh To Existing Viewmodels
- Adding Muzzle Flashes that lights up the world
- Adding MySQL++
- Adding New Ammotypes
- Adding PBR to Your Mod
- Adding Point Entities
- Adding Portal-style regenerating health
- Adding Prop Models
- Adding Proximity Voice
- Adding the Game Instructor
- Adding Water
- Adding Weapon Inspect
- Talk:Source Mod Installers
- Alien Swarm Level Creation/Your first Alien Swarm map
- Alien Teleport Effect (HL1)
- Alternative Multi-Stop Elevator
- Ammo pack (TFC)
- Animated cursor
- Animating Weapons
- Animation in XSI
- Antlions: Random Spawn
- Applying Textures
- Applying Textures/v2draft
- Areaportal tutorial
- Arrival departure transition ents.vmf (Portal 2)
- Authoring a Brush Entity
- Authoring a Brush Entity/Code
- Authoring a Logical Entity
- Authoring a Model Entity
- Authoring and Using TrueType Fonts
- AVI Materials
B
- Basic Construction
- Basic Hud Modification
- Battlefield Style Hitmarker
- Blowout Doors
- Bonus Maps
- Box dropper
- Breakable Glass
- BSP Content Extraction
- BTS Light Sources
- BTS Sewer Room
- BTS Support Beams
- BTS Turret Repair Rooms
- Bullet Penetration in Counter-Strike: Source
- Bullet Penetration in Day of Defeat: Source
- Bump map
- Burst Fire (Machine Gun)
C
- Camera Bob
- Car Explosions
- Changing default spawn weapons
- Changing max ammo in HL2
- Changing Maximum Player Count
- Changing prop models dynamically
- Changing the fading speed of the GUI Windows
- Changing the viewmodel bob
- Choreography creation
- Clock
- CollisionProperty
- Color Theory in Level Design
- Command line
- Compiling a model
- Compiling under VS2002
- Compiling under VS2003
- Compiling under VS2005
- Compiling under VS2005/Older SDK
- Compiling under VS2008
- Compiling under VS2010
- Compiling under VS2012
- Compiling under VS2022
- Compiling vgui controls.lib
- Compiling your map using htct
- Complex Brush Creation
- Complimentary Victory Lift
- Configuring Hammer for Day of Defeat
- Configuring Hammer for Deathmatch Classic
- Configuring Hammer for Half-Life
- Configuring Hammer for Half-Life Deathmatch: Source
- Configuring Hammer for Half-Life: Source
- Controlling portals
- Converting brushes to models with XSI
- Counter-Strike: Global Offensive/Game Modes/Co-op Strike
- Counter-Strike: Global Offensive/Game Modes/Danger Zone
- Counter-Strike: Global Offensive/Game Modes/Guardian
- Counter-Strike: Global Offensive/Game Modes/Retakes
- Counter-Strike: Global Offensive/Game Modes/Wingman
- Crate
- Create traffic lights
- Creating a Bomb Defusal Map
- Creating A Class System
- Creating a Classic Counter-Strike Map
- Creating a Curved Hallway
- Creating A Fire Particle
- Creating a Hostage Rescue Map
- Creating a Material
- Creating a moving platform
- Creating a Portal AI Voice
- Creating a portal elevator
- Creating a Portal Radio
- Creating a portal/object fizzler
- Creating a rotating portalgun
- Creating a Roundtimer
- Creating a security camera
- Creating a wake-up bed
- Creating a wall light
- Creating a Waterfall Material
- Creating a working Crane in Half-Life 2
- Creating a working mini-map for CS:GO
- Creating An Auto Portal
- Creating an energy ball launcher and catcher
- Creating an HL2DM megacharger
- Creating an incinerator
- Creating an Observation Hallway
- Creating Animated Clouds
- Creating BTS Fans
- Creating custom Portal 2 funnel music
- Creating Holes in Displacements
- Creating indicator lights
- Creating multiple buttons for one door
- Creating Player Spawns in Day of Defeat Source
- Creating poison water
- Creating Portal Breaking Ladders
- Creating Portal Cat Walks
- Creating Portal Doors
- Creating Portal Ducts
- Creating Portal Neurotoxin Gas
- Creating Portal Piston Panels
- Creating Portal Piston Types
- Creating Portal Speakers
- Creating Portal Turret Claws
- Creating Portal turrets
- Creating Portal Vacuum Tubes
- Creating Portal Vents
- Creating Spawns
- CSS/Animated Clouds
- Custom Floor Buttons
- Custom Menu Screen
- Custom Testchamber Signs
- Customizable triggered HUD-message
D
- Death notices with custom weapons
- Decals in GIMP
- Decals in Photoshop
- Decompiling Maps
- Demo Recording Tools
- Detailing BTS Areas
- Detailing BTS Wall Pipes
- Detailing metal walls
- Digital Elevation Models
- Displacement Grass
- DODS/Creating cap zones
- DODS/Creating the detonation map type
- DODS/Creating the main map area
- DODS/Creating Weapon Spawns
- Dog/Playing fetch
- Door creation
- Dropping empty magazines (GoldSrc)
- Dual Pistols (CSS Style)
- Dynamic assaults
- Dynamic RTT shadow angles in Source 2007
- Dynamic Viewmodel FOVs
- Dynamic Weapon Spawns
- Dynamic Weapon Spawns (Advanced)
E
F
- Fading Out NPC Ragdolls
- Fading The Player In Thirdperson
- Fading The Player In Thirdperson 2013
- Falling headcrab tutorial
- Filter Applications
- First Person Ragdolls In Singleplayer
- Fix Missing Player Animations
- Fixing DXT Green Tint Compression
- Fixing first time HL2DM compile problems
- Fixing trigger gravity