DepleteOrDestroy

From ZDoom Wiki
Jump to navigation Jump to search

Inventory

Usage

A virtual function used by the Inventory class. Normally, this is called automatically when the item's amount is reduced to 0 by any means, to determine if an instance of this item should still stay in the owner's inventory, or if it should be removed entirely. By default, it only checks for the presence of the KEEPDEPLETED flag, but it can be overridden to add custom behavior.

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.


	virtual void DepleteOrDestroy ()
	{
		// If it's not ammo or an internal armor, destroy it.
		// Ammo needs to stick around, even when it's zero for the benefit
		// of the weapons that use it and to maintain the maximum ammo
		// amounts a backpack might have given.
		// Armor shouldn't be removed because they only work properly when
		// they are the last items in the inventory.
		if (bKeepDepleted)
		{
			Amount = 0;
		}
		else
		{
			Destroy();
		}
	}

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