Page 3 of 5

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

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

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

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

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

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

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

Posted: Sun Dec 28, 2014 11:03 pm
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"
        }
   },
}

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

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

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

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

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

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

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

Posted: Sun Dec 28, 2014 11:58 pm
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" },
}

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

Posted: Mon Dec 29, 2014 12:52 am
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?

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

Posted: Tue Dec 30, 2014 12:17 am
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 :)