Particle Muzzle Flash: Difference between revisions
(Added category(s)) |
Thunder4ik (talk | contribs) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Multiple issues| | |||
{{Dead end|date=January 2024}} | |||
{{Orphan|date=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. | 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 == | == Adding particle_parse.h == | ||
First, start off by opening '''weapon_smg1.cpp''' located under game/server/hl2. | 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'''. | 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'''. | ||
<source lang=cpp>#include "particle_parse.h"</source> | |||
== Precaching the Particles == | == 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. | 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 <code>void CWeaponSMG1::Precache( void )</code> method around line '''154''', add: | In the <code>void CWeaponSMG1::Precache( void )</code> method around line '''154''', add: | ||
<source lang=cpp>PrecacheParticleSystem( "muzzle_smg1" );</source> | |||
== Dispatching the Particles == | == 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. | 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. | 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. | ||
Line 21: | Line 28: | ||
In the <code>void CWeaponSMG1::FireNPCPrimaryAttack</code> method, around line '''180 add''': | In the <code>void CWeaponSMG1::FireNPCPrimaryAttack</code> method, around line '''180 add''': | ||
<source lang=cpp>Vector vecShootOrigin2; //The origin of the shot | |||
QAngle angShootDir2; //The angle of the shot</source> | |||
We also need to find the position of the muzzle, so '''add''': | We also need to find the position of the muzzle, so '''add''': | ||
<source lang=cpp>//We need to figure out where to place the particle effect, so lookup where the muzzle is | |||
GetAttachment( LookupAttachment( "muzzle" ), vecShootOrigin2, angShootDir2 );</source> | |||
And now, '''add''' the following code that will dispatch the particle system: | And now, '''add''' the following code that will dispatch the particle system: | ||
<source lang=cpp>DispatchParticleEffect( "muzzle_smg1", vecShootOrigin2, angShootDir2);</source> | |||
Now, because we have a new muzzle flash effect we don't need the old one. '''Comment out the line''': | Now, because we have a new muzzle flash effect we don't need the old one. '''Comment out the line''': | ||
<source lang=cpp> | |||
pOperator->DoMuzzleFlash();</source> | |||
So now, you should have: | |||
<source lang=cpp> | |||
< | |||
void CWeaponSMG1::FireNPCPrimaryAttack( CBaseCombatCharacter *pOperator, Vector &vecShootOrigin, Vector &vecShootDir ) | void CWeaponSMG1::FireNPCPrimaryAttack( CBaseCombatCharacter *pOperator, Vector &vecShootOrigin, Vector &vecShootDir ) | ||
{ | { | ||
Line 48: | Line 55: | ||
pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, | pOperator->FireBullets( 1, vecShootOrigin, vecShootDir, VECTOR_CONE_PRECALCULATED, | ||
MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2, entindex(), 0 ); | MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 2, entindex(), 0 ); | ||
Vector vecShootOrigin2; //The origin of the shot | Vector vecShootOrigin2; //The origin of the shot | ||
Line 60: | Line 66: | ||
m_iClip1 = m_iClip1 - 1; | m_iClip1 = m_iClip1 - 1; | ||
} | } | ||
</ | </source> | ||
Now compile everything, and now we are ready to make the actual particles. | Now compile everything, and now we are ready to make the actual particles. | ||
== Making the Muzzle Flash == | == Making the Muzzle Flash == | ||
Line 73: | Line 78: | ||
== Finishing Up == | == Finishing Up == | ||
The final step is to add your particle system to the file <code>particles_manifest.txt</code> in your mod's '''particles''' folder. | The final step is to add your particle system to the file <code>particles_manifest.txt</code> in your mod's '''particles''' folder. | ||
Open up <code>particles_manifest.txt</code> and add: | Open up <code>particles_manifest.txt</code> and add: | ||
"file" "particles/smg_muzzle_flash.pcf" | "file" "particles/smg_muzzle_flash.pcf" | ||
Congratulations! We are all done! See, wasn't that easy? | |||
Congratulations! We are all done! See, wasn't that easy? | |||
== Screenshot == | == Screenshot == | ||
The finished result: | The finished result: | ||
[[ | [[File:Muzzle smg.jpg]] | ||
[[Category:Particle System]] | [[Category:Particle System]] | ||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
[[Category: | [[Category:Weapons programming]] |
Latest revision as of 10:08, 21 January 2024




January 2024

You can help by

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: