Originally Posted by Phanx
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:
local playerSpells
do
local iterateFlyout, iterateSlots, iterateTabs
iterateFlyout = function(state)
while state.flyoutSlotIdx <= state.numFlyoutSlots do
local spellId, _, spellKnown, spellName = GetFlyoutSlotInfo(state.flyoutId, state.flyoutSlotIdx)
state.flyoutSlotIdx = state.flyoutSlotIdx + 1
if spellKnown then
return spellId, spellName
end
end
state.slotIdx = state.slotIdx + 1
state.currentIterator = iterateSlots
return state:currentIterator()
end
iterateSlots = function(state)
while state.slotIdx <= state.numSlots do
local spellBookItem = state.slotOffset + state.slotIdx
local spellName, spellSubtext = GetSpellBookItemName(spellBookItem, BOOKTYPE_SPELL)
local spellType, spellId = GetSpellBookItemInfo(spellBookItem, BOOKTYPE_SPELL)
if spellType == "SPELL" and not IsPassiveSpell(spellId) then
state.slotIdx = state.slotIdx + 1
return spellId, spellName, spellSubtext
elseif spellType == "FLYOUT" then
local _, _, numFlyoutSlots, flyoutKnown = GetFlyoutInfo(spellId)
if flyoutKnown then
state.flyoutId = spellId
state.flyoutSlotIdx = 1
state.numFlyoutSlots = numFlyoutSlots
state.currentIterator = iterateFlyout
return state:currentIterator()
end
end
state.slotIdx = state.slotIdx + 1
end
state.tabIdx = state.tabIdx + 1
state.currentIterator = iterateTabs
return state:currentIterator()
end
iterateTabs = function(state)
while state.tabIdx <= state.numOfTabs do
local _, _, slotOffset, numSlots, _, offSpecID = GetSpellTabInfo(state.tabIdx)
if offSpecID ~= 0 then
state.tabIdx = state.tabIdx + 1
else
state.slotOffset = slotOffset
state.numSlots = numSlots
state.slotIdx = 1
state.currentIterator = iterateSlots
return state:currentIterator()
end
end
return nil
end
local function dispatch(state)
return state:currentIterator()
end
playerSpells = function()
local state = { }
state.tabIdx = 1
state.numOfTabs = GetNumSpellTabs()
state.currentIterator = iterateTabs
return dispatch, state
end
end