As indicated in another thread, I have two issues currently with an addon that until 4.0 has worked just fine. Some fundamental things have changed and we all know documentation on these changes is spotty at best, often non existant the rest of the time.
This second issue is how a spell's existence in the player's spellbook is handled. I will include two pieces of code this time because the problem is related to both. The first piece of code is the button creation. Ignoring for the moment that the normaltexture size is all wrong (that is covered in a previous thread). This time, the focus is on the setattribute functions.
In order to tell a button to cast a spell, I set its type attribute to spell and set its spell attribute to the name of the spell I wish to cast.
This now causes a problem. Apparently there are hidden spells in a player's spellbook. These hidden spells possess the same name as others that aren't hidden.
The logic is as follows:
I use spellIDs to check for the existance of a spell in the player's spellbook. If it exists, I make a button for it. I have to cast the spell using its name (or so I believe) but this is where the problem now seems to come in. The traps for throwing and dropping are apparently different spells. Only one version of which appears in the spellbook. However, when told to cast by spellname as I apparently have to do with the spell attribute, the game will find the first instance of it even in the "hidden" spell list and will fail. In my case, all of the first instances of the spell with the trap names are the throw versions which won't work unless you have the throw trap buff on at the time. This can be useful but I need access to the drop versions.
So, is there a way to tell the spell attribute WHICH version of a spell I want? There are no longer ranks and the names are the same. The only differences I can see are the spellIDs but I can't tell the spell attribute to cast by spellID (apparently). It would seem I am hosed. The tooltip works correctly (showing the version of the spell I really mean). It is the casting part that borks.
Code:
trap_b[t] = CreateFrame("Button","trapper_button"..t,trapper,"ActionButtonTemplate, SecureActionButtonTemplate")
trap_b[t].cooldown = CreateFrame("Cooldown","trapper_button"..t.."Cooldown",trap_b[t],"CooldownFrameTemplate")
-- Set type and spell for each state
trap_b[t]:SetAttribute("type","spell")
trap_b[t]:SetAttribute("spell",trap_n[t])
-- Set the image for the button
trap_b[t]:SetNormalTexture(trap_i[t])
trap_b[t]:SetPushedTexture(trap_i[t])
trap_b[t]:SetPoint("CENTER",trapper,offx[t],offy[t])
trap_b[t]:RegisterEvent("SPELL_UPDATE_COOLDOWN")
trap_b[t]:SetScript("OnEvent",trapper_buttonevent)
trap_b[t]:SetScript("OnEnter",trapper_tooltipon)
trap_b[t]:SetScript("OnLeave",trapper_tooltipoff)
trap_b[t].tipID=trap_sid[t]
trap_b[t]:Show()
Here is a second segment of code for finding out if a spell exists in a player's spellbook. I had to change up how I used to do it given that GetSpellInfo was no longer working well.
Code:
function trapper:isspellinbook(id)
local i
local s
for s = 1,MAX_SPELLS do
_,i=GetSpellBookItemInfo(s,BOOKTYPE_SPELL)
if i==id then
return true
end
end
return false
end
This seems somewhat inefficient to me as GetSpellInfo(name) used to return only if said name was in the player's book. GetSpellInfo(id) would return info if the spell was in the book or not.
Any insights are appreciated.