Thread Tools Display Modes
10-14-10, 06:14 AM   #1
BDelacroix
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 33
Secure button spell casting (setattribute)

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.
  Reply With Quote
10-14-10, 03:29 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You should be able to use a spell ID instead of a spell name so the following should work:
Code:
button:SetAttribute('type', 'spell')
button:SetAttribute('spell', 12345)

Since all spells are in the spell book now is checking for a spell in there really going to be that useful? I would think just checking the player's class once would be easier unless you are meaning to check if the spell has been learned which would be a slightly different check. In any case, the following will turn a spell ID into a spell slot:
Code:
local slot = FindSpellBookSlotBySpellID(spellID)

The following should tell you if a spellID is known:
Code:
local function IsSpellKnown(spellID)
	local slot = FindSpellBookSlotBySpellID(spellID)
	if slot and slot <= MAX_SPELLS then
		local slotType, id = GetSpellBookItemInfo(slot, BOOKTYPE_SPELL)
		return id == spellID and slotType ~= 'FUTURESPELL'
	end
end
  Reply With Quote
10-16-10, 12:49 AM   #3
BDelacroix
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 33
Thank you very much.

That was helpful to optimize a few things in this addon and another. Also, good news on being able to cast by spellID.

While I still have the huge texture problem, this particular problem is solved.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Secure button spell casting (setattribute)


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