Particle Muzzle Flash

From Valve Developer Community
Jump to: navigation, search
Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

In this article, we will walk through the steps to change the SMG's world muzzle flash to the new Orange Box particle system. This means that only third-person SMG muzzle flashes(NPC's) will be changed. A link to the new SMG's particles can be found at the end of the article.

Adding particle_parse.h

First, start off by opening weapon_smg1.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 CWeaponSMG1::Precache( void ) method around line 154, add:

PrecacheParticleSystem( "muzzle_smg1" );

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 where the muzzle is, and we also need to find out the angle the gun is pointed at so the particles are pointed the correct direction.

In the void CWeaponSMG1::FireNPCPrimaryAttack method, around line 180 add:

Vector vecShootOrigin2; //The origin of the shot 
QAngle	angShootDir2;    //The angle of the shot

We also need to find the position of the muzzle, so add:

//We need to figure out where to place the particle effect, so lookup where the muzzle is
GetAttachment( LookupAttachment( "muzzle" ), vecShootOrigin2, angShootDir2 );

And now, add the following code that will dispatch the particle system:

DispatchParticleEffect( "muzzle_smg1", vecShootOrigin2, angShootDir2);

Now, because we have a new muzzle flash effect we don't need the old one. Comment out the line:

pOperator->DoMuzzleFlash();

So now, you should have:

void CWeaponSMG1::FireNPCPrimaryAttack( CBaseCombatCharacter *pOperator, Vector &vecShootOrigin, Vector &vecShootDir )
{
        // FIXME: use the returned number of bullets to account for >10hz firerate
        WeaponSoundRealtime( SINGLE_NPC );

        CSoundEnt::InsertSound( SOUND_COMBAT|SOUND_CONTEXT_GUNFIRE, pOperator->GetAbsOrigin(), SOUNDENT_VOLUME_MACHINEGUN, 0.2, pOperator, SOUNDENT_CHANNEL_WEAPON, pOperator->GetEnemy() );
        pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED,
                 MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2, entindex(), 0 );

        Vector vecShootOrigin2;  //The origin of the shot 
        QAngle	angShootDir2;    //The angle of the shot

        //We need to figure out where to place the particle effect, so look up where the muzzle is
        GetAttachment( LookupAttachment( "muzzle" ), vecShootOrigin2, angShootDir2 );

        //pOperator->DoMuzzleFlash();
        DispatchParticleEffect( "muzzle_smg2", vecShootOrigin2, angShootDir2);
        m_iClip1 = m_iClip1 - 1;
}

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

Making the Muzzle Flash

Now that we have to code finished and compiled, we can make the muzzle flash using the built-in particle editor.

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.

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

Finishing Up

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

Open up particles_manifest.txt and add:

"file"		"particles/smg_muzzle_flash.pcf"

Congratulations! We are all done! See, wasn't that easy?

Screenshot

The finished result:

Muzzle smg.jpg