A_TakeInventory

From ZDoom Wiki
Jump to: navigation, search

bool A_TakeInventory (string type [, int amount [, int flags [, pointer giveto]]])

Usage

Removes amount items of type type from the calling or pointed to actor's inventory. The minimum amount of item of a type in an inventory is zero, removing a greater amount than what the actor actually possesses will not result in a negative amount.

Parameters

  • type: The inventory item to take.
  • amount: The amount to take. If this is 0 or a value which is equal to or greater than the number of samples in the inventory, the item is cleared from the inventory unless it has the INVENTORY.KEEPDEPLETED flag set, and in which case, its amount is merely reduced to 0. Default is 0.
  • flags: There is at the moment only one flag:
    • TIF_NOTAKEINFINITE — If this flag is set, nothing is taken if the type is an Ammo and the player benefits from infinite ammo (either from a powerup or a cheat).
  • giveto: The actor to take the item from. This is an actor pointer, which can be any of the following:
    • AAPTR_DEFAULT — The calling actor itself (default value).
    • AAPTR_NULL — No actor at all.
    • AAPTR_TARGET — The calling actor's target, if any (equivalent to using A_TakeFromTarget).
    • AAPTR_MASTER — The calling actor's master, if any.
    • AAPTR_TRACER — The calling actor's tracer, if any.

Remember that the nature of these pointers depend on the actor type and is not always intuitive.

Return value

The function returns true if the number of samples of type in the pointed-to actor's inventory (before attempting removal) is greater than zero, otherwise it returns false.

Examples

This is a working example of a forgetful imp that uses inventory for timed checks. A_TakeInventory is used to reset the inventory based timer.

ACTOR ForgetfulImp : DoomImp
{
  States
  {
  See:
    TROO AABBCCDD 3 A_Chase
    TROO A 0 A_GiveInventory("Forgettimer", 1) // A dummy inventory for tracking how long the imp has been searching.
    TROO A 0 A_JumpIfInventory("Forgettimer", 20, "Forget") // Jump to the Forget state when the timer reaches 20.
    Loop
  Melee:
  Missile:
    TROO E 0 A_TakeInventory("Forgettimer", 255) // Reset the timer.
    TROO EF 8 A_FaceTarget
    TROO G 6 A_TroopAttack
    Goto See
  Forget: 
    TROO A 0 A_TakeInventory("Forgettimer", 255)
    TROO A 3 A_ClearTarget
    Goto Spawn
  }
}