SpawnParticle (ZScript)

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.

struct LevelLocals
native void SpawnParticle(FSpawnParticleParams p);


Spawns a particle on the map. This acts as a struct-using replacement for A_SpawnParticleEx, due to how many parameters that method has. Since this method is in the LevelLocals struct, it must be called with the LevelLocals or Level prefix.


  • p: A pointer to the FSpawnParticleParams struct that stores the parameters the function will use.


Note: Structs have no default values, so parameters that have defaults in A_SpawnParticleEx such as startalpha and color1 do not have them here !

The parameters the FSpawnParticleParams struct has are the same as the ones A_SpawnParticleEx uses. However, several parameters are squashed into Vector3 parameters, listed below:

  • pos: The absolute XYZ coordinate to spawn the particle in. It replaces the relative x/y/zoff parameters that the other particle spawn methods have.
  • vel: The velocity to apply to the particle on the XYZ axes, like the velx/y/z parameters it replaces, these values are absolute as well.
  • accel: The acceleration to apply to the particle on the XYZ axes. It replaces the accelx/y/z parameters that the other particle spawn methods have.
  • angle: This parameter no longer exists in FSpawnParticleParams, since the SpawnParticle method uses absolute coordinates. This also means that the `SPF_REL*` flags do nothing by extension.
  • startalpha: This parameter is what 'startalphaf' is renamed to.
  • color1: This parameter is what 'color' is renamed to.
  • fadestep: This parameter is what 'fadestepf' is renamed to.


This is a spawner that can be configured in a level editor to spawn different types of particles at a specified frequency.

Class RandomParticleSpawner : Actor
		//|$Title Random Particle Spawner
		//$Category Decoration
		//$Arg0 Particle Types
		//$Arg0Tooltip "What type of particle should the spawner create"
		//$Arg0Type 11
		//$Arg0Enum {0 = "Default"; 1 = "Fire Particles"; 2 = "Doomguy Hologram";}
		//$Arg1 Frequency
		//$Arg1Tooltip "How frequently (in tics) the spawner should create a particle"
		//$Arg1Default 35
	//Give some names to the possible values of Args[0]
	Enum ParticleTypes
	Vector3 Offsets; //The offsets relative to the spawner to use for each particle.
	Override Void Tick()
		//Spawn a particle every time that the age of the spawner can be divided by the spawn frequency. Or immediately spawn one if the frequency is 0 or less.
		If (Args[1] <= 0 || GetAge() % Args[1] == 0)
			//Play fire sound for fire particles.
			If (Args[0] == TYPE_FIREBALL)
				A_StartSound ("vile/firecrkl",flags:CHANF_NOSTOP);
			//Stop fire sound if the particle type was changed during runtime.
				A_StopSound (CHAN_BODY);
			//Spawn boring default particle.
			If (Args[0] == TYPE_DEFAULT)
				Offsets = (FRandom (64,-64),FRandom (64,-64),0);
				FSpawnParticleParams DefaultParticle;
				DefaultParticle.Color1 = "Gray";
				DefaultParticle.Style = STYLE_None;
				DefaultParticle.Lifetime = 70;
				DefaultParticle.Pos = Vec3Offset (Offsets.X,Offsets.Y,Offsets.Z); //Spawn relative to the spawner.
				DefaultParticle.Size = 1.5;
				DefaultParticle.SizeStep = 1;
				DefaultParticle.Vel.Z = FRandom (0.2,6); //Randomize the velocity of the particle.
				DefaultParticle.StartAlpha = 1;
				DefaultParticle.FadeStep = 0.004;
				Level.SpawnParticle (DefaultParticle);
			//Spawn cool fire particle.
			Else If (Args[0] == TYPE_FIREBALL)
				Offsets = (FRandom (64,-64),FRandom (64,-64),0);
				FSpawnParticleParams FireballParticle;
				FireballParticle.Texture = TexMan.CheckForTexture ("BAL1A0");
				FireballParticle.Color1 = "FFFFFF";
				FireballParticle.Style = STYLE_Add;
				FireballParticle.Flags = SPF_ROLL|SPF_FULLBRIGHT;
				FireballParticle.Vel = (FRandom (0.5,-0.5),FRandom (0.5,-0.5),FRandom (0.1,0.8)); //Randomize the velocity of the particle.
				FireballParticle.RollVel = 0.25;
				FireballParticle.StartAlpha = 1;
				FireballParticle.Size = 0.4;
				FireballParticle.SizeStep = 0.2;
				FireballParticle.Lifetime = FRandom (35,35*4); //Randomize the lifespan of the particle.
				FireballParticle.Pos = Vec3Offset (Offsets.X,Offsets.Y,Offsets.Z); //Spawn relative to the spawner.
				Level.SpawnParticle (FireballParticle);
				Level.SpawnParticle (FireballParticle); //Spawn more particles for better effect.
				Level.SpawnParticle (FireballParticle);
			//Spawn super cool Doomguy particle.
			Else If (Args[0] == TYPE_DOOMGUY)
				FSpawnParticleParams DoomguyParticle;
				DoomguyParticle.Texture = TexMan.CheckForTexture ("PLAYA1");
				DoomguyParticle.Lifetime = INT.MAX; //Doom(guy) is eternal.
				DoomguyParticle.Style = STYLE_Add;
				DoomguyParticle.StartAlpha = 1;
				DoomguyParticle.FadeStep = -1;
				DoomguyParticle.Size = 75;
				DoomguyParticle.SizeStep = 0;
				DoomguyParticle.Color1 = "Blue";
				DoomguyParticle.Flags = SPF_FULLBRIGHT|SPF_REPLACE;
				DoomguyParticle.Pos = Self.Pos; //Spawn relative to the spawner.
				Level.SpawnParticle (DoomguyParticle);
			//If the spawner has no frequency, spawn only one particle and go away. Allows for spawning a single permanent Doomguy hologram for example.
			If (Args[1] <= 0)