I miss MSBT's low health/mana alerts since I don't use it anymore and decided to recreate it myself with a small addon.
Code:
local playedhp, playedmp
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, unit, ...)
if not unit=="player" then return end
if event=="UNIT_HEALTH" then
if UnitHealth("player") < (UnitHealthMax("player")/100)*30 then
if playedhp ~= true then
playedhp = true
PlaySoundFile("Interface\\AddOns\\!FreeUI\\media\\LowHealth.mp3")
end
else
playedhp = false
end
elseif event=="UNIT_MANA" then
if UnitPower("player") < (UnitPowerMax("player")/100)*30 then
if playedmp ~= true then
playedmp = true
PlaySoundFile("Interface\\AddOns\\!FreeUI\\media\\LowMana.mp3")
end
else
playedmp = false
end
end
end)
f:RegisterEvent("UNIT_HEALTH")
f:RegisterEvent("UNIT_MANA")
The problem is that, say, when the health drops to below 30%, it won't play the sound instantly; it will play the sound after the health is updated *again* (OOC regen/healing/...). I'm fairly clueless as to why. The way I see it now, as soon as the health drops below 30%, 'playedhp' becomes true and the sound file should be instantly played. But that doesn't seem to be happening.
I didn't test mana yet but I'm fairly sure it's the same.
Could anyone help me out here?