Hook framework (a.k.a LoG Framework 2)

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Hook framework (a.k.a LoG Framework 2)

Post by Aisuu »

I will try it as soon as I get home and I let you know. Thank you very much :)
Teto
Posts: 7
Joined: Sat Apr 28, 2012 11:51 am

Re: Hook framework (a.k.a LoG Framework 2)

Post by Teto »

JKos wrote:
Teto wrote:Sorry about my dumbness, what is a hook ? (it's not clear in the documentation, or I missed something) :oops:
They are like event handlers. See LoG 1 documentation:
http://www.grimrock.net/modding_log1/scripting-hooks/
Oh, thanks a lot ! :P
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Hook framework (a.k.a LoG Framework 2)

Post by Aisuu »

Works.. :mrgreen:
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Hook framework (a.k.a LoG Framework 2)

Post by JKos »

Small bug fix: fw.script:remove('hook.identi.fier') didn't work.
Just update the fw.lua https://sites.google.com/site/jkoslog2/install/fw.lua
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Hook framework (a.k.a LoG Framework 2)

Post by Aisuu »

Guys, little help in here.

Iam trying to create hook for item onPickUpItem. But my code doesnt work :cry:
SpoilerShow

Code: Select all

fw.script:set('my_item@item.mymod.onPickUpItem',function()
     hudPrint("picked up")
end)
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Hook framework (a.k.a LoG Framework 2)

Post by JKos »

That's because the game doesn't have a Item.onPickUpItem-hook, instead it has a party.onPickUpItem-hook. But since item.onPickupItem will be useful and it's easy to implement I added it to the framework.

Open fw_hooks.lua and replace party.onPickUpItem function definition with this:

Code: Select all

		onPickUpItem = function(self, item) 	 
			if fw.script:executeEntityHooks('item','onPickUpItem',item) == false then
				return false
			end
			return fw.script:execute('party','onPickUpItem',self, item) 	 
		end,
Now it should work. I will update the fw_hooks.lua too soon, so if you don't want to modify it by hand you can wait that. But I decided to post this as an example that shows how you can add your own hooks to the framework. It's possible to call executeEntityHooks from script entities too, so if you want to handle your custom events through the framework, it's really easy.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Hook framework (a.k.a LoG Framework 2)

Post by Aisuu »

WoW :D I will test it, if I get home and let you know if I have any problems. Many thx for help :mrgreen:
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Hook framework (a.k.a LoG Framework 2)

Post by cameronC »

Hello, JKos. I've got an item that gains a secondary action. A new MeleeAttack component is created named specialattack and then the item's secondaryAction is set to specialattack and the other properties of the attack are then defined in script (attackPower, Cooldown, etc). weapon.go.id correctly returns the id of the item in question, though nothing prints (The specialattack secondaryAction is available and performs without error, of course). What have I done wrong?

Code: Select all

fw.script:set(weapon.go.id .. '@specialattack.mymod.onHitMonster', function()
			print("HIYA! ")
		end)
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Hook framework (a.k.a LoG Framework 2)

Post by JKos »

By default the framework only works with components which are named by the class name. That's because we can't access the component name from the scripts, so I can't do anything about it.
But if you really need to to use the framework with custom named components you can do it like this.

Code: Select all

		{
			class = "MeleeAttack",
			name = "specialattack",
			attackPower = 16,
			accuracy = 0,
			damageType = "shock",
			cooldown = 3.7,
			swipe = "vertical",
			attackSound = "swipe",
			requirements = { "light_weapons", 1 },
			onHitMonster = function(self, monster, tside, damage, champion) 	 
			    return fw.script:executeEntityHooks('specialattack','onHitMonster',self, monster, tside, damage, champion) 	 
			end,
		},
Now it should work. And as you can see, the name of the component and hook method are hard coded.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Eleven Warrior
Posts: 746
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Hook framework (a.k.a LoG Framework 2)

Post by Eleven Warrior »

Hi all sorry about this I have tried this as a test and it's not working could someone tell where imam going wrong.. Is it possible if we could get more demo's on how to do things, just simple stuff :)
The error I get is: attempt to index global 'weapon' ('a nil value')

I did just copy and paste the dagger out of the Assets lua Script.

Object: my_dagger.

Code: Select all

defineObject{
	name = "my_dagger",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/dagger.fbx",
		},
		{
			class = "Item",
			uiName = "Dagger",
			gfxIndex = 10,
			gfxIndexPowerAttack = 415,
			impactSound = "impact_blade",
			weight = 0.8,
			projectileRotationX = 90,
			projectileRotationY = 90,
			description = "A vicious looking dagger, which is effective in close combat as well as from a distance. The dagger is the favorite weapon of many a rogue.",
			traits = { "light_weapon", "dagger" },
		},
		{
			class = "MeleeAttack",
			attackPower = 7,
			accuracy = 5,
			cooldown = 2.5,
			swipe = "vertical",
			attackSound = "swipe_light",
			powerAttackTemplate = "throw",

onHitMonster = function(self, monster, tside, damage, champion)
return fw.script:executeEntityHooks('specialattack','onHitMonster',self, monster, tside, damage, champion)
end,
		},
	},
	tags = { "weapon" },
}
Script Code in Editor:

Code: Select all

fw.script:set(weapon.go.id .. 'specialattack.mymod.onHitMonster', function()
print("Why did you hit me? ")
end)
EDIT: Say a player picks up a item you could have a huPrint, sound etc.. How do you do this? Thxs for any help.
Post Reply