Page 2 of 5

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

Posted: Fri Nov 14, 2014 12:02 pm
by Aisuu
I will try it as soon as I get home and I let you know. Thank you very much :)

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

Posted: Fri Nov 14, 2014 2:59 pm
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

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

Posted: Fri Nov 14, 2014 6:47 pm
by Aisuu
Works.. :mrgreen:

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

Posted: Sun Nov 16, 2014 2:03 pm
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

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

Posted: Tue Nov 25, 2014 9:32 pm
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)

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

Posted: Tue Nov 25, 2014 10:27 pm
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.

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

Posted: Wed Nov 26, 2014 9:10 am
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:

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

Posted: Sun Dec 28, 2014 6:21 pm
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)

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

Posted: Sun Dec 28, 2014 7:38 pm
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.

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

Posted: Sun Dec 28, 2014 9:23 pm
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.