Scripting Hooks

Scripting hooks are Lua functions that can be added to asset definitions. Hooks can be used to extend and customize behavior of assets that support hooks. Hooks are called when certain events occur in the engine and before the corresponding action is executed. Most actions can be cancelled by returning false from the hooks. For example, the onPickUpItem hook in Party class is called when an item is about to be picked up. If the hook returns false, the pick up action is cancelled.

For example, the following script when placed in dungeon’s init.lua will add onMove and onTurn hooks to party class:

cloneObject{
   name = "party",
   baseObject = "party",

   onMove = function(self, dir)
       print("party moves in direction", dir)
   end,

   onTurn = function(self, dir)
       print("party turns", dir)
       return false -- returning false cancels the action, so the party is unable to turn!
   end,
}

See Asset Definition Reference for supported hooks.