Skip to content

Callbacks

MrOinky edited this page Nov 13, 2022 · 3 revisions

Callbacks

Pie adds several new callbacks to the Item class that can be overriden to add extra functionality to items. Item callbacks only run on items that are equipped by an active party member. Many callbacks are equivalent to callbacks from other objects in Kristal, and these equivalents are shown where they exist. Because of how Pie implements callbacks that mimick from other classes, it is essential that the super version of the callback is called whenever these are overriden, in order for all callbacks in the Item class to function correctly.

Item callbacks can be overriden as any other function would be in an item:

local item, super = Class(Item)

function item:init()
    super:init(self)
    -- Item init code goes here
end

-- Example callback override
function item:callbackName(battler, ...)
    -- Code goes here
end

return item

Available Callbacks

Every callback contains different arguments that may be of use when adding functionality, listed after each entry.

The first argument of a callback will always be battler which references the batter holding the item.

Item:onBattleInit(battler) - Called whenever a battle initializes. Item equivalent of Encounter:onBattleInit().

Item:onBattleStart(battler) - Called whenever a battle begins. Item equivalent of Encounter:onBattleStart().

Item:onBattleEnd(battler) - Called whenever a battle ends. Item equivalent of Encounter:onBattleEnd().

Item:onTurnStart(battler, turn) - Called when a new turn begins in battle. Item equivalent of Encounter:onTurnStart().

  • turn (integer): The current turn of the battle, starting at 1.

Item:onTurnEnd(battler, turn) - Called when a turn ends in battle. Item equivalent of Encounter:onTurnEnd().

  • turn (integer): The current turn of the battle, starting at 1.

IMPORTANT: if you are overriding onTurnEnd(), you must call super:onTurnEnd() for some library functionality to work correctly.

Item:onActionsStart(battler) - Called when the party begin to complete their Actions in battle. Item equivalent of Encounter:onActionsStart().

Item:onActionsEnd(battler) - Called when the party finish their Actions in battle. Item equivalent of Encounter:onActionsEnd().

Item:beforeStateChange(battler, old, new) - Called when a state change occurs in battle, before the change has actually taken effect. Item equivalent of Encounter:beforeStateChange(battler, old, new).

  • old (string): The current state of the battle.
  • new (string): The state that the battle is changing to.

Item:onStateChange(battler, old, new) - Called when a state change occurs in battle. Item equivalent of Encounter:onStateChange(battler, old, new)

  • old (string): The previous state of the battle.
  • new (string): The state that the battle has changed to.

Item:beforeGameOver(battler) - Called just before the game over process begins, when all of the party have been downed. If this callback returns true, then the game over process will be cancelled, and the active wave will continue. This is a callback NEW to Pie, but there is also an implemented Encounter variation of the callback, Encounter:beforeGameOver().

Item:onGameOver(battler) - Called after the game over process ends the current wave, before triggering the heart-break animation. If this callback returns true, then the game over process will be cancelled. Item equivalent of Encounter:onGameOver().

Item:onEnemyHit(battler, enemy, damage) - Called when the holder of this item deals any damage to an enemy.

  • enemy (EnemyBattler): The EnemyBattler instance attacked by this battler.
  • damage (integer): The amount of damage dealt to enemy.

Item:beforeHolderHurt(battler, damage, defending) - Called just before the holder of this item is hurt by an attack. If this callback returns true, the holder will not take any damage.

  • damage (integer): The amount of damage that will be dealt to battler.
  • defending (boolean): Whether battler is currently defending.

IMPORTANT: if you are overriding beforeHolderHurt(), you must call super:beforeHolderHurt() for some library functionality to work correctly.

Item:onHolderHurt(battler, damage, defending) - Called when the holder of this item is hurt by an attack.

  • damage (integer): The amount of damage taken by battler.
  • defending (boolean): Whether battler is currently defending.

IMPORTANT: if you are overriding onHolderHurt(), you must call super:onHolderHurt() for some library functionality to work correctly.

Item:beforeHolderDowned(battler) - Called just before the holder of this item is downed. If this callback returns true, the holder will not be downed.

Item:onHolderDowned(battler) - Called when the holder of this item is downed.

Item:onDodge(battler, damage, defending) (New in v1.1.0) - Called when this item triggers its dodge effect. Creates a "miss" text and plays a sound by default.

  • damage (integer): The amount of damage taken by battler.
  • defending (boolean): Whether battler is currently defending.

Item:onThorns(battler, damage, thorned, enemy, defending) (New in v1.1.0) - Called when this item triggers its thorns effect. Plays a sound by default.

  • damage (integer): The amount of damage taken by battler.
  • thorned (integer): The amount of damage dealt to enemy.
  • enemy (EnemyBattler): The enemy struck by the thorns effect.
  • defending (boolean): Whether battler is currently defending.

Item:onReflect(battler, damage, reflected, enemy, defending) (New in v1.1.0) - Called when this item triggers its reflect effect. Plays a sound by default.

  • damage (integer): The amount of damage taken by battler.
  • reflected (integer): The amount of damage dealt to enemy.
  • enemy (EnemyBattler): The enemy struck by the thorns effect.
  • defending (boolean): Whether battler is currently defending.

Clone this wiki locally