Particles
Namespace:
DeadworksManaged.Api
A particle effect is a visual effect in the world, like an explosion, a beam or a glow. The game's effects are .vpcf files. A plugin can play any of them.
Play a particle effect
First, precache the effect. Use the .vpcf path, not .vpcf_c.
public override void OnPrecacheResources()
{
Precache.AddResource("particles/upgrades/mystical_piano_hit.vpcf");
}
Then create it where you want it.
var particle = CParticleSystem.Create("particles/upgrades/mystical_piano_hit.vpcf")
.AtPosition(pawn.Position + Vector3.UnitZ * 100)
.Spawn();
This plays the effect slightly above the player. See Precaching for more on loading.
Find an effect to play
Browse the game's files with Source2Viewer. Effects are under particles/.
Attach an effect to a player
Use AttachedTo to make the effect follow the player.
var particle = CParticleSystem.Create("particles/abilities/bull_drain.vpcf")
.AttachedTo(pawn)
.Spawn();
AttachedTo works with any entity, not only players.
To attach or detach an effect that already exists:
particle.AttachTo(pawn);
particle.Detach();
Remove an effect
particle.Destroy();
To remove it after a delay, use a timer:
Timer.Once(5.Seconds(), () => particle.Destroy());
Turn an effect off and on
particle.Stop();
particle.Start();
To create an effect that doesn't play until you call Start(), add StartActive(false):
var particle = CParticleSystem.Create("particles/abilities/bull_drain.vpcf")
.AtPosition(position)
.StartActive(false)
.Spawn();
Rotate an effect
var particle = CParticleSystem.Create("particles/abilities/bull_drain.vpcf")
.AtPosition(position)
.WithAngles(new Vector3(0, 90, 0))
.Spawn();
The angles are pitch, yaw and roll, in degrees.
Change an effect's colour
var particle = CParticleSystem.Create("particles/abilities/bull_drain.vpcf")
.AtPosition(position)
.WithTint(Color.Red, 1)
.Spawn();
The number is the control point the effect reads its colour from. The control point depends on the effect. Not every effect has one.
Set an effect's control points
Many effects read extra values, such as a size or an end point, from numbered control points. Which numbers an effect uses depends on the effect.
var particle = CParticleSystem.Create("particles/abilities/bull_drain.vpcf")
.AtPosition(position)
.WithDataCP(2, new Vector3(100, 0, 0)) // give control point 2 a value
.WithControlPoint(1, targetEntity) // make control point 1 follow an entity
.Spawn();