From ZDoom Wiki
Jump to navigation Jump to search


virtual void AddInventory(Inventory item)


A virtual function called by an actor to attach a specific, already existing Inventory item to their inventory. In contrast to GiveInventory and similar functions, this doesn't create a new item but is meant to attach an instance of an item that already exists in the world.

Can be overridden to add custom behavior executed by actors when they receive items.


  • Inventory item
A pointer to an item that should be placed in the calling actor's inventory.

ZScript definition

Note: The ZScript definition below is for reference and may be different in the current version of GZDoom.The most up-to-date version of this code can be found on GZDoom GitHub.

Various actors may override this function, but the base Actor class defines it as follows:

	virtual void AddInventory (Inventory item)
		// Check if it's already attached to an actor
		if (item.Owner != NULL)
			// Is it attached to us?
			if (item.Owner == self)

			// No, then remove it from the other actor first
			item.Owner.RemoveInventory (item);

		item.Owner = self;
		item.Inv = Inv;
		Inv = item;

		// Each item receives an unique ID when added to an actor's inventory.
		// This is used by the DEM_INVUSE command to identify the item. Simply
		// using the item's position in the list won't work, because ticcmds get
		// run sometime in the future, so by the time it runs, the inventory
		// might not be in the same state as it was when DEM_INVUSE was sent.
		Inv.InventoryID = InventoryID++;


Nuvolachalk.png Note: This article lists no examples. If you make use of this feature in your own project(s) or know of any basic examples that could be shared, please add them. This will make it easier to understand for future authors seeking assistance. Your contributions are greatly appreciated.

See also