Yes, that should work, but you should be aware that functions aaa and bbb will be copied when the game is saved, so every item will have their own copies of those functions, I think this is what you meant by "function ownership will change from this script component to the fw script". It's an effect of the serialization method of LoG, references can not be serialized instead the referenced object/fuction will be copied.minmay wrote: ...
Well, you cannot overwrite the native addConnector method as far as I know, so you can't use that exact code. You would use something like this:Also if the hook framework works similarly to how it does in LoG1 (I haven't tested) function ownership will change from this script component to the fw script if the game is saved and reloaded, so you need to account for that (only reference the global environment in the function).Code: Select all
function myTestSpawn() local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation) fw.script:set(o.id..'@item.whateverNamespaceYouWant.onEquipItem',aaa) fw.script:set(o.id..'@item.whateverNamespaceYouWant.onUnequipItem',bbb) end function aaa() print("A") end function bbb() print("B") end
If you want to avoid that you should define those hooks like this:
Code: Select all
function myTestSpawn()
local o = spawn("rope", party.level, party.x, party.y, 0, party.elevation)
fw.script:set(o.id..'@item.whateverNamespaceYouWant.onEquipItem',function(hook,item,champion,slot)
your.script.aaa(item,champion,slot)
end)
fw.script:set(o.id..'@item.whateverNamespaceYouWant.onUnequipItem',function(hook,item,champion,slot)
your.script.bbb(item,champion,slot)
end)
end
Code: Select all
modifyObjects{
filter = {
hasComponents = {"item"}
},
components = {
fw_addHooks{
class = 'Item',
}
}
}