Thread Tools Display Modes
09-10-12, 06:49 PM   #1
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Making a simple addon need event help

I'm making a simple addon to check my pets health and see if it's below 80% but i'm stuck on what event i should use to check it's health

i'm very newby to lua and have only made one other addon i get the jist of it but choosing what events i should use is still a bit difficult
  Reply With Quote
09-10-12, 07:08 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
UNIT_HEALTH with arg1 being "pet"
http://wowprogramming.com/docs/events/UNIT_HEALTH

And then use GetUnitHealth("pet")
http://wowprogramming.com/docs/api/UnitHealth

This is of course you are talking about hunter pets. If you are talking about the critter pets these are listed elsewhere on the same site under pet battle.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
09-10-12, 07:10 PM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
UnitHealth, not GetUnitHealth.

Also a good idea is to check if the unitID returned by UNIT_HEALTH is that of the unit you're interested in before you do anything else.
  Reply With Quote
09-10-12, 07:17 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Code:
local eventframe = CreateFrame("Frame")

eventframe:SetScript("OnEvent", 
	function(self,event,...)
		return self.event and self.event(...)
	end)
	
eventframe:RegisterUnitEvent("UNIT_HEALTH_FREQUENT","pet")

function eventframe.UNIT_HEALTH_FREQUENT(...)
	local hpRatio = UnitHealth("pet")/UnitHealthMax("pet") < 0.8 and print("Pet Health Low!")
end

Last edited by Dridzt : 09-11-12 at 01:47 AM.
  Reply With Quote
09-10-12, 07:41 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Originally Posted by Haleth View Post
UnitHealth, not GetUnitHealth.

Also a good idea is to check if the unitID returned by UNIT_HEALTH is that of the unit you're interested in before you do anything else.
Oops so it was. Erm, it's 2am, guess I misread it with my tired eyes. Yeah that might work. Thanks haleth.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
09-10-12, 07:43 PM   #6
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Ok, I went over everything you guys posted and it really helped alot!

Thanks Dridzt your code made it easier for me to understand what i needed to change and now everything works fine =D

and thanks everyone else all very helpful =)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Making a simple addon need event help


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