CanPickup

From ZDoom Wiki
Jump to navigation Jump to search

Inventory

virtual bool CanPickup(Actor toucher)

Usage

A virtual function called by Inventory items from their CallTryPickup function to determine if the actor who is trying to receive this item (the toucher) is allowed to receive it.

Can be overridden to add specific conditions to when the item can be picked up. By default items use it to handle the inner workings behind the Inventory.RestrictedTo and Inventory.ForbiddenTo properties.

If you want to modify the pickup rules from the recipient of the item rather than the item itself, see CanReceive.

Note: If this function returns false but the item does NOT have the INVENTORY.RESTRICTABSOLUTELY flag, its result may be overridden by TryPickupRestricted.


Parameters

  • Actor toucher
The actor who is trying to receive this item.

Return values

Returning true tells the game that toucher can pick up this 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.

This function can be overridden, but the base Inventory class defines it as follows:

	virtual bool CanPickup(Actor toucher)
	{
		if (toucher == null) return false;

		int rsize = RestrictedToPlayerClass.Size();
		if (rsize > 0)
		{
			for (int i=0; i < rsize; i++)
			{
				if (toucher is RestrictedToPlayerClass[i]) return true;
			}
			return false;
		}
		rsize = ForbiddenToPlayerClass.Size();
		if (rsize > 0)
		{
			for (int i=0; i < rsize; i++)
			{
				if (toucher is ForbiddenToPlayerClass[i]) return false;
			}
		}
		return true;
	}

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