View Single Post
06-06-23, 01:37 AM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Lua Code:
  1. local AddOnPath=("Interface\\AddOns\\%s\\"):format(...);--  Dynamically fetch our addon path
  2. local EventFrame=CreateFrame("Frame");
  3.  
  4. EventFrame:RegisterEvent("PLAYER_LOGIN");
  5. EventFrame:RegisterUnitEvent("UNIT_PET","player");
  6. EventFrame:RegisterUnitEvent("UNIT_HEALTH","pet");
  7.  
  8. local LowHealthThreshold=0.35;
  9. local LastHealthValue=0;
  10. EventFrame:SetScript("OnEvent",function(self)
  11.     local cur,max; if UnitExists("pet") then--  Check if pet exists
  12.         cur,max=UnitHealth("pet"),UnitHealthMax("pet");
  13.     else cur,max=0,1; end-- Process no pet as dead
  14.  
  15.     if cur and max and max>0 then-- Check if we have health data
  16.         if cur<=0 and LastHealthValue>0 then--  Is pet dead?
  17.             PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  18.         elseif cur/max<=LowHealthThreshold and LastHealthValue/max>LowHealthThreshold then--    Is pet low health?
  19.             PlaySoundFile(AddOnPath.."Res\\PHA.ogg");
  20.         end
  21.  
  22.         LastHealthValue=cur;--  Update tracking value
  23.     else LastHealthValue=0; end--   Reset to zero if health not available yet
  24. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote