Hooks redirector template

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Hooks redirector template

Post by Diarmuid »

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:
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,

}
then add this at the end of init.lua:

Code: Select all

import "mod_assets/scripts/party_hooks.lua"
and then put this in the dungeon editor in a script_entity named "hooks":
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
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.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Hooks redirector template

Post by Eleven Warrior »

Hi Diarmuid..

I know I have been waiting for something like this. I have an idea how it works but not 100% sure what to do.. Is it possible to get a Demo EG: Some commands put into your Editor Script to give some idea of what to do?? I know your busy but beginners may not understand what you mean Thxs

1 - Does this take care of the CloneParty in our init.lua files so then all we have to do is add what the scripter wants in the CloneParty Code said?
This is from my init file whitout the end, then etc... EG"

function = onDrawGui
if ( search_script ~= nil and search_script.onDrawGui ~= nil )

2 - onMove = function(self, dir)
skyScript.onMove(dir)
if (gui.globalVars["shopOn"])

3 - onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" )then playSound("mine_horror07")

Sorry for sounding Dumb but your work is awesome, I myself find hard to implement because I don't understand what to do, I do try Hard though..
Thxs for your time Appreciated
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: Hooks redirector template

Post by Diarmuid »

Yeah, the idea is just that you put those lines in a script entity in the dungeon editor instead of the .lua file or init.lua.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Hooks redirector template

Post by Eleven Warrior »

Hi Ohhh man that is so cool.. Now i have to try this out for sure, i feel the headaches going alread.. If this works for me, then this will be the best thing since sliced bread LOL.. Thxs diarmuid awesome..
Post Reply