Hooks redirector template
Posted: Mon Oct 14, 2013 8:54 pm
Credits to Xanathar originally for the idea who used it for testing purposes in his mod, and I adapted the solution for the ORRR2.
As I see here everyday questions on where to put hooks, how to integrate different scripts together and so on, I thought I might just share the template.
Essentially, the idea here is just to have a standard party_hooks.lua which redirects all hooks to a hooks script entity in the dungeon editor, that way you can only have ONE cloneObject of the party, put all hooks directly in the editor without Ctrl-R all the time, and adjust easily any execution order/override behaviours between different scripts.
So put that in a party_hooks.lua file in mod_assets/scripts:
then add this at the end of init.lua:
and then put this in the dungeon editor in a script_entity named "hooks":
Of course, this is just a template to make your life easier, it's not doing anything on its own. Using this just saves you a bunch of typing, I now automatically put this in any dungeon I start.
NOTE: This IS NOT COMPATIBLE with the LoG framework or grimwidgets just like that. It can be made to work (which we did in the ORRR2) if you manually copy the required function calls to fw or gw. But out of the box, this will disable a lot of their functionality.
As I see here everyday questions on where to put hooks, how to integrate different scripts together and so on, I thought I might just share the template.
Essentially, the idea here is just to have a standard party_hooks.lua which redirects all hooks to a hooks script entity in the dungeon editor, that way you can only have ONE cloneObject of the party, put all hooks directly in the editor without Ctrl-R all the time, and adjust easily any execution order/override behaviours between different scripts.
So put that in a party_hooks.lua file in mod_assets/scripts:
SpoilerShow
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onDrawGui = function(g)
hooks.party_onDrawGui(g);
end,
onDrawInventory = function(g, C)
hooks.party_onDrawInventory(g, C);
end,
onDrawStats = function(g, C)
hooks.party_onDrawStats(g, C);
end,
onDrawSkills = function(g, C)
hooks.party_onDrawSkills(g, C);
end,
onMove = function(party, direction)
return hooks.party_onMove(party, direction);
end,
onTurn = function(party, direction)
return hooks.party_onTurn(party, direction);
end,
onAttack = function(champion, weapon)
return hooks.party_onAttack(champion, weapon);
end,
onDamage = function(champ, damage, damagetype)
return hooks.party_onDamage(champ, damage, damagetype);
end,
onProjectileHit = function(champion,projectile,damage,damageType)
return hooks.party_onProjectileHit(champion,projectile,damage,damageType);
end,
onDie = function(champion)
return hooks.party_onDie(champion);
end,
onUseItem = function(champion, item, slot)
return hooks.party_onUseItem(champion, item, slot);
end,
onRest = function()
return hooks.party_onRest();
end,
onWakeUp = function()
return hooks.party_onWakeUp();
end,
onLevelUp = function(c)
return hooks.party_onLevelUp(c);
end,
onPickUpItem = function(self, item)
return hooks.party_onPickUpItem(self, item);
end,
onReceiveCondition = function(champion, condition, value)
return hooks.party_onReceiveCondition(champion, condition, value);
end,
onCastSpell = function(champion, spell)
return hooks.party_onCastSpell(champion, spell);
end,
}Code: Select all
import "mod_assets/scripts/party_hooks.lua"
SpoilerShow
Code: Select all
function party_onMove(party, direction)
end
function party_onAttack(champion, weapon)
end
function party_onTurn(party, direction)
end
function party_onDamage(champion, damage, damagetype)
end
function party_onProjectileHit(champion, projectile, damage, damageType)
end
function party_onDie(champion)
end
function party_onUseItem(champion, item, slot)
end
function party_onRest()
end
function party_onWakeUp()
end
function party_onReceiveCondition(champion, condition, value)
end
function party_onCastSpell(champion, spell)
end
function party_onLevelUp(c)
end
function party_onPickUpItem(self, item)
end
function party_onDrawGui(g)
end
function party_onDrawInventory(g, C)
end
function party_onDrawStats(g, C)
end
function party_onDrawSkills(g, C)
end
NOTE: This IS NOT COMPATIBLE with the LoG framework or grimwidgets just like that. It can be made to work (which we did in the ORRR2) if you manually copy the required function calls to fw or gw. But out of the box, this will disable a lot of their functionality.