WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Making a simple addon need event help (https://www.wowinterface.com/forums/showthread.php?t=44274)

Spawnova 09-10-12 06:49 PM

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

Xrystal 09-10-12 07:08 PM

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.

Haleth 09-10-12 07:10 PM

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.

Dridzt 09-10-12 07:17 PM

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


Xrystal 09-10-12 07:41 PM

Quote:

Originally Posted by Haleth (Post 263262)
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.

Spawnova 09-10-12 07:43 PM

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 =)


All times are GMT -6. The time now is 11:44 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI