GetArmorType

From ZDoom Wiki
Jump to: navigation, search

int GetArmorType (string armortype, int playernum)

Returns true if the player's armor type matches the first parameter.

Parameters

  • armortype: The class name of an armor type. This must be either “None”, the name of a BasicArmorPickup or that of a BasicArmorBonus.
  • playernum: Player number. This information can be obtained through PlayerNumber.

This function targets only players. It concerns only BasicArmor and therefore does not cover HexenArmor.

Return value

The return value is the number of armor points if the player wears the designated armor, 0 otherwise.

Examples

This script constantly informs the first player which kind of Doom armor he is wearing.

#define ARMORTYPES	4

str armor_types[ARMORTYPES] = {
  "ArmorBonus",
  "GreenArmor",
  "BlueArmor",
  "BlueArmorForMegasphere"
};

str armor_messages[6] = {
  "You are unarmored, but have found armor bonuses.",
  "You are wearing security armor.",
  "You are wearing combat armor.",
  "You have a megasphere.",
  "What the hell are you wearing?",
  "You are unarmored."
};

function void PrintArmorType (void)
{
  bool found_armor;

  if (CheckInventory("Armor")) // If player has at least 1 armor point, proceed to check the type...
  {
    for (int i; i<ARMORTYPES; i++)
    {
      if (GetArmorType(armor_types[i], PlayerNumber()))
      {
        found_armor = TRUE;
        break;
      }
    }

    if (found_armor)
    {
      HudMessage(s:armor_messages[i]; HUDMSG_PLAIN, 1, CR_RED, 0.1, 0.9, 1.0);
    }
    else
    {
      HudMessage(s:armor_messages[4]; HUDMSG_PLAIN, 1, CR_RED, 0.1, 0.9, 1.0);
    }
  }
  else // ... otherwise, print the "unarmored" message
  {
    HudMessage(s:armor_messages[5]; HUDMSG_PLAIN, 1, CR_RED, 0.1, 0.9, 1.0);
  }
}

script 1 ENTER
{
  while (TRUE)
  {
    PrintArmorType();
    delay(35);
  }
}