TakeInventory (Actor)
(Redirected from TakeInventory (ZScript))
Jump to navigation
Jump to search
Note: This function is for ZScript. For the ACS function of the same name see TakeInventory. |
bool TakeInventory(class<Inventory> itemclass, int amount, bool fromdecorate = false, bool notakeinfinite = false)
Usage
A ZScript-only variant of A_TakeInventory. Takes the specified amount of the specified Inventory class from the calling actor's inventory.
Parameters
- class<Inventory> itemclass
- The name of the Inventory item class that should be taken.
- int amount
- The amount of the specified item to take.
- bool fromdecorate
- If this is
false
, the notakeinfinite check is skipped. The item's amount is reduced, DepleteOrDestroy is called if it reached 0, and the function unconditionally returnsfalse
.
- bool notakeinfinite
- If this is
true
AND fromdecorate istrue
, the item will not be taken if itemclass is an Ammo class and the user either has a PowerInfiniteAmmo-based powerup, or the sv_infiniteammo cheat is enabled.
Return values
- bool — The function may return
true
orfalse
depending on the result:
- If the fromdecorate argument is
false
, the function always returnsfalse
. - Otherwise, if the notakeinfinite argument is
true
, itemclass is an Ammo class, and the caller has PowerInfiniteAmmo or uses the sv_infiniteammo cheat, the function returnsfalse
. - Otherwise, if after the TakeInventory call the caller still has some amount of itemclass' left, the function returns
true
; if caller has none left, it returnsfalse
.
- If the fromdecorate argument is
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. |
bool TakeInventory(class<Inventory> itemclass, int amount, bool fromdecorate = false, bool notakeinfinite = false)
{
amount = abs(amount);
let item = FindInventory(itemclass);
if (item == NULL)
return false;
if (!fromdecorate)
{
item.Amount -= amount;
if (item.Amount <= 0)
{
item.DepleteOrDestroy();
}
// It won't be used in non-decorate context, so return false here
return false;
}
bool result = false;
if (item.Amount > 0)
{
result = true;
}
// Do not take ammo if the "no take infinite/take as ammo depletion" flag is set
// and infinite ammo is on
if (notakeinfinite &&
(sv_infiniteammo || (player && FindInventory('PowerInfiniteAmmo', true))) && (item is 'Ammo'))
{
// Nothing to do here, except maybe res = false;? Would it make sense?
result = false;
}
else if (!amount || amount >= item.Amount)
{
item.DepleteOrDestroy();
}
else item.Amount -= amount;
return result;
}
Examples
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. |