Particles In Code
Jump to navigation
Jump to search
Precaching
Particle systems must be precached before they can be used. This is done by listing the PCF containing them in particles_manifest.txt, then making this call:
PrecacheParticleSystem( "your_particle_effect_name" );
Creating
Serverside
Particles are dispatched as events. The functions are shared, so there's no need to #ifdef calls out on the client.
#include "particle_parse.h"
// Create at world co-ords
void DispatchParticleEffect( "my_particle", vecOrigin, angAngles, pOwnerEntity )
// Create at model attachment
void DispatchParticleEffect( "my_particle", ParticleAttachment_t, pOwnerEntity, iAttachmentPoint, bResetAllParticlesOnEntity )
Values of ParticleAttachment_t are:
PATTACH_ABSORIGINPATTACH_ABSORIGIN_FOLLOW- Spawn at (and optionally follow) the entity's origin.
PATTACH_POINTPATTACH_POINT_FOLLOW- Spawn at (and optionally follow) an attachment point on the entity's model.
PATTACH_CUSTOMORIGIN- Spawn at a given origin.
PATTACH_WORLDORIGIN- Don't associate with an entity at all. Use with caution - could easily cause memory leaks.
Client
Each particle system is a temporary entity: only the client can interact with it once it has been dispatched. In addition, it isn't possible to specify control points on the server at all.
Each active system is a CNewParticleEffect object that can be created and accessed through an entity's ParticleProp() accessor.
#include "particles_new.h"
// To create a new systen:
CNewParticleEffect* pEffect = ParticleProp()->Create( "my_particles", PATTACH_ABSORIGIN );
// Or if the system already exists:
CNewParticleEffect* pEffect = ParticleProp()->FindEffect( "my_particles" );
pEffect->SetControlPoint( 1, vecSomeVector );
Alternatively, you can hook into particle creation:
void C_MyEntity::OnNewParticleEffect( const char* pszParticleName, CNewParticleEffect* pNewParticleEffect )
{
// ...
}
Destroying
You can stop particle systems with:
StopParticleEffects( CBaseEntity* )- Stops all effects on the given entity
ParticleProp()->StopParticlesInvolving( CBaseEntity* )- Stops all effects with a control point attached to the given entity.
ParticleProp()->StopParticlesNamed( const char* )- Stops all effects with the given system name. Todo: Global or only on current entity?
CNewParticleEffect::StopEmission( bool bInfiniteOnly, bool bRemoveAllParticles, bool bWakeOnStop)- Stops the current particle system, without removing it. Todo: Meaning of first and third arguments.