Thread Tools Display Modes
08-26-09, 08:16 PM   #1
kc102
A Defias Bandit
Join Date: Aug 2009
Posts: 2
Attempting a Health Alert addon

This is the first addon I'm making from scratch and I really don't see why it doesn't wish to work. Doesn't seem to load at all, and yes it's in the correct location with a toc file and such. Any and all help much appreciated.

TOC
Code:
## Title: Health Alert
## Version: 1.0
## Author: R34P3R
## Interface: 30200
## Notes: An addon that alerts nearby players when health is low.
HealthAlert.lua
HealthAlert.xml
XML

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ >
<Frame name="HealthAlert">
	<Scripts>
		<OnLoad>
			ha_OnLoad();
		</OnLoad>
		<OnEvent>
			ha_OnUpdate();
		</OnEvent>
	</Scripts>
</Frame>
</Ui>
LUA
Code:
function ha_OnUpdate()
   local HPC = UnitHealth("player") / UnitMaxHealth("player");
   
   if HPC < 0.5 then
		SendChatMessage("My health is below 50%!","SAY",nil);
   elseif HPC < 0.4 then
		SendChatMessage("My health is below 40%!","SAY",nil);
   elseif HPC < 0.3 then
		SendChatMessage("My health is below 30%!","SAY",nil);
   elseif HPC < 0.2 then
		SendChatMessage("My health is below 20%! CRITICAL!","YELL",nil);
   elseif HPC < 0.1 then
		SendChatMessage("My health is below 10%! HEAL ME!","YELL",nil);
   end
end

function ha_OnLoad()
	DEFAULT_CHAT_FRAME:AddMessage("Health Alert Loaded", 1, 0, 0);
	this:RegisterEvent("UNIT_HEALTH");
end

Last edited by kc102 : 08-26-09 at 08:43 PM.
  Reply With Quote
08-26-09, 08:21 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
You don't need to reference healthalert.lua in two places, and you need a frame. Thus...

Change this:
Code:
<Script file="HealthAlert.lua" />
to this:
Code:
<Frame name="HealthAlert">
And this:
Code:
</Scripts>
to this:
Code:
</Scripts>
</Frame>
  Reply With Quote
08-26-09, 08:26 PM   #3
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
As a secondary point, you should probably change the conditionals to elseifs or some other way of not spamming all of the levels that you're below (if you're below 10 it will send all 5 warnings); and also, throttle it so that you don't announce every time anyone's health changes.
  Reply With Quote
08-26-09, 08:44 PM   #4
kc102
A Defias Bandit
Join Date: Aug 2009
Posts: 2
I've updated 1st post with said changes but it still doesn't wish to work. I don't know how to make it only pick up my health, but I did change it to elseifs.

Edit: Got it, thanks.

Last edited by kc102 : 08-31-09 at 04:37 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Attempting a Health Alert addon


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