health% sound alert (help)
Hello, can you please tell me what to add to this addon so there's a sound alert playing when my life goes below 99%?
There's already sounds alerts when my life goes below 50% and 25%, but I need to add an alert for 99% if possible.
Thanks.
Code:
local version = "2.4"
-- www.curse.com/addons/wow/low-hp-alert
-- quick and dirty, what else.
-- Author: Fratzi, Puriya (creator)
-- Frame for updating variables after addon load (used for new addon releases)
local name, addon = ...
local f = CreateFrame("Frame")
local function onevent(self, event, arg1, ...)
if((event == "ADDON_LOADED" and name == arg1)) then
-- Fresh Install, setting globals
if(LowHPAlert_Options == nil) then
LowHPAlert_Options = {
["tankmode"] = false,
["soundcombatonly"] = false,
["soundalwaysoff"] = false,
["showtext"] = true,
["version"] = version
}
elseif(LowHPAlert_Options.version == nil) then
-- Version is below 2.4, adding new rows into tables, clear up deprecated variables
LowHPAlert_Options.version = "2.4"
LowHPAlert_Options.showtext = true
LowHPAlert_Options.cockpit = nil
DEFAULT_CHAT_FRAME:AddMessage("----------------------------------------------", 1.0, 0.0, 0.0, nil, true)
DEFAULT_CHAT_FRAME:AddMessage("Low HP Alert updated - new option to turn off all text messages: /lowhpalert text", 1.0, 0.0, 0.0, nil, true)
DEFAULT_CHAT_FRAME:AddMessage("----------------------------------------------", 1.0, 0.0, 0.0, nil, true)
elseif(LowHPAlert_Options.version ~= version) then
-- version is below current version, placeholder for future updates
elseif(LowHPAlert_Options.version == version) then
-- Everything is ok, placeholder
end
f:UnregisterAllEvents()
end
end
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", onevent)
local sounds = true
-- sets player HP to OK!
local LastHealth = 0
-- event caller
function LowHPAlert_OnUpdate()
if (LowHPAlert_Options.soundalwaysoff) then
sounds = false
elseif (LowHPAlert_Options.soundcombatonly and not UnitAffectingCombat("player")) then
sounds = false
else
sounds = true
end
-- some hardcore math
hp = UnitHealth("player")
hpPct = hp / UnitHealthMax("player")
if (LowHPAlert_Options.tankmode) then
LowHPAlert_OnUpdate_tank()
else
LowHPAlert_OnUpdate_default()
end
end
-- tankmode 0 = warning at 50% and 25%
function LowHPAlert_OnUpdate_default()
if (hpPct > 0.5) then
LastHealth = 0
return
elseif (hpPct > 0.25) then
if (LastHealth == 0) then
if (LowHPAlert_Options.showtext) then HealthMessageFrame:AddMessage("", 1, 1, 0, 1, 3) end
if (sounds) then PlaySoundFile("Interface\\AddOns\\LowHPAlert\\20.mp3", "master") end
end
LastHealth = 1
return
-- HP < 25%
elseif (LastHealth ~= 2) then
if (LowHPAlert_Options.showtext) then HealthMessageFrame:AddMessage("", 1, 0, 0, 1, 3) end
if (sounds) then PlaySoundFile("Interface\\AddOns\\LowHPAlert\\30.mp3", "master") end
end
LastHealth = 2
end
-- slash commands
SLASH_LOWHPALERT1 = '/lowhpalert'
local function slashhandler(msg, editbox)
if msg == 'tankmode' then
if(LowHPAlert_Options.tankmode) then
LowHPAlert_Options.tankmode = false
print("Tankmode OFF!")
else
LowHPAlert_Options.tankmode = true
LowHPAlert_Options.cockpit = false
print("Tankmode ON!")
end
elseif msg == 'combatmode' then
if(LowHPAlert_Options.soundcombatonly) then
LowHPAlert_Options.soundcombatonly = false
print("Alerts always ON!")
else
LowHPAlert_Options.soundcombatonly = true
print("Alertts will be only played in combat!")
end
elseif msg == 'sound' then
if(LowHPAlert_Options.soundalwaysoff) then
LowHPAlert_Options.soundalwaysoff = false
print("Sounds ON!")
else
LowHPAlert_Options.soundalwaysoff = true
print("Sounds always OFF!")
end
elseif msg == 'text' then
if(LowHPAlert_Options.showtext) then
LowHPAlert_Options.showtext = false
print("Text OFF!")
else
LowHPAlert_Options.showtext = true
print("Text ON!")
end
else
print(" ")
print("LowHPAlert version " .. version)
print("-----------------------------")
print("/lowhpalert tankmode - only alerts at 30% HP")
print("/lowhpalert combatmode - only play alert sounds in combat")
print("/lowhpalert sound - turns off all sounds")
print("/lowhpalert text - turns off all text messages on screen")
end
end
SlashCmdList["LOWHPALERT"] = slashhandler
function LowHPAlert_OnLoad()
DEFAULT_CHAT_FRAME:AddMessage("Low HP Alert version " .. version .. " loaded - Options: /lowhpalert", 0.0, 0.8, 0.0, nil, true)
end
|