WoW:Detecting an instant cast spell: Difference between revisions
Jump to navigation
Jump to search
demoted headings
(demoted headings) |
|||
| Line 1: | Line 1: | ||
= Explanation of SPELLCAST_STOP = | == Explanation of SPELLCAST_STOP == | ||
Unfortunately until more information is exposed to us through events or the API, there isn't currently a very reliable manner to catch instant cast spells being cast by the player, for interaction with the UI. For a spell with a casting time, we get SPELLCAST_START with the spell name and the length of the cast time. When the spell is finished (successfully) casting, we get a SPELLCAST_STOP. In between we could get SPELLCAST_FAILED, SPELLCAST_INTERRUPTED, etc. which help us keep our states straight. | Unfortunately until more information is exposed to us through events or the API, there isn't currently a very reliable manner to catch instant cast spells being cast by the player, for interaction with the UI. For a spell with a casting time, we get SPELLCAST_START with the spell name and the length of the cast time. When the spell is finished (successfully) casting, we get a SPELLCAST_STOP. In between we could get SPELLCAST_FAILED, SPELLCAST_INTERRUPTED, etc. which help us keep our states straight. | ||
| Line 5: | Line 5: | ||
With an instant cast spell, we get one single SPELLCAST_STOP message, with no information (no spell name, no target, nothing). As a result any mod that tries to track something involving these instant cast spells has to guess and play around. I finished writing a Heal Tracking addon that me asures your healing efficiency, and for this purpose-- I needed those instant cast spells. This is the method I used to get them reliably. | With an instant cast spell, we get one single SPELLCAST_STOP message, with no information (no spell name, no target, nothing). As a result any mod that tries to track something involving these instant cast spells has to guess and play around. I finished writing a Heal Tracking addon that me asures your healing efficiency, and for this purpose-- I needed those instant cast spells. This is the method I used to get them reliably. | ||
== Spellcasting functions and timeline == | === Spellcasting functions and timeline === | ||
We have the following functions involved in the casting/targeting process: | We have the following functions involved in the casting/targeting process: | ||
| Line 20: | Line 20: | ||
Keep in mind when looking at this world, there are plenty of combinations that need to be considered when trying to detect instant cast spells. I try to take these into consideration with my hooks. | Keep in mind when looking at this world, there are plenty of combinations that need to be considered when trying to detect instant cast spells. I try to take these into consideration with my hooks. | ||
= Implementing this system = | == Implementing this system == | ||
== Caveats == | === Caveats === | ||
This code will grab every spell that is being cast as well as every action that is being used on the client side. Due to global cooldowns and other timing the overhead we incur here is very small, and I've done everything I can to make the code efficient and to ensure that the original functions are called as quickly as possible. | This code will grab every spell that is being cast as well as every action that is being used on the client side. Due to global cooldowns and other timing the overhead we incur here is very small, and I've done everything I can to make the code efficient and to ensure that the original functions are called as quickly as possible. | ||
| Line 28: | Line 28: | ||
If you are interested in grabbing just a subset of instant cast functions, you can put them in a localized table and use that lookup to determine whether or not you change the MyMod_Spell variable. | If you are interested in grabbing just a subset of instant cast functions, you can put them in a localized table and use that lookup to determine whether or not you change the MyMod_Spell variable. | ||
== Provide a custom tooltip == | === Provide a custom tooltip === | ||
As much as I wish it wasn't necessary, we need some way to glean the spell information. This step is somewhat optional if you have your own tooltip to look this up, but I like my functions to be somewhat complete in providing accurate information. Let's create a tooltip in our XML file so we can use it later. | As much as I wish it wasn't necessary, we need some way to glean the spell information. This step is somewhat optional if you have your own tooltip to look this up, but I like my functions to be somewhat complete in providing accurate information. Let's create a tooltip in our XML file so we can use it later. | ||
| Line 43: | Line 43: | ||
</GameTooltip> | </GameTooltip> | ||
== Variables == | === Variables === | ||
We could use some variables here to store information as we progress, so we'll define the following in the LUA body: | We could use some variables here to store information as we progress, so we'll define the following in the LUA body: | ||
| Line 54: | Line 54: | ||
MyMod_Target = nil | MyMod_Target = nil | ||
== Hooking the casting functions == | === Hooking the casting functions === | ||
=== CastSpell === | ==== CastSpell ==== | ||
MyMod_oldCastSpell = CastSpell; | MyMod_oldCastSpell = CastSpell; | ||
| Line 80: | Line 80: | ||
CastSpell = MyMod_newCastSpell | CastSpell = MyMod_newCastSpell | ||
=== CastSpellByName === | ==== CastSpellByName ==== | ||
Corrected syntax for 1.10 patch. | Corrected syntax for 1.10 patch. | ||
| Line 107: | Line 107: | ||
CastSpellByName = MyMod_newCastSpellByName | CastSpellByName = MyMod_newCastSpellByName | ||
=== UseAction === | ==== UseAction ==== | ||
MyMod_oldUseAction = UseAction | MyMod_oldUseAction = UseAction | ||
function MyMod_newUseAction(a1, a2, a3) | function MyMod_newUseAction(a1, a2, a3) | ||
| Line 130: | Line 130: | ||
UseAction = MyMod_newUseAction | UseAction = MyMod_newUseAction | ||
== Hooking the targeting functions == | === Hooking the targeting functions === | ||
=== SpellTargetUnit === | ==== SpellTargetUnit ==== | ||
This one is nice, and provides us with a good framwork because of its limitations. Since SpellTargetUnit can ONLY be called after a spellcast has been issued, we can always be sure of who we're casting the spell on. Even if ClearTarget is used, it just triggers the need to target after casting. | This one is nice, and provides us with a good framwork because of its limitations. Since SpellTargetUnit can ONLY be called after a spellcast has been issued, we can always be sure of who we're casting the spell on. Even if ClearTarget is used, it just triggers the need to target after casting. | ||
| Line 155: | Line 155: | ||
SpellTargetUnit = MyMod_newSpellTargetUnit | SpellTargetUnit = MyMod_newSpellTargetUnit | ||
=== TargetUnit === | ==== TargetUnit ==== | ||
This is the same code from SpellTargetUnit, with the names changed to protect the innocent. | This is the same code from SpellTargetUnit, with the names changed to protect the innocent. | ||
| Line 178: | Line 178: | ||
TargetUnit = MyMod_newTargetUnit | TargetUnit = MyMod_newTargetUnit | ||
=== SpellStopTargeting === | ==== SpellStopTargeting ==== | ||
All we need to do here is clear MyMod_Spell to ensure we keep our state clean. | All we need to do here is clear MyMod_Spell to ensure we keep our state clean. | ||
| Line 194: | Line 194: | ||
SpellStopTargeting = MyMod_newSpellStopTargeting | SpellStopTargeting = MyMod_newSpellStopTargeting | ||
=== CameraOrSelectOrMoveStart === | ==== CameraOrSelectOrMoveStart ==== | ||
After the 1.10 patch, CameraOrSelectOrMoveStart may no longer be hooked by custom UI mods. The below code is preserved for historical purposes, but will no longer work. | After the 1.10 patch, CameraOrSelectOrMoveStart may no longer be hooked by custom UI mods. The below code is preserved for historical purposes, but will no longer work. | ||
| Line 222: | Line 222: | ||
CameraOrSelectOrMoveStart = MyMod_newCameraOrSelectOrMoveStart | CameraOrSelectOrMoveStart = MyMod_newCameraOrSelectOrMoveStart | ||
== Hooking the mouse click == | === Hooking the mouse click === | ||
In the 1.10 patch, CameraOrSelectOrMoveStart can no longer be hooked by the user interface. Attempting to call the hooked function will cause your addon to be reported as blocked by the game. The solution to this problem is to hook the mouse click itself. Since the user clicks on the screen to target a spell, all we have to do is add a call to our custom script when this occurs. | In the 1.10 patch, CameraOrSelectOrMoveStart can no longer be hooked by the user interface. Attempting to call the hooked function will cause your addon to be reported as blocked by the game. The solution to this problem is to hook the mouse click itself. Since the user clicks on the screen to target a spell, all we have to do is add a call to our custom script when this occurs. | ||
=== OnMouseDown === | ==== OnMouseDown ==== | ||
function myMouseDown() | function myMouseDown() | ||
| Line 250: | Line 250: | ||
end | end | ||
== Watching for SPELLCAST events == | === Watching for SPELLCAST events === | ||
In your OnLoad handler, register the following events: | In your OnLoad handler, register the following events: | ||