A_SelectWeapon

From ZDoom Wiki
Jump to navigation Jump to search

bool A_SelectWeapon (class<Weapon> whichweapon [, int flags])

Usage

Selects the specified weapon type as the calling player's current weapon.

Parameters

  • whichweapon: the class name of the weapon to switch to. Unless the SWF_SELECTPRIORITY flag is passed, this has to be a valid weapon and the weapon must be present in the player's inventory for the switch to happen. The function will be carried out whether or not the weapon to switch to has ammo.
  • flags: Default is 0.
    • SWF_SELECTPRIORITY — if the specified weapon is either invalid or does not exist in the inventory and this flag is set, the function switches to the highest priority weapon the player has, in the same vein as running out of ammo.

Return value

The function returns true if the weapon switch happens, otherwise it returns false.

Examples

This berserk pack uses A_SelectWeapon to change to a new unarmed attack which replaces the fist.

actor NewBerserk : Berserk
{
    States
    {
    Pickup:
        TNT1 A 0 A_GiveInventory("PowerStrength") 
        TNT1 A 0 HealThing(100)
        TNT1 A 0 A_SelectWeapon("KoolFist")
        Stop
    } 
}


This rather odd item, when picked up, tries to switch the player's weapon to the BFG9000. If the weapon exists in the player's inventory, the switch happens and the player receives 40 points of energy cells. If, however, the switch fails, i.e the player does not have the weapon, the player gets damage by half of his or her health.

actor OddArtifact : Megasphere
{
    Inventory.PickupMessage "Oddsphere!"

    States
    {
    Pickup:
        TNT1 A 0
        { // See anonymous functions.
            if (A_SelectWeapon("BFG9000"))
            {
                A_GiveInventory("Cell", 40);
            }
            else
            {
                A_DamageSelf(health / 2);
            }
        }
        Stop
    }
}