Difference between revisions of "L4D Style Muzzle Smoke"

From Valve Developer Community
Jump to: navigation, search
m (Fixed Dead Link of weapon_smoke.pcf)
(FIX - Smoke effect transfer to new selection weapon during changing.)
 
Line 34: Line 34:
 
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).
 
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 [http://brainbreadsource.googlecode.com/svn-history/r30/trunk/bbs/particles/weapon_smoke.pcf 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:
+
If you do not have any experience with the particle editor, you can download a pre-made particle file [http://brainbreadsource.googlecode.com/svn-history/r30/trunk/bbs/particles/weapon_smoke.pcf Here] Place this file in your mod's '''particle''' folder.  
<code>weapon_muzzle_smoke</code>, <code>weapon_muzzle_smoke_b</code>, <code>weapon_muzzle_smoke_b Version #2</code>, <code>weapon_muzzle_smoke_long</code>, and <code>weapon_muzzle_smoke_long_b</code>. Take a look at devtest.pcf if you want to see what these look like.
+
 
 +
Alternatively, VALVe left a file named devtest.pcf that has both muzzle flashes and smoke on it in Episode 2.  
 +
They are:
 +
<code>weapon_muzzle_smoke</code>, <code>weapon_muzzle_smoke_b</code>, <code>weapon_muzzle_smoke_b Version #2</code>, <code>weapon_muzzle_smoke_long</code>, and <code>weapon_muzzle_smoke_long_b</code>.  
 +
 
 +
 
 +
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''', <code>weapon_muzzle_smoke</code>.
 
However, if you want to make your own particle effect you can do so. Make sure you name the particle system, '''not the file''', <code>weapon_muzzle_smoke</code>.
Line 48: Line 54:
 
Congratulations! That's it!  
 
Congratulations! That's it!  
  
 +
== Small fix ==
 +
During changing of the weapons, this smoke effect is transferred to new selected weapon, which you have not yet fired.
 +
 +
To fix this, you need to call the '''StopParticleEffects''' function during the change of weapons.
 +
 +
 +
Open: '''basecombatweapon_shared.cpp'''
 +
 +
In the top, above:      '''#include "vprof.h"'''
 +
 +
 +
Add the header file:
 +
<source lang=cpp>
 +
#include "particle_parse.h" // Weapon Smoke effect fix
 +
</source >
 +
 +
 +
After that, find Find:
 +
'''bool CBaseCombatWeapon::Holster( CBaseCombatWeapon *pSwitchingTo )'''
 +
 +
and below    '''m_bFiringWholeClip = false;'''    add this:
 +
<source lang=cpp>
 +
CBasePlayer *pPlayer = ToBasePlayer(GetOwner()); // Weapon Smoke effect fix
 +
StopParticleEffects(pPlayer->GetViewModel()); // Weapon Smoke effect fix
 +
</source >
 +
 +
 +
 +
It will be better if you restore [[Full_Holster_Sequence_(HL2MP)|Full Holster Sequence]]
  
 
[[Category:Particle System]]
 
[[Category:Particle System]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]
 
[[Category:Weapons programming]]
 
[[Category:Weapons programming]]

Latest revision as of 21:09, 1 June 2021

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!

Small fix

During changing of the weapons, this smoke effect is transferred to new selected weapon, which you have not yet fired.

To fix this, you need to call the StopParticleEffects function during the change of weapons.


Open: basecombatweapon_shared.cpp

In the top, above: #include "vprof.h"


Add the header file:

#include "particle_parse.h" // Weapon Smoke effect fix


After that, find Find: bool CBaseCombatWeapon::Holster( CBaseCombatWeapon *pSwitchingTo )

and below m_bFiringWholeClip = false; add this:

	CBasePlayer *pPlayer = ToBasePlayer(GetOwner()); // Weapon Smoke effect fix
	StopParticleEffects(pPlayer->GetViewModel()); // Weapon Smoke effect fix


It will be better if you restore Full Holster Sequence