Thread Tools Display Modes
12-06-13, 05:05 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Pet Spells

Since i don't play classes with pets, i could use some help here. I would like a function which iterates through the current pet's spells. I'm also not sure is there any pets spells with the new "flyout" button system, but if there is then also incude thoose too.
  Reply With Quote
12-06-13, 08:27 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Iterating over pet spells is pretty much the same as iterating over player spells, except your pass BOOKTYPE_PET instead of BOOKTYPE_SPELL where required. Your post is pretty light on the specifics of what exactly you want to do, but here is a bare-bones example:

Code:
for i = 1, 100 do
     local skillType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
     if not skillType then break end
     print(i, GetSpellLink(i, BOOKTYPE_PET))
end
__________________
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
12-06-13, 11:15 AM   #3
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
The flyoutbutton pet spells are listed here:

http://www.wowhead.com/search?q=call+pet
  Reply With Quote
12-06-13, 01:55 PM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Iterating over pet spells is pretty much the same as iterating over player spells, except your pass BOOKTYPE_PET instead of BOOKTYPE_SPELL where required. Your post is pretty light on the specifics of what exactly you want to do, but here is a bare-bones example:

Code:
for i = 1, 100 do
     local skillType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
     if not skillType then break end
     print(i, GetSpellLink(i, BOOKTYPE_PET))
end
I want to track cooldown of the pet spells.

I have a function which iterates through player spells like this, i could modify this to pet booktype, but i think it's kinda an overkill if there is no flyout type spells and spell book tabs like in the player's spells, so i'm looking for a more lightweigth solution:

Lua Code:
  1. local playerSpells
  2. do
  3.     local iterateFlyout, iterateSlots, iterateTabs
  4.     iterateFlyout = function(state)
  5.         while state.flyoutSlotIdx <= state.numFlyoutSlots do
  6.             local spellId, _, spellKnown, spellName = GetFlyoutSlotInfo(state.flyoutId, state.flyoutSlotIdx)
  7.             state.flyoutSlotIdx = state.flyoutSlotIdx + 1
  8.             if spellKnown then
  9.                 return spellId, spellName
  10.             end
  11.         end
  12.         state.slotIdx = state.slotIdx + 1
  13.         state.currentIterator = iterateSlots
  14.         return state:currentIterator()
  15.     end
  16.     iterateSlots = function(state)
  17.         while state.slotIdx <= state.numSlots do
  18.             local spellBookItem = state.slotOffset + state.slotIdx
  19.             local spellName, spellSubtext = GetSpellBookItemName(spellBookItem, BOOKTYPE_SPELL)
  20.             local spellType, spellId = GetSpellBookItemInfo(spellBookItem, BOOKTYPE_SPELL)
  21.             if spellType == "SPELL" and not IsPassiveSpell(spellId) then
  22.                 state.slotIdx = state.slotIdx + 1
  23.                 return spellId, spellName, spellSubtext
  24.             elseif spellType == "FLYOUT" then
  25.                 local _, _, numFlyoutSlots, flyoutKnown = GetFlyoutInfo(spellId)
  26.                 if flyoutKnown then
  27.                     state.flyoutId = spellId
  28.                     state.flyoutSlotIdx = 1
  29.                     state.numFlyoutSlots = numFlyoutSlots
  30.                     state.currentIterator = iterateFlyout
  31.                     return state:currentIterator()
  32.                 end
  33.             end
  34.             state.slotIdx = state.slotIdx + 1
  35.         end
  36.         state.tabIdx = state.tabIdx + 1
  37.         state.currentIterator = iterateTabs
  38.         return state:currentIterator()
  39.     end
  40.     iterateTabs = function(state)
  41.         while state.tabIdx <= state.numOfTabs do
  42.             local _, _, slotOffset, numSlots, _, offSpecID = GetSpellTabInfo(state.tabIdx)
  43.             if offSpecID ~= 0 then
  44.                 state.tabIdx = state.tabIdx + 1
  45.             else
  46.                 state.slotOffset = slotOffset
  47.                 state.numSlots = numSlots
  48.                 state.slotIdx = 1
  49.                 state.currentIterator = iterateSlots
  50.                 return state:currentIterator()
  51.             end
  52.         end
  53.         return nil
  54.     end
  55.     local function dispatch(state)
  56.         return state:currentIterator()
  57.     end
  58.     playerSpells = function()
  59.         local state = { }
  60.         state.tabIdx = 1
  61.         state.numOfTabs = GetNumSpellTabs()
  62.         state.currentIterator = iterateTabs
  63.         return dispatch, state
  64.     end
  65. end
  Reply With Quote
12-06-13, 09:33 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
local state = {}

local f = CreateFrame("Frame")
f:RegisterEvent("SPELL_UPDATE_COOLDOWN")
f:SetScript("OnEvent", function()
	for i = 1, 100 do
		local skillType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
		if not skillType then break end
		if (skillType == "SPELL" or skillType == "PETACTION") and not IsPassiveSpell(spellID) then
			local newstate = "READY"
			local start, duration, enabled = GetSpellCooldown(i, BOOKTYPE_PET)
			if enabled == 0 then
				newstate = "ACTIVE"
			elseif start > 0 and duration > 0 then
				newstate = start + duration
			end
			if state[spellID] ~= newstate then
				state[spellID] = newstate
				print(GetSpellLink(i, BOOKTYPE_PET), "is", type(newstate) == "number" and format("on cooldown for %.1f seconds", newstate - GetTime()) or newstate)
			end
		end
	end
end)
__________________
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
12-09-13, 11:40 AM   #6
jlam
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 29
This is how I scan a spellbook in Ovale and deal with flyout spells.
Lua Code:
  1. local function ParseHyperlink(hyperlink)
  2.         return select(3, strfind(hyperlink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+)|?h?%[?([^%[%]]*)%]?|?h?|?r?"))
  3. end
  4.  
  5. -- Scan a spellbook and populate self_spell table.
  6. local function ScanSpellBook(bookType, numSpells, offset)
  7.         offset = offset or 0
  8.         for index = offset + 1, offset + numSpells do
  9.                 local skillType, spellId = API_GetSpellBookItemInfo(index, bookType)
  10.                 if skillType == "SPELL" or skillType == "PETACTION" then
  11.                         -- Use GetSpellLink() in case this spellbook item was replaced by another spell,
  12.                         -- i.e., through talents or Symbiosis.
  13.                         local spellLink = API_GetSpellLink(index, bookType)
  14.                         if spellLink then
  15.                                 local linkdata, spellName = select(3, ParseHyperlink(spellLink))
  16.                                 self_spell[tonumber(linkdata)] = spellName
  17.                                 if spellId then
  18.                                         self_spell[spellId] = spellName
  19.                                 end
  20.                         end
  21.                 elseif skillType == "FLYOUT" then
  22.                         local flyoutId = spellId
  23.                         local _, _, numSlots, isKnown = API_GetFlyoutInfo(flyoutId)
  24.                         if numSlots > 0 and isKnown then
  25.                                 for flyoutIndex = 1, numSlots do
  26.                                         local id, overrideId, isKnown, spellName = GetFlyoutSlotInfo(flyoutId, flyoutIndex)
  27.                                         if isKnown then
  28.                                                 self_spell[id] = spellName
  29.                                                 self_spell[overrideId] = spellName
  30.                                         end
  31.                                 end
  32.                         end
  33.                 -- elseif skillType == "FUTURESPELL" then
  34.                 --        no-op
  35.                 elseif not skillType then
  36.                         break
  37.                 end
  38.         end
  39. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Pet Spells


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