AttachToOwner

From ZDoom Wiki
Jump to navigation Jump to search

Inventory

virtual void AttachToOwner(Actor other)

Usage

A virtual function called by Inventory items when they've been received (TryPickup has run successfully) and the item now has to be attached to the recipient's inventory. The item in this case can be either the original item, or a copy created via CreateCopy (for example, in multiplayer, Key|keys copy themselves rather than being picked up directly, so that the original key can stay behind to be picked up by other players).

Can be overridden to add custom behavior executed by items once they've become a part of an actor's inventory.

Important notes:

  • This function is only executed when an item is received for the first time (ther other actor doesn't have an instance of this item in ther inventory). When items of the same type are received again, this function isn't called; instead they find this instance in the other's inventory and increase its amount and destroy themselves (this happens in TryPickup). If you want something to happen whenever an item is received, even if it's a duplicate, override Use instead.
  • This isn't called at all on items that don't actually get placed in the inventory, like Health, PowerupGiver, BasicArmorPickup and others.

Parameters

  • Actor other
The actor that is receiving the item.

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 items may override this function, but the base Inventory class defines it as follows:

	virtual void AttachToOwner (Actor other)
	{
		BecomeItem ();
		other.AddInventory (self);
	}

See BecomeItem and AddInventory.

Examples

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