GetWeapon

From ZDoom Wiki
Jump to: navigation, search

str GetWeapon (void);

Usage

Retrieves the class name of the weapon currently equipped by the player.

Return Value

Returns the class name of the weapon currently equipped by the player as a string.

Example

This script, when called, will give the player a little bit of ammunition depending on the currently equipped weapon.

Script "Ammo provider" (void)
{
  str weapon = GetWeapon();
  
  If(StrIcmp(weapon, "Pistol") == 0 || StrIcmp(weapon, "Chaingun") == 0)
  {
    GiveInventory("Clip", 10);
    Log(s:"Received a clip.");
  }

  Else If(StrIcmp(weapon, "Shotgun") == 0 || StrIcmp(weapon, "SuperShotgun") == 0)
  {
    GiveInventory("Shell", 4);
    Log(s:"Received 4 shotgun shells.");
  }

  Else If(StrIcmp(weapon, "RocketLauncher") == 0)
  {
    GiveInventory("RocketAmmo", 1);
    Log(s:"Received a rocket.");
  }

  Else If(StrIcmp(weapon, "PlasmaRifle") == 0 || StrIcmp(weapon, "BFG9000") == 0)
  {
    GiveInventory("Cell", 20);
    Log(s:"Received an energy cell.");
  }

  Else Print(s:"A firearm needs to be equipped first to receive ammo for it");
}