WoW:Detecting an instant cast spell: Difference between revisions

Added OnMouseDown event to list, deprecated CameraOrSelectOrMoveStart
(Added OnMouseDown event to list, deprecated CameraOrSelectOrMoveStart)
Line 15: Line 15:
* [[API_TargetUnit]] - Called to change the physical target (in game) to a specific unit
* [[API_TargetUnit]] - Called to change the physical target (in game) to a specific unit
* [[API_SpellStopTargeting]] - Stops the targeting for the current spell awaiting targeting
* [[API_SpellStopTargeting]] - Stops the targeting for the current spell awaiting targeting
* [[API_CameraOrSelectOrMoveStart]] - Called when a spell is waiting targeting, and you click on the 3-D world.
* [[API_CameraOrSelectOrMoveStart]] - Called when a spell is waiting targeting, and you click on the 3-D world. <i>This function is blocked in 1.10.</i>
* OnMouseDown - Hook this event to detect clicks on the 3-D world.  ([[XML_User_Interface#Event_Handler_reference]])


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.
Line 30: Line 31:


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.
After the 1.10 patch, it is necessary to provide an anchor for all tooltips; otherwise they will not be filled in by the UI.  See [[UIOBJECT_GameTooltip]] for additional information.


  <GameTooltip name="MyMod_Tooltip" frameStrata="TOOLTIP" hidden="true"
  <GameTooltip name="MyMod_Tooltip" frameStrata="TOOLTIP" hidden="true"
  inherits="GameTooltipTemplate" parent="UIParent">
  inherits="GameTooltipTemplate" parent="UIParent">
    <Scripts>
        <OnLoad>
            this:SetOwner(UIParent, "ANCHOR_NONE");
        </OnLoad>
    </Scripts>
</GameTooltip>


== Variables ==
== Variables ==
Line 72: Line 81:


=== CastSpellByName ===
=== CastSpellByName ===
Corrected syntax for 1.10 patch.
  MyMod_oldCastSpellByName = CastSpellByName;
  MyMod_oldCastSpellByName = CastSpellByName;
  function MyMod_newCastSpellByName(spellName)
  function MyMod_newCastSpellByName(spellName, onSelf)
     -- Call the original function
     -- Call the original function
     MyMod_oldCastSpellByName(spellName)
     MyMod_oldCastSpellByName(spellName, onSelf)
      
      
     -- This will give us the full spellname, including Rank.   
     -- This will give us the full spellname, including Rank.   
Line 87: Line 98:
         -- Spell is being cast on the current target
         -- Spell is being cast on the current target
         MyMod_EndCast = spellName
         MyMod_EndCast = spellName
         MyMod_Target = UnitName("target")
         if onSelf then
            MyMod_Target = UnitName("player")
        else
            MyMod_Target = UnitName("target")
        end
     end
     end
  end
  end
  CastSpellByName = MyMod_CastSpellByName
  CastSpellByName = MyMod_CastSpellByName
 
=== UseAction ===
=== UseAction ===
  MyMod_oldUseAction = UseAction
  MyMod_oldUseAction = UseAction
Line 180: Line 195:
   
   
=== 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.
----


This one is a little trickier.. we need to grab the information before we call the original function, so lets be quick about it:
This one is a little trickier.. we need to grab the information before we call the original function, so lets be quick about it:
Line 202: Line 221:
  end
  end
  CameraOrSelectOrMoveStart = MyMod_newCameraOrSelectOrMoveStart
  CameraOrSelectOrMoveStart = MyMod_newCameraOrSelectOrMoveStart
== 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.
=== OnMouseDown ===
WorldFrame:SetScript("OnMouseDown", myMouseDown)
function myMouseDown()
    if arg1 == "LeftButton" then
        local targetName = nil
 
        if MyMod_Spell and UnitName("mouseover") then
            targetName = UnitName("mouseover")
        end
        if MyMod_Spell and targetName then
            MyMod_EndCast = MyMod_Spell
            MyMod_Target = targetName
            MyMod_Spell = nil
        end
    end
end


== Watching for SPELLCAST events ==
== Watching for SPELLCAST events ==
Anonymous user