Classes:RandomSpawner
From ZDoom Wiki
| Random spawner | |||
|---|---|---|---|
| Actor type | Internal | Game | |
| DoomEd Number | None | Class Name | RandomSpawner |
Classes: RandomSpawner
(development version only)
The RandomSpawner is a special actor which randomly spawns one of a series of actors specified with the DropItem property in its DECORATE code.
The RandomSpawner should not be used directly. Instead, authors should derive a new class from the actor and specify the actors they wish to be randomly spawned in the code of the new actor. (See examples below)
In addition to specifying the actors that may spawn, two optional parameters may be specified for each entry in the list. The first is an integer used to specify the spawn chance of any given monster in the list, assuming it is selected to spawn, with 0 being never and 255 being always (default is 255). The second number specifies this actor's "weight" or chance of spawning versus other actors in the list (default is 1).
Examples
Basic example:
This will create a random spawner which when placed in the map will always spawn one of four enemies with equal chance:
actor MySpawner : RandomSpawner 1111
{
DropItem "ZombieMan"
DropItem "DoomImp"
DropItem "HellKnight"
DropItem "BaronOfHell"
}
This code will create a spawner which will randomly choose from among four enemies with varying chance, and will sometimes spawn nothing when one of the larger enemies is chosen:
Use of parameters:
actor MySpawner : RandomSpawner 1112
{
DropItem "ZombieMan" 255 10
DropItem "DoomImp" 255 8
DropItem "HellKnight" 128 4
DropItem "BaronOfHell" 64 1
}
Both parameters affect the likelihood that one of the actors will appear, but in different ways.
The first affects the probability that it will appear if selected. Using 255 is the equivalent of omitting the parameter entirely, and guarantees that the actor will spawn when selected. In this case, the Zombieman and DoomImp will always spawn if selected. The HellKnight, if selected, will only spawn half the time, and the Baron will only spawn 1/4th of the time. Otherwise nothing will spawn at all.
The second weighs the probability the actor will be selected. Here, the ZombieMan will be selected 10 times on 23 (about 43% of the times); ten is its weight and 23 is the total weight of all actors (10+8+4+1).
Keyword-based replacer:
A random spawner can be used to replace a given actor with a randomly-chosen one. There is one caveat, though: the replaced actor cannot be spawned directly. For example, the following code will create a spawner which replaces all the zombies in the map and will spawn either a pistol zombie (75% chance) or a shotgun zombie (25% chance). Note the creation of the ZombieMan2 actor to avoid creating a recursion with the spawner spawning a copy of itself if it selects a ZombieMan.
actor ZombieMan2 : ZombieMan {}
actor ZombieReplacer : RandomSpawner replaces ZombieMan
{
DropItem "ZombieMan2" 255 3
DropItem "ShotgunGuy" 255 1
}
Editor number-based replacer:
To avoid the inconvenience of having to define clones of replaced actors, it is possible to instead give the random spawner the doom editor number of the actor to replace. Our previous example would then be:
actor ZombieReplacer : RandomSpawner 3004
{
DropItem "ZombieMan" 255 3
DropItem "ShotgunGuy" 255 1
}
3004 is the doom editor number of the ZombieMan, so he is replaced when the map is initialized. The advantage of this method is that this makes the spawner more compatible with other mods (for example, one that attaches dynamic lights to its firing frame, or one that replaces them with a modified actor to achieve certain special effects). The drawback is that only actors directly placed on the map in the editor will be replaced; not those spawned by ACS or other custom actors.
DECORATE definition
ACTOR RandomSpawner native
{
+NOBLOCKMAP
+NOSECTOR
+NOGRAVITY
}

