Classes:RandomSpawner
Note: Wait! Stop! Before you copy this actor's definition into your mod, remember the following things:
|
| Random spawner | |||
|---|---|---|---|
| Actor type | Internal | Game | |
| DoomEd Number | None | Class Name | RandomSpawner |
Classes: RandomSpawner
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.
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).
It is possible for RandomSpawners to spawn other RandomSpawners. However, to prevent infinite recursion loops, an error marker will instead be created if more than 32 random spawners get nested in such a way.
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 Imp will always spawn if selected. The Hell Knight, 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.
Important note: for replacing boss monsters (Arachnotron, BaronOfHell, Cyberdemon, Fatso, Ironlich, Minotaur, Sorcerer2 and SpiderMastermind), you need to use the replaces keyword or the game will not be able to know that the boss monsters are being replaced. A spawner normally removes itself entirely from the game after spawning a monster; but if it finds the BOSS or BOSSDEATH flag on a monster it replaces or spawns, it will stay around and monitor its health so as to call A_BossDeath when the monster dies. It is the spawner, not the monster itself, which will trigger the map's special action in such a scenario.
For a scripted map, as long as the monsters which must trigger special actions have the special directly set on them or are identified by a TID rather than by their type, the random spawners should work correctly. However, scripts which identify monsters by their type (using functions such as ThingCount or ThingCountName) will be broken unless the spawned replacements are made as bosses.
DECORATE definition
ACTOR RandomSpawner native
{
+NOBLOCKMAP
+NOSECTOR
+NOGRAVITY
+THRUACTORS
}
- Chex Quest actors
- Chex Quest internal actors
- Chex Quest 3 actors
- Chex Quest 3 internal actors
- Doom actors
- Doom internal actors
- Doom II actors
- Doom II internal actors
- Heretic actors
- Heretic internal actors
- Hexen actors
- Hexen internal actors
- Strife actors
- Strife internal actors
- ZDoom actors
- ZDoom internal actors
- Internal
- Special ZDoom things