Thread Tools Display Modes
02-23-23, 06:52 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
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?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
02-24-23, 12:49 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-24-23, 05:38 PM   #3
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
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?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
02-25-23, 02:52 AM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by Walkerbo View Post
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.
  Reply With Quote
02-25-23, 04:35 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Walkerbo View Post
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.



Originally Posted by Walkerbo View Post
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).
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-26-23, 03:23 PM   #6
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
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
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Cancel a spell cast

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off