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
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 »

To Elven Warrior:
That error is caused by your script, not the framework. As the message clearly says, the weapon variable is not defined.
And in your example you can just use fw_addHooks because you are using meleeAttack component with default name, no need to call fw.script:executeEntityHooks

Working example:

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" },
          },
         fw_addHooks{
             class = "MeleeAttack",
             attackPower = 7,
             accuracy = 5,
             cooldown = 2.5,
             swipe = "vertical",
             attackSound = "swipe_light",
             powerAttackTemplate = "throw",
          },
       },
       tags = { "weapon" },
    }
Then in some script entity

Code: Select all

fw.script:set('my_dagger@meleeattack.mymod.onHitMonster', function(hook,item,monster)
      print( "Why did you hit me? ")
end)
Link to the documentation can be found from my sig.
- 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 »

Thank you Jkos for the help :) How would I add a onPickUp hook to this dagger so when the party picks it up it will do a hudPrint etc...
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 »

Eleven Warrior wrote:Thank you Jkos for the help :) How would I add a onPickUp hook to this dagger so when the party picks it up it will do a hudPrint etc...
Try this:
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 »

Aisuu wrote:
Eleven Warrior wrote:Thank you Jkos for the help :) How would I add a onPickUp hook to this dagger so when the party picks it up it will do a hudPrint etc...
Try this:
SpoilerShow

Code: Select all


fw.script:set('my_item@item.mymod.onPickUpItem',function()
     hudPrint("picked up")
end)
Yes, but first download the new version of fw_hooks.lua.
https://sites.google.com/site/jkoslog2/install
I just updated it, forgot to do it before.
AND you must also enable party hooks for item.onPickupItem, since internally it uses party.onPickupItem

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
   components = {
        fw_addHooks{
            class = "Party"
        }
   },
}
- 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 »

Thank you guys I got it to work (below) The last question is if the player puts the dagger on the ground and picks it up again it huPrints again etc.. How do I stop this thank you? I think it has something to do with return false?

Dagger Object:

Code: Select all

defineObject{
	name = "my_dagger_pickup",
	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",


		},
	},
	tags = { "weapon" },
}
In Script Entity Code:

Code: Select all

fw.script:set('my_dagger_pickup@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 »

There is an example in docs ;) , but here you are.

Code: Select all

fw.script:set('my_dagger_pickup@item.mymod.onPickUpItem',function(hook)
hudPrint("picked up")
fw.script:remove(hook)
end)
This removes the hook after the first call, really useful feature IMO.
- 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 »

JKos wrote:There is an example in docs ;) , but here you are.

Code: Select all

fw.script:set('my_dagger_pickup@item.mymod.onPickUpItem',function(hook)
hudPrint("picked up")
fw.script:remove(hook)
end)
This removes the hook after the first call, really useful feature IMO.
So I use this code to stop hooks when I want awesome thx again:) I happy chappie now lol
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 »

Sorry about this Jkos I used the code you gave me when the dagger hits a monster and I don't see the hudPrint. Am I doing something wrong :oops:

Script Entity in Editor:

Code: Select all

fw.script:set('my_dagger@meleeattack.mymod.onHitMonster', function(hook,item,monster)
hudPrint("Why did you hit me?")
end)
Dagger Object:

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" },
},

fw_addHooks{
class = "MeleeAttack",
attackPower = 7,
accuracy = 5,
cooldown = 2.5,
swipe = "vertical",
attackSound = "swipe_light",
powerAttackTemplate = "throw",
},
},
tags = { "weapon" },
}
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 »

Well I just copy pasted that code to my test dungeon and it worked fine, so I really don't know what's wrong, sorry. Are you sure that you are hitting monsters with my_dagger and not with regular dagger?
- 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
melierax
Posts: 29
Joined: Sat Oct 27, 2012 2:08 am
Location: Quebec, Canada

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

Post by melierax »

Bonjour
Si possible est-ce qu'il y a quelqu'un qui se sert du LoG Framework 2 et pourrait me faire un petit donjon avec un exemple fonctionnel ?
J'ai essayé de l'incorporer dans mon donjon mais cela ne fonctionne pas :( (pourtant j'ai suivi à la lettre toutes les instructions de JKos
Merci :)

Sorry google translation

Hello
If possible is it that there is someone who uses LoG Framework 2 and could make me a dungeon with a working example?
I tried to incorporate it into my dungeon, but it does not work :( (though I followed to the letter all the instructions JKos
Thank you :)
Post Reply