WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Macro Help (https://www.wowinterface.com/forums/forumdisplay.php?f=140)
-   -   Get spell name from a button name (https://www.wowinterface.com/forums/showthread.php?t=59265)

mooman219 10-16-22 02:07 PM

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.

Dridzt 10-16-22 06:35 PM

Quote:

Originally Posted by mooman219 (Post 341241)
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.

mooman219 10-16-22 07:42 PM

Quote:

Originally Posted by Dridzt (Post 341245)
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


Fizzlemizz 10-16-22 08:29 PM

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)

mooman219 10-16-22 09:09 PM

That's perfect! Thank you! Everything works as expected after deferring it PLAYER_ENTERING_WORLD.


All times are GMT -6. The time now is 04:01 AM.

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