Thread Tools Display Modes
11-13-13, 06:13 PM   #1
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Issue with UnitBuff

Right so, this is a tiny addon i've had for a while to auto answer ready checks depnding on the situation.

Everything works exept the flask part, flask is always nil and i don't understand what i did wrong.

Code:
local _, caelUI = ...

caelUI.readycheck = caelUI.createModule("ReadyCheck")

local GetSpellName = function(spellId)
	return GetSpellInfo(spellId)
end

local flasks = {
	-- Cataclysm
	GetSpellName(80719),		-- Flask of Steelskin
	GetSpellName(80720),		-- Flask of the Draconic Mind
	GetSpellName(80721),		-- Flask of the Winds
	GetSpellName(80723),		-- Flask of Titanic Strength
	GetSpellName(94162),		-- Flask of Flowing Water

	-- Pandaria
	GetSpellName(105694),	-- Flask of the Earth
	GetSpellName(105691),	-- Flask of the Warm Sun
	GetSpellName(105696),	-- Flask of Winter's Bite
	GetSpellName(105693),	-- Flask of Falling Leaves
	GetSpellInfo(105689),	-- Flask of Spring Blossoms
}

ReadyCheckListenerFrame:SetScript("OnShow", nil)

local isGuildGroup

caelUI.readycheck:SetScript("OnEvent", function(self, event)
	if event == "PLAYER_ENTERING_WORLD" then
		hooksecurefunc(GuildInstanceDifficulty, "Show", function()
			isGuildGroup = true
		end)

		hooksecurefunc(GuildInstanceDifficulty, "Hide", function()
			isGuildGroup = false
		end)
	elseif event == "READY_CHECK" then
		PlaySoundFile([[Sound\Interface\ReadyCheck.wav]], "Master")

		local food = UnitBuff("player", GetSpellName(104280))

		for k, v in pairs(flasks) do
			local flask =  UnitBuff("player", k)
		end

		if (not isGuildGroup and food) or (isGuildGroup and flask and food) then
			ReadyCheckFrame:Hide()
			ConfirmReadyCheck(1)
		end
	end
end)

for _, event in next, {
	"PLAYER_ENTERING_WORLD",
	"READY_CHECK",
} do
	caelUI.readycheck:RegisterEvent(event)
end
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
11-13-13, 06:21 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
GetSpellInfo returns multiple stuff, i guess you need the name of the spell.

name = GetSpellInfo(spellId or spellName or spellLink)

http://www.wowwiki.com/API_GetSpellInfo

Also i'm not sure GetSpellName is a valid API atm, and it's only for spellbook items so its useless for you. I think you need to use GetSpellInfo for food too.

Last edited by Resike : 11-13-13 at 06:27 PM.
  Reply With Quote
11-13-13, 06:32 PM   #3
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by Resike View Post
GetSpellInfo returns multiple stuff, i guess you need the name of the spell.

name = GetSpellInfo(spellId or spellName or spellLink)

http://www.wowwiki.com/API_GetSpellInfo

Also i'm not sure GetSpellName is a valid API atm, and it's only for spellbook items so its useless for you. I think you need to use GetSpellInfo for food too.
Hmm ? GetSpellName is a function i create, and GetSpellInfo without parameters returns the name.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
11-13-13, 07:16 PM   #4
Nimhfree
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 267
Instead of worrying about the spell names, since you already have the spell IDs for the ones in which you have interest, why don't you just use UnitAura in a loop like:

flasks = {} -- fill this with each one
local i = 1
local foundFLask = nil
while (true) do
local name,_,_,_,_,_,_,_,_,_,spellId = UnitAura("player", i)
if name then
spellId = tonumber(spellId)
if tContains(flasks, spellId) then foundFlask = spellId end -- or use name if you want
i = i + 1
else
break
end
end
  Reply With Quote
11-13-13, 11:28 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You have a scoping problem.

Code:
for k, v in pairs(flasks) do
	local flask =  UnitBuff("player", k)
	-- "flask" is local to this scope.
end

-- "flask" does not exist in this scope.
if (not isGuildGroup and food) or (isGuildGroup and flask and food) then
	ReadyCheckFrame:Hide()
	ConfirmReadyCheck(1)
end
Also, you may want to change your GetSpellName function to return an empty string, or UNKNOWN, or some other "dummy" value for spell IDs that don't return a real name. Otherwise, if Blizzard changes a spell ID, you will end up with holes in your otherwise sequentially-indexed table.

Also also, since you are using an indexed table, you should use for i = 1, #flasks do local k = flasks[ i ] instead of for k, v in pairs(flasks) to avoid the slow call to pairs.
__________________
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.

Last edited by Phanx : 11-13-13 at 11:32 PM.
  Reply With Quote
11-13-13, 11:30 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Nimhfree View Post
if tContains(flasks, spellId) then ...
Never, ever, ever, ever, never use tContains. It's a complete waste of a function call. If you're going to need to check "is this value in this table?" you should just set up your table correctly in the first place, so you can do a simple table lookup instead:

Code:
if flasks[spellId] then ...
Also, in this case the number of important buffs (flask buffs) is smaller than the number of buffs that will likely be on a player at any given time, and it's simply more efficient to iterate over the smaller list, so what Caellian is doing is fine.
__________________
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.

Last edited by Phanx : 11-13-13 at 11:34 PM.
  Reply With Quote
11-14-13, 02:29 AM   #7
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Not sure i understand what you meant with the function GetSpellName but here's what i did, if that's correct.

Code:
local _, caelUI = ...

caelUI.readycheck = caelUI.createModule("ReadyCheck")

local GetSpellName = function(id)
	return GetSpellInfo(id)
end

local flasks = {
	-- Cataclysm
	GetSpellName(80719),		-- Flask of Steelskin
	GetSpellName(80720),		-- Flask of the Draconic Mind
	GetSpellName(80721),		-- Flask of the Winds
	GetSpellName(80723),		-- Flask of Titanic Strength
	GetSpellName(94162),		-- Flask of Flowing Water

	-- Pandaria
	GetSpellName(105694),	-- Flask of the Earth
	GetSpellName(105691),	-- Flask of the Warm Sun
	GetSpellName(105696),	-- Flask of Winter's Bite
	GetSpellName(105693),	-- Flask of Falling Leaves
	GetSpellName(105689),	-- Flask of Spring Blossoms

	GetSpellName(127230),	-- For testing purpose: Vision of Insanity
}

ReadyCheckListenerFrame:SetScript("OnShow", nil)

local isGuildGroup

caelUI.readycheck:SetScript("OnEvent", function(self, event)
	if event == "PLAYER_ENTERING_WORLD" then
		hooksecurefunc(GuildInstanceDifficulty, "Show", function()
			isGuildGroup = true
		end)

		hooksecurefunc(GuildInstanceDifficulty, "Hide", function()
			isGuildGroup = false
		end)
	elseif event == "READY_CHECK" then
		PlaySoundFile([[Sound\Interface\ReadyCheck.wav]], "Master")

		local food = UnitBuff("player", GetSpellName(104280))

		local flask

		for i = 1, #flasks do
			flask = UnitBuff("player", flasks[i])
		end

		if (not isGuildGroup and food) or (isGuildGroup and flask and food) then
			ReadyCheckFrame:Hide()
			ConfirmReadyCheck(1)
		end
	end
end)

for _, event in next, {
	"PLAYER_ENTERING_WORLD",
	"READY_CHECK",
} do
	caelUI.readycheck:RegisterEvent(event)
end
But now i get:

Code:
Error occured in: Global
Message:
..\AddOns\caelUI\modules\misc\readyCheck.lua line 52:
   Usage: UnitBuff("unit", [index] or ["name", "rank"][, "filter"])
Debug:
   [C]: ?
   [C]: UnitBuff()
   caelUI\modules\misc\readyCheck.lua:52:
      caelUI\modules\misc\readyCheck.lua:35
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote
11-14-13, 06:36 AM   #8
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Caellian View Post
Hmm ? GetSpellName is a function i create, and GetSpellInfo without parameters returns the name.
My bad i tought it's:

http://wowprogramming.com/docs/api/GetSpellName
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with UnitBuff


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