Thread Tools Display Modes
03-26-13, 06:23 AM   #1
itrulia
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Mar 2013
Posts: 2
Get spellid of a macro

Hi people,

I'm working on an addOn that highlights paladin abilities if you have 3 holy power. My problem is I do not know how to get the spellid of a macro.

What do I have:

if unit == "player" and UnitClass(unit) == "Paladin" then
for _, btn in pairs({"ActionButton", "MultiBarLeftButton", "MultiBarRightButton", "MultiBarBottomLeftButton", "MultiBarBottomRightButton"}) do
for i = 1, 12 do
local button = _G[btn..i];

local actionType, id, subType = GetActionInfo(button.action);

for _, spellId in pairs(spells["holyPower"]) do
if actionType == "spell" then
local spellId2 = id;

if (spellId == spellId2) and UnitPower(unit , SPELL_POWER_HOLY_POWER) >= 3 then
ActionButton_ShowOverlayGlow(button)
else
ActionButton_HideOverlayGlow(button)
end
elseif actionType == "macro" then
-- print(id);
end;
end;
end
end
end;
works with spells as intended but not with macros
  Reply With Quote
03-26-13, 07:27 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
nUI uses the function ActionButton_CalculateAction(button) to return the actionID which is then used in the GetSpellInfo function. You might want to see if that helps you. It allows us to see cooldowns and timers on the spells the macros use that way.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-26-13, 01:23 PM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
You can use GetMacroSpell and a lookup table. GetMacroSpell will give you the localized name but you can use a lookup table to find the spell id:
lua Code:
  1. local gsi = GetSpellInfo
  2. local spell2id = {}
  3. spell2id[gsi(85256)] = 85256 -- TV
  4. spell2id[gsi(53385)] = 53385 -- DS
  5. spell2id[gsi(84963)] = 84963 -- Inq
  6. spell2id[gsi(85222)] = 85222 -- LoD
  7. spell2id[gsi(85673)] = 85673 -- WoG
  8. -- did I list them all?
  9.  
  10. -- a reverse table.
  11. local id2spell = {}
  12. for name, id in next, spell2id do
  13.     id2spell[id] = name
  14. end
  15.  
  16. local function isHolyPowerAction(actionId)
  17.     local actionType, id = GetActionInfo(actionId)
  18.     if actionType == 'spell' then
  19.         return id
  20.     elseif actionType == 'macro' then
  21.         local name = GetMacroSpell(id)
  22.         return name and spell2id[name], name
  23.     end
  24. end
  25.  
  26. -- assuming action 1 has a macro with a spell.
  27. local id, name = action2spell(1)
Note: may come with syntax errors because I am tired of work and I cba to check ingame
Put the lookup tables outside of your event code and just use isHolyPowerAction instead of looping through a table.

Last edited by ravagernl : 03-26-13 at 01:36 PM.
  Reply With Quote
03-26-13, 01:26 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
This is basically how I do it in my Crack Cooldown addon.
Lua Code:
  1. if unit == "player" and UnitClass(unit) == "Paladin" then
  2.  local hasPower = UnitPower(unit , SPELL_POWER_HOLY_POWER) >= 3
  3.  for _, btn in pairs({"ActionButton", "MultiBarLeftButton", "MultiBarRightButton", "MultiBarBottomLeftButton", "MultiBarBottomRightButton"}) do
  4.   for i = 1, 12 do
  5.    local button = _G[btn..i]
  6.    local actionType, id, subType, _ = GetActionInfo(button.action)
  7.    if actionType == 'macro' then
  8.     _, _, id = GetMacroSpell(id)
  9.    elseif actionType == "spell" or (actionType == 'macro' and id) then
  10.     for _, spellId in pairs(spells["holyPower"]) do
  11.      --local spellId2 = id
  12.      if spellId == id and hasPower then
  13.       ActionButton_ShowOverlayGlow(button)
  14.      else
  15.       ActionButton_HideOverlayGlow(button)
  16.      end
  17.     end
  18.    end
  19.   end
  20.  end
  21. end
I moved your for loop around so you wouldn't have to keep looking up the spell id for the button for every spell in your list.

However, calling ActionButton_HideOverlayGlow on every button that doesn't match your criteria is going to wipe out every other overlay glow, so you might want to keep track of which ones you set in a table or something.

Unless you're only calling it on buttons that won't have glows apart from yours, in which case it doesn't really matter.

Last edited by semlar : 03-26-13 at 01:52 PM.
  Reply With Quote
03-26-13, 01:39 PM   #5
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by semlar View Post
This is what I use in my Crack Cooldown addon.
Lua Code:
  1. elseif actionType == "macro" then
  2.   local _, _, spellId2 = GetMacroSpell(id)
  3. end
Awesome, wowprogramming/wowpedia/wowwiki all listed two arguments, seems the spell id was added recently then?
  Reply With Quote
03-26-13, 01:51 PM   #6
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It's not recent, I have no idea how long it's returned the spell ID but I started writing that addon probably more than 2 years ago.

It's here on curse if you want to see it, although the code is not great it does what it's supposed to. Mostly.

Last edited by semlar : 03-26-13 at 02:00 PM.
  Reply With Quote
03-26-13, 04:11 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Ah yeah, looks like the 3rd return value came into play around Wow 4.3 . Totally forgot about GetMacroSpell function.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-26-13, 10:01 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I updated the GetMacroSpell API page on Wowpedia.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-02-13, 01:06 AM   #9
itrulia
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Mar 2013
Posts: 2
Originally Posted by Phanx View Post
I updated the GetMacroSpell API page on Wowpedia.
Ty, I figured it out 10 min after I wrote that post (found the function on warcraftprogramming, wowpedia is my first source --> is not listen in the wowapi)

Last edited by itrulia : 04-02-13 at 01:57 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Get spellid of a macro


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