Particles In Code: Difference between revisions
Jump to navigation
Jump to search
Tip:You can stop all systems tied to a given entity with
Bug:Valve's code for dispatching a particle attached to a model is broken. Get the fix here. [todo tested in ?]
TomEdwards (talk | contribs) (direct dispatching) |
TomEdwards (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
== Precaching == | == Precaching == | ||
Particle | Particle systems must be [[precache]]d before they can be used. This is done by listing the PCF containing them in <code>[[particles_manifest.txt]]</code>, then making this call: | ||
<source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source> | <source lang=cpp>PrecacheParticleSystem( "your_particle_effect_name" );</source> | ||
Line 9: | Line 9: | ||
== Dispatching == | == Dispatching == | ||
Particles systems are "dispatched" on the client. | Particles systems are "dispatched" on the client. They are always associated with an entity. | ||
{{tip|You can stop all systems tied to a given entity with <code>StopParticleEffects( CBaseEntity* pEntity )</code>. But you cannot otherwise control the lifespan of a system | {{tip|You can stop all systems tied to a given entity with <code>StopParticleEffects( CBaseEntity* pEntity )</code>. But you cannot otherwise directly control the lifespan of a system: it will choose when it terminates.}} | ||
=== Simple === | === Simple === | ||
Line 22: | Line 22: | ||
int iAttachmentPoint, bool bResetAllParticlesOnEntity )</source> | int iAttachmentPoint, bool bResetAllParticlesOnEntity )</source> | ||
The first function creates the system at some arbitrary world co-ordinates. The second | The first function creates the system at some arbitrary world co-ordinates. The second enables you to spawn it at an [[attachment]] point and/or make it follow the entity. | ||
{{bug|Valve's code for dispatching a particle attached to a model is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}} | {{bug|Valve's code for dispatching a particle attached to a model is broken. [[SDK Known Issues List Fixed#Server Dispatching an Attached Particle Effect|Get the fix here.]]}} | ||
Values for <code>ParticleAttachment_t</code> are: | |||
; <code>PATTACH_ABSORIGIN</code> | |||
; <code>PATTACH_ABSORIGIN_FOLLOW</code> | |||
: Spawn at (and optionally follow) the entity's [[origin]]. | |||
; <code>PATTACH_POINT</code> | |||
; <code>PATTACH_POINT_FOLLOW</code> | |||
: Spawn at (and optionally follow) an [[attachment]] point on the entity's model. | |||
; <code>PATTACH_CUSTOMORIGIN</code> | |||
: Spawn at a given origin. | |||
; <code>PATTACH_WORLDORIGIN</code> | |||
: Don't attach to an entity. Use with caution. | |||
=== Complex === | === Complex === |
Revision as of 04:39, 21 October 2009
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" );
Dispatching
Particles systems are "dispatched" on the client. They are always associated with an entity.

StopParticleEffects( CBaseEntity* pEntity )
. But you cannot otherwise directly control the lifespan of a system: it will choose when it terminates.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 enables you to spawn it at an attachment point and/or make it follow the entity.

Values for ParticleAttachment_t
are:
PATTACH_ABSORIGIN
PATTACH_ABSORIGIN_FOLLOW
- Spawn at (and optionally follow) the entity's origin.
PATTACH_POINT
PATTACH_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 attach to an entity. Use with caution.
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
.