L4D Style Muzzle Smoke

From Valve Developer Community
Jump to: navigation, search

In this article, we will walk through the steps to add a L4D style weapon muzzle smoking effect to the HL2 Pistol.

Adding particle_parse.h

First, start off by opening weapon_pistol.cpp located under game/server/hl2.

We need to include the header file that allows us to use the particle effects, so add the following under #include "gamestats.h" at line 19.

#include "particle_parse.h"

Precaching the Particles

Now we need to let the engine know that we are going to use a particle effect. We do this by precaching the particle system we are going to use.

In the void CWeaponPistol::Precache( void ) method around line 176, add:

PrecacheParticleSystem( "weapon_muzzle_smoke" );

Dispatching the Particles

Now that we have all of our precaching setup, we can now add the actual code that will dispatch the particle effect.

We need to find out how many shots have been fired in a interval of time. Luckily, the Pistol already keeps track of this for us to calculate accuracy.

In the void CWeaponPistol::PrimaryAttack( void ) method, around line 252 add:

if(m_nNumShotsFired >= 5)
{
     //We shot >5, clean up and start the muzzle smoking effect (like l4d)
     DispatchParticleEffect( "weapon_muzzle_smoke", PATTACH_POINT_FOLLOW, pOwner->GetViewModel(), "muzzle", true);
}

Now compile everything, and now we are ready to make the actual particles.

Making the Smoke

Now that we have to code finished and compiled, we can make the smoke using the built-in particle editor (launching your mod in -tools mode).

If you do not have any experience with the particle editor, you can download a pre-made particle file Here Place this file in your mod's particle folder. Alternatively, VALVe left a file named devtest.pcf that has both muzzle flashes and smoke on it in Episode 2. They are: weapon_muzzle_smoke, weapon_muzzle_smoke_b, weapon_muzzle_smoke_b Version #2, weapon_muzzle_smoke_long, and weapon_muzzle_smoke_long_b. Take a look at devtest.pcf if you want to see what these look like.

However, if you want to make your own particle effect you can do so. Make sure you name the particle system, not the file, weapon_muzzle_smoke.

Finishing Up

The final step is to add your particle system to the file particles_manifest.txt in your mod's root folder.

Open up particles_manifest.txt and add:

"file"		"particles/weapon_smoke.pcf"


Congratulations! That's it!