SetInventory
Jump to navigation
Jump to search
bool SetInventory(Class<Inventory> itemclass, int amount, bool beyondMax = false)
Usage
A non-action version of A_SetInventory. Sets the amount of itemclass item in the calling actor's inventory to amount
(if the actor didn't have itemclass item at all, it'll be given first).
Parameters
- Class<Inventory> itemclass
- the class name of the item to give. This should be a valid inventory item.
- int amount
- The number the item's
amount
will be set to.
- bool beyondMax
- If true, the amount of the item will be allowed to exceed default MaxAmount for the itemclass class.
Return value
The function returns true
if the item's amount was successfully set. Note, if the calling actor already had the specified amount, it'll return false.
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 SetInventory(class<Inventory> itemclass, int amount, bool beyondMax = false)
{
let item = FindInventory(itemclass);
if (item != null)
{
// A_SetInventory sets the absolute amount.
// Subtract or set the appropriate amount as necessary.
if (amount == item.Amount)
{
// Nothing was changed.
return false;
}
else if (amount <= 0)
{
//Remove it all.
return TakeInventory(itemclass, item.Amount, true, false);
}
else if (amount < item.Amount)
{
int amt = abs(item.Amount - amount);
return TakeInventory(itemclass, amt, true, false);
}
else
{
item.Amount = (beyondMax ? amount : clamp(amount, 0, item.MaxAmount));
return true;
}
}
else
{
if (amount <= 0)
{
return true;
}
item = Inventory(Spawn(itemclass));
if (item == null)
{
return false;
}
else
{
item.Amount = amount;
item.bDropped = true;
item.bIgnoreSkill = true;
item.ClearCounters();
if (!item.CallTryPickup(self))
{
item.Destroy();
return false;
}
return true;
}
}
return false;
}
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. |