View Single Post
08-01-14, 03:55 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your first problem is this:
Code:
    local name = UnitBuff("player", BLOODLUST)
    if name == 1 then
The first value returned by UnitBuff will never be the number 1, so this check will never pass.

Your second problem is that you can't set multiple OnEvent scripts on the same frame -- each one you set overwrites all the ones set before it.

Your third problem is that you're only checking if the player currently has the buff before playing the sound -- this will result in the sound playing over and over every time your buffs change, as long as the specific buff is still active. You need to keep track of the state for each buff, so you only play the sound when you first gain the buff.

Also you'd mixed up your Bloodlust and Heroism spell IDs when you get the names from GetSpellInfo.

Try this:

Code:
local state = {
	[(GetSpellInfo(2825))]  = false, -- Bloodlust
	[(GetSpellInfo(32182))] = false, -- Heroism
	[(GetSpellInfo(80353))] = false, -- Time Warp
}

local f = CreateFrame("Frame")
f:RegisterUnitEvent("UNIT_AURA", "player")
f:SetScript("OnEvent", function()
	for buff, active in pairs(state) do
		if UnitBuff("player", buff) then
			if not active then
				PlaySoundFile("Interface\\AddOns\\BLita\\Sounds\\BLita.mp3", "Master")
				state[buff] = true
			end
		elseif active then
			state[buff] = false
		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