WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Cancel a spell cast (https://www.wowinterface.com/forums/showthread.php?t=59516)

Walkerbo 02-23-23 06:52 PM

Cancel a spell cast
 
Hi all

I have a list of spells, (hearthstones), that I want to cancel during it's cast.
This is a secure action so I have set up the button as a SecureActionButtonTemplate.
Lua Code:
  1. if event == "UNIT_SPELLCAST_SENT" then
  2.     unit, _, _, spellID = ...
  3.     if unit == "player" then
  4.         for k, v in pairs(hearthtonesList) do
  5.             if spellID == v then
  6.                 print("found") -- debug --
  7.                 b.hiddenSpellStopButton:Click()
  8.             end
  9.         end
  10.     end
  11. end
  12.  
  13. b.hiddenSpellStopButton = CreateFrame("Button", nil, nil, "SecureActionButtonTemplate")
  14. b.hiddenSpellStopButton:RegisterForClicks("AnyDown")
  15. b.hiddenSpellStopButton:SetAttribute("type", "macro")
  16. b.hiddenSpellStopButton:SetAttribute("macrotext", "/stopcasting")
  17. b.hiddenSpellStopButton:SetScript(
  18.     "OnClick",
  19.     function()
  20.         print("here i am") -- debug --
  21.     end
  22. )
  23. b:RegisterEvent("UNIT_SPELLCAST_SENT")
I get both of the prints, so I can confirm that the button does click yet the spell does not stop the cast.

I have been banging away for the last few days trying to get this working.

Is there a way to stop a cast?

SDPhantom 02-24-23 12:49 AM

You're replacing SecureActionButtonTemplate's OnClick handler, which makes it no longer work.
Also calling :Click() taints the execution and throws a protected call error.

Walkerbo 02-24-23 05:38 PM

Hi SDPhantom

Ok, so the hidden button onclick overrides the SecureActionButtonTemplate, that makes sense.

I have removed the onclick from the hidden button, (I only added the onclick to test if the button was indeed being clicked).

Now with the b.hiddenSpellStopButton:Click() I do not understand what you mean.

I have tested the code and it throws no errors at all.

If I should not use b.hiddenSpellStopButton:Click() how do I click the button to stop the cast?

Dridzt 02-25-23 02:52 AM

Quote:

Originally Posted by Walkerbo (Post 342201)
Hi SDPhantom

Ok, so the hidden button onclick overrides the SecureActionButtonTemplate, that makes sense.

I have removed the onclick from the hidden button, (I only added the onclick to test if the button was indeed being clicked).

Now with the b.hiddenSpellStopButton:Click() I do not understand what you mean.

I have tested the code and it throws no errors at all.

If I should not use b.hiddenSpellStopButton:Click() how do I click the button to stop the cast?

The whole point of the secure system is to prevent automation.
If you could click secure buttons from code in response to events then what's the point.

"how do I click the button to stop the cast?" You click it with your mouse or press a keybind.

SDPhantom 02-25-23 04:35 PM

Quote:

Originally Posted by Walkerbo (Post 342201)
Now with the b.hiddenSpellStopButton:Click() I do not understand what you mean.

:Click() calls the OnClick handler for the button. Being a SecureActionButton, the stock handler would read the button's attributes to perform a protected action. Normally, this is to respond to a user click, which can be simulated also with a click-style keybind. Direct interaction from the user means the OnClick handler runs from a secure state and it runs as normal. However, when called from an addon using any means carries the addon's insecure status and any protected action that the button would take would be blocked.

The specific function that would throw the protected action error in this case would be RunMacroText() called from FrameXML\SecureTemplates.lua:468.

Disregarding that, /stopcasting calls SpellStopCasting(), which is also a protected function.



Quote:

Originally Posted by Walkerbo (Post 342201)
If I should not use b.hiddenSpellStopButton:Click() how do I click the button to stop the cast?

As Dridzt explained, you can't without the user directly interacting with the button. It's an intentional limitation to prevent addons from automating gameplay (aka botting).

Walkerbo 02-26-23 03:23 PM

Hi SDPhantom and Dridzt

Yes, it does make sense that the virtual click does not work against a hardware click, I should have seen that for myself.

@SDPhantom thanks for the detailed explanation, it really does help.

Cheers all


All times are GMT -6. The time now is 12:07 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI