Thread Tools Display Modes
11-05-10, 10:48 PM   #1
vbaspcppguy
A Murloc Raider
Join Date: Jan 2008
Posts: 8
Execute range notifcation?

I'm looking for an addon that will notify me when I need to switch to backstab for mut spec (at 35% hp) ...preferably one that isn't bloated with other stuff.
  Reply With Quote
11-06-10, 07:58 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
  Reply With Quote
11-07-10, 01:56 PM   #3
vbaspcppguy
A Murloc Raider
Join Date: Jan 2008
Posts: 8
So, I gave this a whack. No joy. I'll try to put some time into it later... I'm actually a programmer but I have very little experience with the wow api. This should be enough to get me on my way though.

Couple notes:
-Only tested in a duel so far. Dunno if its meant to work in PvP applications.
-I haven't actually put this in a lua file. I used WowLua to run it.
-There was a problem with the syntax of the inline function that I couldn't figure out (don't know lua well), so I made it a regular function.
  Reply With Quote
11-08-10, 05:01 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Fixed; there was a missing "end" in there. I tested in-game to make sure it works this time:

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 health, maxHealth = UnitHealth("target"), UnitHealthMax("target")
		if health > 0 and health / maxHealth <= PERCENT then

			-- The target is alive, and its health is 35% or lower.
			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
		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)

Last edited by Phanx : 11-08-10 at 05:06 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Execute range notifcation?


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