GiveInventoryType

From ZDoom Wiki
Jump to navigation Jump to search

Inventory GiveInventoryType (class<Inventory> itemtype)

Usage

Gives the specified inventory item to the calling actor. The amount given is as specified by the item's amount property.

Parameters

  • itemtype: the class name of the inventory item to give.

Return value

If the item is received successfully, the function returns a pointer to the item. Otherwise, it returns null.

Examples

This item, upon pickup, increases the player's shell ammo capacity by a random value from 1 to 4.

class ShellACU : Inventory
{
    Default
    {
        Inventory.PickupMessage "Picked up shell ammo capacity upgrade.";
    }

    override bool TryPickup (in out Actor toucher)
    {
        int gain = Random(1, 4);
        class<Inventory> itemcls = "Shell";
        Inventory item = toucher.FindInventory(itemcls);

        if (item)
        {
            item.MaxAmount += gain;
            GoAwayAndDie();
            return true;
        }
        else
        {
            item = toucher.GiveInventoryType(itemcls);

            if (item)
            {
                item.Amount = 0;
                item.MaxAmount += gain;
                GoAwayAndDie();
                return true;
            }
        }

        return false;
    }

    States
    {
    Spawn:
        BPAK A -1; // Uses the Backpack sprite.
        Stop;
    }
}