Thread Tools Display Modes
10-16-22, 02:07 PM   #1
mooman219
A Defias Bandit
 
mooman219's Avatar
Join Date: Oct 2022
Posts: 3
Get spell name from a button name

Hello,

I'm looking to setup a script at load time to do the following:
Code:
local button = _G["BT4Button73"]
local action = GetAction(button)
if (action == "spell or item") then
  print("/use [@mouseover]%s", spell/item name)
end
I'm still reading into lua syntax, and trying to catch up on wowpedia.fandom.com/wiki/ for the API docs.

Last edited by mooman219 : 10-16-22 at 03:12 PM.
  Reply With Quote
10-16-22, 06:35 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
Originally Posted by mooman219 View Post
Hello,

I'm looking to setup a script at load time to do the following:
Code:
local button = _G["BT4Button73"]
local action = GetAction(button)
if (action == "spell or item") then
  print("/use [@mouseover]%s", spell/item name)
end
I'm still reading into lua syntax, and trying to catch up on wowpedia.fandom.com/wiki/ for the API docs.
There's a couple issues with your code but before I get into those I'm going to jump to the end and say that even if you properly got what's on that Bartender4 button you can't call protected actions like that.

Can't simply run a /use or /cast as a script from addons.
  Reply With Quote
10-16-22, 07:42 PM   #3
mooman219
A Defias Bandit
 
mooman219's Avatar
Join Date: Oct 2022
Posts: 3
Originally Posted by Dridzt View Post
There's a couple issues with your code but before I get into those I'm going to jump to the end and say that even if you properly got what's on that Bartender4 button you can't call protected actions like that.

Can't simply run a /use or /cast as a script from addons.
Seems reasonable, I can setup a secure action for this later. I'm having more trouble just getting the information I need first unfortunately. I played with the following snippit in WowLua, and it actually works as intended: I get the spell name from the Bartender4 button. From addon:Initialization though the button appears to be nil, even after marking Bartender4 as a dependency



Code:
function ParseSpellName(spellId)
   local spellName, spellSubName, _ = GetSpellInfo(spellId);
   if spellSubName then
      return string.format("%s(%s)", spellName, spellSubName)
   else
      return spellName
   end
end


local button = _G["BT4Button73"]
local slot = button:GetAttribute('action');
local actionType, actionId, _ = GetActionInfo(slot);
if (actionType == 'spell') then
   local command = string.format("/use [@mouseover]%s", ParseSpellName(actionId))
   print(command);
end
  Reply With Quote
10-16-22, 08:29 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
You're addon is probably running the code before Bartender has initialised the bars. This usually happens at a specific event that fires during the game loading sequence.

It's also why it works when you're already in the game tesing in WowLua.

Try something like:

Lua Code:
  1. function ParseSpellName(spellId)
  2.    local spellName, spellSubName, _ = GetSpellInfo(spellId);
  3.    if spellSubName then
  4.       return string.format("%s(%s)", spellName, spellSubName)
  5.    else
  6.       return spellName
  7.    end
  8. end
  9.  
  10.  
  11. local f = CreateFrame("Frame")
  12. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  13. f:SetScript("OnEvent", function(self, event, ...)
  14.     self:UnregisterAllEvents() -- PLAYER_ENTERING_WORLD will fire every time you see a loading screen so, stop that happening
  15.     local button = BT4Button73
  16.     local slot = button:GetAttribute('action');
  17.     local actionType, actionId, _ = GetActionInfo(slot);
  18.     if (actionType == 'spell') then
  19.        local command = string.format("/use [@mouseover]%s", ParseSpellName(actionId))
  20.        print(command);
  21.     end
  22. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
10-16-22, 09:09 PM   #5
mooman219
A Defias Bandit
 
mooman219's Avatar
Join Date: Oct 2022
Posts: 3
That's perfect! Thank you! Everything works as expected after deferring it PLAYER_ENTERING_WORLD.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » Macro Help » Get spell name from a button name

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