Not tested at all, but this should work:
1. Create a folder in your AddOns folder and name it "SimpleExecuteAlert".
2. Create a text file inside that folder and name it "SimpleExecuteAlert.toc". Inside it, write:
Code:
## Interface: 40000
SimpleExecuteAlert.lua
3. Create another text file in the same location and name it "SimpleExecuteAlert.lua". Inside it, write:
Code:
-- ***** BEGIN CONFIGURATION *****
-- Set the health percent below which to alert you.
local PERCENT = 0.35
-- Set the alert message to show you.
local MESSAGE = "Execute Now!"
-- Set the interval (in seconds) between alerts.
local INTERVAL = 10
-- ***** END CONFIGURATION *****
-- Store the time of the last reminder
local lasttime = 0
-- Create a frame to watch for target changes and health changes.
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_TARGET_CHANGED")
f:SetScript("OnEvent", function(self, event, unit)
if event == "UNIT_HEALTH" then
if unit ~= "target" then
-- We don't care about this unit.
-- Quit.
return
end
-- Find out how much health the target has.
local current, max = UnitHealth("target"), UnitHealthMax("target")
if current / max <= PERCENT then
-- The target's health is less than or equal to 35%.
if GetTime() - lasttime >= INTERVAL then
-- It's been at least INTERVAL seconds since the last alert.
-- Show the alert message in the UI Errors frame.
UIErrorsFrame:AddMessage(MESSAGE, 1, 0.6, 0)
-- Store the time of the alert.
lasttime = GetTime()
end
else
-- Don't need to check if it's PLAYER_TARGET_CHANGED, since
-- that's the only other event this frame listens for.
if UnitExists("target") and UnitCanAttack("player", "target") then
-- Target exists and is attackable.
-- Start watching its health.
self:RegisterEvent("UNIT_HEALTH")
-- Reset the time of the last warning, since this is a different target.
lasttime = 0
-- Immediately check the target's health.
self:GetScript("OnEvent")(self, "UNIT_HEALTH", "target")
else
-- Target doesn't exist or isn't attackable.
-- Stop watching its health.
self:UnregisterEvent("UNIT_HEALTH")
end
end
end)
4. Change the values at the top of the Lua file as desired.