Event for weapon drawn/sheathed ?
Hello everyone,
Today, as a trial, I wanted to display a message in the chat when I sheath or draw weapons. Sadly I can't find a satisfying EVENT (I searched the EVENT_PLAYER_DRAW_WEAPONS, but I guess it would be too simple ^^). What should I search for ? I guess the solution might be on animation or something like that, but would love some help. :D |
Check the code of existing addons with same behavior, or reactions on weapon sheath e.g.
If I remember correctly it is a function you need to react to (prehook e.g.). I doubt there is an event for it. http://www.esoui.com/downloads/info9...athWeapon.html |
Thanks a lot :)
As it seems there is no event for it, I used the RegisterForUpdate() function instead of RegisterForEvent(). Gonna test it. |
If you want to put a message into the chat as the weapon sheaths you can do it like this:
Lua Code:
You can use the function IsUnitInCombat("player") to check if you ar ein combat and change the message shown in the chat accordingly. In combat: Weapon drawn, Out of combat: weapon sheath -> Maybe out of combat will be always false within a preHook to TogglePlayerWield as you run your code before the weapon gets sheathed and you might be in combat at this time too. For the weapon draw stuff you could register an event for "getting into combat" I guess: EVENT_PLAYER_COMBAT_STATE |
Why would I want to use preHook instead of a regular d() ?
Here is my code atm : Code:
myAddon = {} I don't want to use the function "isUnitInCombat" because the chat message will not occur when I draw/sheath weapons. |
If you use EVENT_MANAGER:RegisterForUpdate it will just call your function every x milliseconds,
This is not needed and will be ressource hungry as every second your funciton checks and writes a message. EVENT_MANAGER:RegisterForUpdate is not handled via any event or "clause". It's just run! My code above will "only be run" if the weapon sheath/draw toggle function is executed, and as a prehook it will be executed before the original function will be executed. |
You should not really use RegisterForUpdate unless it is absolutely necessary. Using PreHook is going to be simpler, and your code will only be run when the weapon is sheathed or unsheathed.
Using PreHook essentially makes it a 'custom' event. Plus, you'll get instant feedback rather than having it delayed by up to a second. |
I see :)
Thanks a lot, I found my method very inefficient too. Will modify my code later and see if I can make it works. |
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 = {} |
Actually, object table is the table where the function is. In this case, that is _G.Existingfunctionname is the name of the function you want to replace, as a string. So "ToggleWeaponsSheathed"
And the last parameter is your hook function, i.e. the function you want to run before ToggleWeaponsSheathed |
As shown above the code should look like this:
Lua Code:
ZO_PreHook(objectTable, existingFunctionName, hookFunction) objectTable: The name of an object (e.g. SMITHING) or if it is the global namespace (_G) you can just pass the function name existingFunctionName without the objectTable. existingFunctionName: The name of the function you'd like to preHook, in string quotes " " hookFunction: Your definded hook function or an anonymouse function within the prehook like shown above in my example code. So your code should look like this e.g. Lua Code:
This is the same: Lua Code:
|
One problem is that TogglePlayerWield() isn't run if the user clicks the game field to draw their weapons, which I do a lot. More specifically, I do a brief block to predraw my weapons before an assassination. The player doesn't automatically draw their weapons when they enter combat either. It's always done by user action. I know these are edge cases, but it still makes these tracking methods unreliable.
|
True. That's why I have mentiond the EVENT_PLAYER_COMBAT_STATE above.
If you get into combat you'll normaly draw your weapons. And if not you can be pretty sure that you will do so soon :p Or check it with ArePlayerWeaponsSheathed() in the event callback function. |
So if I do :
Lua Code:
I changed my code, but it's still not working as intended. Do you know some add-on which use this ? I searched in my add-ons but found none with this function (even the "SheathWeapon" add-on use RegisterForUpdate() ! ) Thanks a lot for all the help you give me, :) |
Quote:
ZO_PreHook("TogglePlayerWield", myAddon.ToggleWeaponsSheathed()) |
Yes but as SDPhantom said, "TogglePlayerWield() isn't run if the user clicks the game field to draw their weapons":o. So a second case must be checked : when the player draw his weapons with the Keybind or when he presses a spell.
|
I'm gonna stick with the code below for know, and work on graphics outputs.
I am still interested on some full code exemples of ZO_Prehook from the pros. ;) It's just that I don't want to be stuck for too long on this part. Best regards Lua Code:
|
See ZoPreeHook example from my first post about it above :-)
Just do /script ArePlayerWeaponsSheathed() in the chat and your preehook should run too. |
Quote:
|
All times are GMT -6. The time now is 02:53 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI