Classes:CustomInventory

From ZDoom Wiki

Jump to: navigation, search
Custom inventory
Actor type Internal Game
DoomEd Number None Class Name CustomInventory

Classes: InventoryCustomInventory

 →ArtiBoostMana
 →ArtiEgg
 →ArtiPork
 →Berserk
 →Mana3
 →Megasphere

CustomInventory items are special items that allow some very primitive scripted functionality using its states. The base class CustomInventory is never used directly. It is always the base class for items defined in DECORATE.

DECORATE definition

Actor CustomInventory : Inventory native {}

Using in DECORATE

CustomInventory defines no new properties and only uses the basic Inventory properties.


CustomInventory defines 3 new states:

  • Pickup
  • Use
  • Drop

The behavior is as follows:

  • All code pointers in the Pickup state sequence are called when the item is being picked up. The sequence is successful when either a function is called which doesn't return success or a function which is capable returns successful execution is called (you can also use ACS_ExecuteWithResult to set the result from ACS). Success can be overridden by terminating the state sequence with fail instead of stop.
If the Pickup sequence returns successfully the behavior depends on the presence of the Use state:
  • If there is no Use state the item will be removed from the map and not be placed in the player's inventory.
  • If there is a Use state the item will be placed in the player's inventory.
  • If the item has a Use state and is being used by the player the Use state sequece is called. Failure or success are determined the same way as for the Pickup state. If the sequence returns successfully the item is removed from the inventory. Note that due to this special behavior, the Use state will ignore all frame durations and cannot be looped; every frame will execute within the same tic.
  • If the item is being dropped by a monster the Drop state sequence will be executed and the item will never be spawned. This is mostly there for special actions that can be taken by Strife conversation scripts. For regular monster death actions there are better and more flexible way to achieve the same.

Note:

The Pickup can sometimes fail in a way that isn't actually an error; for example, if you give to the inventory something that the player already has the maximum of, the A_GiveInventory call returns 0 because nothing was added. Normally this if fine, but what if your custom inventory actor should always be picked up? Of course it will be if you use the ALWAYSPICKUP inventory flag; but even then, the pickup message and sound will be omitted by the engine in that case.

In fact, some of the predefined DOOM actors, for example the MegaSphere, are actually implemented in ZDoom as custom inventory items and exhibit exactly this problem - try cheating to 200% health and armour, then summon a MegaSphere; when you pick it up, there's no "Megasphere!" message!

So if you always want your item to appear to "really" be picked up under all circumstances, and given that there is no "success" equivalent of the "fail" command, at least one code pointer in the Pickup sequence must always either return a non-zero result or not return a result at all; one way of achieving this is to call a code pointer that doesn't return a result and in a way that makes it actually change nothing.

The easiest way discovered so far is to use A_ChangeFlag to turn off a flag that is always OFF for a player anyway, such as the ACTLIKEBRIDGE flag, because in a custom inventory item most code pointers affect the player who picked the item up, rather than the item itself. Calling A_ChangeFlag("ACTLIKEBRIDGE", 0) on a player changes nothing, but it forces a successful Pickup sequence because A_ChangeFlag doesn't return a result at all.

Examples:

actor BigBoost : CustomInventory 10492
{
  inventory.pickupmessage "Energy Boost!!!"
  inventory.pickupsound "misc/p_pkup"
  +COUNTITEM
  states
  {
  Spawn:
    AWI3 A -1
    stop
  Pickup:
    TNT1 A 0 A_GiveInventory ("Soulsphere", 2)
    TNT1 A 0 A_GiveInventory ("BFG9000")
    stop
  }
}
// The same actor, modified so that it is always
// picked up and always shows the pickup message
// even when the player already has the items.
actor BigBoostAlways : CustomInventory 10492
{
  inventory.pickupmessage "Energy Boost!!!"
  inventory.pickupsound "misc/p_pkup"
  +INVENTORY.ALWAYSPICKUP
  +COUNTITEM
  states
  {
  Spawn:
    AWI3 A -1
    stop
  Pickup:
    TNT1 A 0 A_GiveInventory ("Soulsphere", 2)
    TNT1 A 0 A_GiveInventory ("BFG9000")
    TNT1 A 0 A_ChangeFlag ("ACTLIKEBRIDGE", 0)
    stop
  }
}
Personal tools