UseInventory (ZScript)
Jump to navigation
Jump to search
bool UseInventory (Inventory item)
Usage
Uses the specified item from the inventory. The actor must be alive and the item must be present in its inventory to be used. Note that what is passed to the function is a pointer to the item, not a class. Also note that the pointer should only be passed to the function if it is not null, as the function does not handle null pointers by itself.
Return value
If the item is successfully used, the function returns true, otherwise it returns false.
Examples
This item is meant as a quick heal method, activated by the press of a key. It uses a quartz flask from the inventory and logs various messages, such as how many flasks are left after a successful use.
class PotionUse : CustomInventory { States { Pickup: TNT1 A 0 { let pmobj = PlayerPawn(self); if (pmobj == null) return; Inventory potion = FindInventory("ArtiHealth"); if (potion) { if (UseInventory(potion)) { potion = FindInventory("ArtiHealth"); if (potion) { A_Log("\c[Cyan]" .. potion.Amount .. "\c[White] potion(s) left."); } else { A_Log("\c[Cyan]You've used your last potion."); } } } else if (pmobj.health > 0 && pmobj.health < pmobj.GetMaxHealth()) { A_Log("\c[Red]You don't have any potions."); } } Stop; } }