Particles In Code
Jump to navigation
Jump to search
Precaching
Particle effects must be precached before they can be used. This is done by listing them in particles_manifest.txt
, then making this call:
PrecacheParticleSystem( "your_particle_effect_name" );
Dispatching
Particles systems are "dispatched" on the client.

StopParticleEffects( CBaseEntity* pEntity )
. But you cannot otherwise control the lifespan of a system from code. It will self-terminate on its own internal schedule.Simple
#include "particle_parse.h"
void DispatchParticleEffect( const char *pszParticleName, Vector vecOrigin, QAngle vecAngles, CBaseEntity *pEntity )
void DispatchParticleEffect( const char *pszParticleName, ParticleAttachment_t iAttachType, CBaseEntity *pEntity,
int iAttachmentPoint, bool bResetAllParticlesOnEntity )
The first function creates the system at some arbitrary world co-ordinates. The second spawns it at an attachment.

Complex
If you need to control the system after it spawns, the helper functions above won't do. Instead:
#include "particles_new.h"
CNewParticleEffect* pEffect = ParticleProp()->Create( "rail_shot", PATTACH_ABSORIGIN );
pEffect->SetControlPoint( 1, vecSomeVector );
See also CNewParticleEffect
.