DoEffect

From ZDoom Wiki
Jump to navigation Jump to search

Inventory

virtual void DoEffect ()

Usage

A virtual function called every game tic by Inventory items as long as they're in an actor's inventory. It's similar to Tick, except Tick() is called every tic as long as the actor exists.

The owner pointer can be utilized here to do something with the actor who is holding the item.

In the base Inventory class this function is empty. However, it's used in the Powerup class to constantly apply the powerup's effects to its owner.

Error.gif
Warning: The owner pointer CAN become null while this function runs. This can notably happen if the owner dies and its Death state sequence is 0 tics long: the items in their inventory will persist for one extra tic while the owner is null.


Note: This function will not be called if the owner has the NOINTERACTION flag (Verification needed)

Examples

This item will restore 5 health to its ownner every second, similar to PowerRegeneration, but without duration or any other powerup effects:

class RegenerationItem : Inventory
{
    override void DoEffect()
    {
        Super.DoEffect();
        if (owner && owner.health > 0 && GetAge() % TICRATE == 0)
        {
            owner.GiveBody(5);
        }
    }
}

(See GiveBody and the ZScript modulo operator for extra information)

See also