Creating new monsters or other complex items

From ZDoom Wiki
Jump to navigation Jump to search

Monsters are just regular actors that call some specific monster AI action functions:

It's these functions that make an actor act like a monster but there's a few more things to observe:

  • Use the Monster property. This sets up all the necessary flags to make an actor act like a monster.
  • A monster's height and radius should be set properly. Unlike decorations it is essential that these values are correct because they are used by the collision detection code which also checks whether a monster has been hit by a weapon.
  • A monster should have proper definitions for all standard sounds or it might remain silent in certain situations.
  • A monster requires a minimum set of states:
  • Spawn: This should define a looping 'idle' sequence. This sequence has to call A_Look or A_Look2 repeatedly so that the monster can react to players.
  • See: This defines a looping walking sequence. This sequence has to call A_Chase or one of its variants repeatedly so that the monster can walk around and do things.
  • Melee/Missile: This defines a near or far attack sequence. At least one of them is needed so that the monster is able to attack players or other monsters
  • Death: This is called when the monster's health goes below zero.
You can also define one of the optional special death sequences, a Pain state which makes the monster react to being attacked or the Raise state which makes it resurrectable by Arch-Viles or other monsters capable of doing that.


This is an example of a properly defined monster. It is just an exact replica of Doom's pistol shooting Zombie:

actor ZombieClone 3004
{
  SpawnID 4
  Obituary "%o was killed by a zombieman."
  Health 20
  Radius 20
  Height 56
  Mass 100
  Speed 8
  PainChance 200
  SeeSound "grunt/sight"
  AttackSound "grunt/attack"
  PainSound "grunt/pain"
  DeathSound "grunt/death"
  ActiveSound "grunt/active"
  DropItem "Clip" 256
  Monster
  +FLOORCLIP
  States
  {
  Spawn:
    POSS AB 10 A_Look
    loop
  See:
    POSS AABBCCDD 4 A_Chase
    loop
  Missile:
    POSS E 10 A_FaceTarget
    POSS F 8 A_PosAttack
    POSS E 8
    goto See
  Pain:
    POSS G 3
    POSS G 3 A_Pain
    goto See
  Death:
    POSS H 5
    POSS I 5 A_Scream
    POSS J 5 A_NoBlocking
    POSS K 5
    POSS L -1
    stop
  XDeath:
    POSS M 5
    POSS N 5 A_XScream
    POSS O 5 A_NoBlocking
    POSS PQRST 5
    POSS U -1
    stop
  Raise:
    POSS KJIH 5
    goto See
  }
}


If you don't need a complete monster but ony a subset of its functions you can do so. For example to create a shootable item that doesn't act as a monster all you have to do is to remove the See state, the call to A_Look in the spawn state and replace the Monster property with the appropriate flags. The one flag you need is SHOOTABLE but normally you might want to set a few others as well. This is an example of a shootable decoration:

actor FloorLamp 10247
{
  Health 1
  Radius 16
  Height 51
  DeathSound "misc/glass"
  +SHOOTABLE
  +SOLID
  +NOBLOOD
  states
  {
  Spawn:
    HAWA A -1 Bright
    Loop
  Death:
    HAWA B 11 A_Scream
    HAWA C 9
    HAWA D -1 A_Fall
    Stop
  }
}


Other things are possible as well, for example an actor that reacts to seeing a player but instead of waking up and attacking the player it is doing something else, for example playing a sound:

actor TriggerSound1 10601
{
  SeeSound "ts1"
  +NOBLOCKMAP
  states
  {
  Spawn:
    TNT1 A 2 A_Look
    Loop
  See:
    TNT1 A 1
    Stop
  }
}