GiveInventory (Actor)
Jump to navigation
Jump to search
Note: This is a ZScript Actor function. For a static function with similar functionality, see GiveInventory (ScriptUtil). For the ACS function of the same name, see GiveInventory. |
bool GiveInventory(Class<Inventory> type, int amount, bool givecheat = false)
Usage
A non-action version of A_GiveInventory. Adds amount
items of type type
to the calling actor's inventory. This function will not add more items than can be carried.
If type
is an armor item, be it a BasicArmorPickup or a BasicArmorBonus, then amount
is treated as a multiplier to the item's save amount, e.g. if type
is BlueArmor and amount
is 3
, then a combat armor with 600 armor points is given.
Parameters
- Class<Inventory> type
- the class name of the item to give. This should be a valid inventory item.
- int amount
- The number of samples of this item to give.
- bool givecheat
- If true, treats the item as being given by the give console command. Default is false.
Return value
The function returns true
if the item is successfully received, otherwise it returns 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 GiveInventory(Class<Inventory> type, int amount, bool givecheat = false)
{
bool result = true;
let player = self.player;
// This can be called from places which do not check the given item's type.
if (type == null || !(type is 'Inventory')) return false;
Weapon savedPendingWeap = player != NULL ? player.PendingWeapon : NULL;
bool hadweap = player != NULL ? player.ReadyWeapon != NULL : true;
Inventory item;
if (!givecheat)
{
item = Inventory(Spawn (type));
}
else
{
item = Inventory(Spawn (type, Pos, NO_REPLACE));
if (item == NULL) return false;
}
// This shouldn't count for the item statistics.
item.ClearCounters();
if (!givecheat || amount > 0)
{
item.SetGiveAmount(self, amount, givecheat);
}
if (!item.CallTryPickup (self))
{
item.Destroy ();
result = false;
}
// If the item was a weapon, don't bring it up automatically
// unless the player was not already using a weapon.
// Don't bring it up automatically if this is called by the give cheat.
if (!givecheat && player != NULL && savedPendingWeap != NULL && hadweap)
{
player.PendingWeapon = savedPendingWeap;
}
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. |