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 : CustomInventory
{
    Default
    {
        Inventory.PickupMessage "Picked up shell ammo capacity upgrade.";
    }

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

    Pickup:
        TNT1 A 0
        {
            int gain = Random(1, 4);
            class<Inventory> itemcls = "Shell";
            Inventory item = FindInventory(itemcls);

            if (item)
            {
               item.MaxAmount += gain;
            }
            else
            {
                item = GiveInventoryType(itemcls);

                if (item)
                {
                    item.Amount = 0;
                    item.MaxAmount += gain;
                }
            }
        }
        Stop;
    }
}