I did some researches but I still don't get when or how I call ZO_preHook...
Here is the prototype : function ZO_PreHook(objectTable, existingFunctionName, hookFunction)
I guess objectTable is the name of my Add-on,
existingFunctionName is the function to be called when hookFunction,
and hookFunction is the triggering event.
Could you provide a more complete exemple please ?
Also, are you sure there is an "end" after the "return false" ? When I run this, I have "expected near 'end' " error ; which I have not when I delete the "end".
Code:
myAddon = {}
myAddon.name = "myAddon"
function myAddon.Initialize()
myAddon.weaponSheathed = ArePlayerWeaponsSheathed()
--preHook the original function
--function ZO_PreHook(objectTable, existingFunctionName, hookFunction)
ZO_PreHook(myAddon.name, myAddon.TogglePlayerWield, ArePlayerWeaponsSheathed)
d("TogglePlayerWield was used")
return false -- return false to run original function code of TogglePlayerWield afterwards!
end
end
function myAddon.TogglePlayerWield()
myAddon.weaponSheathed = not myAddon.weaponSheathed -- toogle
if myAddon.weaponSheathed then
d("Weapons are Sheathed.")
else
d("Weapons are Drawn.")
end
end
-- event handler function which will be called when the "addon loaded" event occurs. Initialize our addon after all of its resources are fully loaded.
function myAddon.OnAddOnLoaded(event, addonName)
-- initialize only when OUR addon is loaded
if addonName == myAddon.name then
myAddon:Initialize()
end
end
-- register our event handler function to be called when the proper event occurs.
EVENT_MANAGER:RegisterForEvent(myAddon.name, EVENT_ADD_ON_LOADED, myAddon.OnAddOnLoaded)