CheckActorClass

From ZDoom Wiki
Jump to: navigation, search

bool CheckActorClass (int tid, str class)

Usage

Parameters

  • tid: TID of the actor. Use 0 to refer to the activator.
  • class: The name to which the actor's class name must be compared.

Return value

True if the class given is the same as that of the actor, false otherwise.

Examples

This example tells you if the owner of the tid passed to script 1 is a DoomImp or not.

script 1 (int tid)
{
  if (CheckActorClass(tid, "DoomImp"))
    print(s:"It's an Imp!");
  else
    print(s:"Not an Imp!");
}

You can set this script to an Actor Enters Sector thing to warn the players when a certain type of monster is approaching. Otherwise, you can specify a tid through direct execution. If a tid is not specified it is resolved as 0 or the tid of the activator (getting the activating actor in either case). The script cycles through the list of monster class names given in the monster_class array to find a match and prints a generic message for unlisted classes.

#define NUM_CLASSES       18

str monster_class[NUM_CLASSES] = {
  "Arachnotron", "Archvile", "BaronOfHell",
  "Cacodemon", "ChaingunGuy", "Cyberdemon",
  "Demon", "DoomImp", "Fatso",
  "HellKnight", "LostSoul", "PainElemental",
  "Revenant", "ShotgunGuy", "Spectre",
  "SpiderMastermind", "WolfensteinSS", "ZombieMan"  
};

script 1 (int tid)
{
  int class_index = -1;

  if (!tid && ActivatorTID())
    tid = ActivatorTID();

  for (int i=0; i<NUM_CLASSES; i++)
    if (CheckActorClass(tid, monster_class[i]))
      class_index = i;
 
  if (class_index > -1)
    PrintBold(s:"Look out for the ", s:monster_class[class_index], s:"!");
  else
    PrintBold(s:"Look out for the... wait, what is that?");
}

This example is slightly more complicated (and fun) in that it prints a custom phrase based on the class of the monster.

#define MONST_CLASS_NAME  0
#define MONST_CLASS_MSG   1
#define NUM_CLASSES       18

str monster_msg[NUM_CLASSES][2] = {
  {"Arachnotron", "time to squash this spider!"},
  {"Archvile", "I haaaaaate Arch-Viles..."},
  {"BaronOfHell", "about 5 rockets oughta do the job."},
  {"Cacodemon", "there's something very... 'Manual of the Planes'-ish about it..."},
  {"ChaingunGuy", "even more annoying than the ShotgunGuy!"},
  {"Cyberdemon", "*ca-chunk* *ca-chunk* *ca-chunk* BLAM! AAAH! SPLAT!"}, 
  {"Demon", "watch as it runs to its death!"},
  {"DoomImp", "an Imp, a shell..."},
  {"Fatso", "LOLFATSO"},
  {"HellKnight", "the Baron's red headed stepchild."},
  {"LostSoul", "get the fly swatter!"},
  {"PainElemental", "he won't spit Lost Souls if he can't see you!"},
  {"Revenant", "time for a fist fight!"},
  {"ShotgunGuy", "easy to take out but annoying in numbers."},
  {"Spectre", "who does he think he's hiding from?"},
  {"SpiderMastermind", "did he say 'RURURU'?"},
  {"WolfensteinSS", "hey I didn't know he had a backside!"},
  {"ZombieMan", "anybody need clips?"}
};

script 1 (int tid)
{
  str prefix;
  int class_index = -1;
  
  if (!tid && ActivatorTID())
    tid = ActivatorTID();
  
  for (int i=0; i<NUM_CLASSES; i++)
    if (CheckActorClass(tid, monster_msg[i][MONST_CLASS_NAME]))
      class_index = i;
      
  switch (monster_msg[class_index][MONST_CLASS_NAME])
  {
    case "Arachnotron":
    case "Archvile":
      prefix = "It's an ";
    break;

    default:
      prefix = "It's a ";
    break;
  }
      
  if (class_index > -1)
    PrintBold(s:prefix, s:monster_msg[class_index][MONST_CLASS_NAME], 
      s:", ", s:monster_msg[class_index][MONST_CLASS_MSG]);
  else
    PrintBold(s:"Uh... what is it?");
}

See also