ZDoom Line Specials

135:Thing_Spawn

Name

Thing_Spawn — spawns an actor at a map spot

Synopsis

Thing_Spawn (tid, type, angle, newtid);
Thing_Spawn (
  tid,       // Map spot(s) to spawn the new thing at
  type,      // The type of thing to spawn
  angle,     // Byte angle for the new thing to face
  newtid     // Thing ID to assign to the newly-spawned thing
);

Parameters

tid
This is the Thing ID of the map spot you want to spawn a new thing at. If there is more than one map spot with this TID, then a new thing will spawn at each map spot.
type
This is the type of thing to spawn. The numbers used here correspond to a thing's spawn ID and not its editor number. You can get a complete list of spawn IDs by looking at zdefs.acs, or by using the command "dumpspawnables" at the ZDoom console.
angle
The newly spawned thing(s) will face the direction specified by this parameter. The direction the map spot is facing is ignored.
newtid
This is the Thing ID to assign to the newly spawned thing(s). If you make this non-zero, then you will be able to affect the new thing(s) using all the normal thing specials that take a TID as an argument.

ACS

This special works equally well whether you use it in a script or on a line. However, if you use it in a script, it is strongly recommended that you specify type using the names defined in zdefs.acs instead of by using the corresponding number. This is so that your script will be more readable, although the special will work equally well whether you use the names or not.

Remarks

Although tid is often the TID of a map spot, it can refer to any thing on the map—not just map spots.

If there is no room for a thing at the location where it is to spawn, then it will not spawn at all. The only way to detect this is to use ThingCount before and after Thing_Spawn and compare the two results to see if the count increased. In most cases, you should not actually need to know this.

This special will create a teleport flash at the location where the new thing spawns. If you do not want this, use Thing_SpawnNoFog instead.

Examples

Spawn an imp at mapspot 1, facing north:

Thing_Spawn (1, T_IMP, 64);

Spawn an imp at mapspot 1, facing north, and give the imp TID 5:

Thing_Spawn (1, T_IMP, 64, 5);

This script will repeatedly try to spawn a cyberdemon at mapspot 2, facing south until it succeeds. You can adapt this as necessary to spawn monsters that absolutely must be spawned.

script 1 (void)
{
    // Notice that we give the spawned cyberdemon a TID of 1000. Counting things
    // with a specific TID is faster than counting things without a particular TID.
    int count1 = ThingCount (T_CYBERDEMON, 1000);
    int count2;

    do
    {
        Thing_Spawn (2, T_CYBERDEMON, 192, 1000);
        count2 = ThingCount (T_CYBERDEMON, 1000);

        // If the spot was occupied, give it some time to become vacant.
        delay (10);
    }
    until (count2 > count1);
}

First Available In

Hexen
Skull Tag added newtid, which was later adopted by ZDoom 1.23

See Also

Thing_Projectile | Thing_ProjectileGravity | Thing_SpawnFacing | Thing_SpawnNoFog