CreateCopy
virtual Inventory CreateCopy (Actor other)
Usage
A virtual function called by Inventory items from their CallTryPickup function. This function will either let the item be directly placed in the toucher's inventory, or will create a copy of the item, and that copy will be placed in the toucher's inventory. The primary purpose of this function is to handle respawnable items. In multiplayer some items, like keys, stay in the world after a player has picked them up, so other players can pick them up as well—this behavior is handled by this function.
Warning: The conditions that determine if the item must be given directly or copied are NOT handled in this function. This function simply creates a copy (or not, if it's not necessary), but the conditions for it are handled through a series of dedicated functions: GoAway, ShouldStay and ShouldRespawn.
Parameters
- Actor toucher
- The actor who is trying to receive this item.
Return values
Returns a pointer to the item that the toucher
will receive: either this will be the calling item, or a freshly c reated copy of the calling 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 Inventory CreateCopy (Actor other)
{
Inventory copy;
Amount = MIN(Amount, MaxAmount);
if (GoAway ())
{
copy = Inventory(Spawn (GetClass()));
copy.Amount = Amount;
copy.MaxAmount = MaxAmount;
}
else
{
copy = self;
}
return copy;
}
Examples
See TryPickup.