View Single Post
05-29-23, 08:20 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Here's what I've come up with along with some tweaks and optimizations.

Lua Code:
  1. local AddOnPath=("Interface\\AddOns\\%s\\"):format(...);--  Dynamically fetch our addon path
  2.  
  3. local Frame=CreateFrame("ScrollingMessageFrame",nil,UIParent)
  4. Frame:SetSize(450,200)
  5. Frame:SetPoint("CENTER")
  6. Frame:SetFont(AddOnPath.."Res\\PHA_.TTF",30,"THICKOUTLINE")
  7. Frame:SetShadowColor(0.00,0.00,0.00,0.75)
  8. Frame:SetShadowOffset(3.00,-3.00)
  9. Frame:SetJustifyH("CENTER")
  10. Frame:SetMaxLines(2)
  11. --Frame:SetInsertMode("BOTTOM")
  12. Frame:SetTimeVisible(2)
  13. Frame:SetFadeDuration(1)
  14.  
  15. Frame:RegisterEvent("PLAYER_LOGIN")
  16. Frame:RegisterUnitEvent("UNIT_PET","player")
  17. Frame:RegisterUnitEvent("UNIT_HEALTH","pet")
  18.  
  19. local LowHealthThreshold=0.35;
  20. local LastHealthValue=0;
  21. Frame:SetScript("OnEvent",function(self)
  22.     if UnitExists("pet") then-- Check if pet exists
  23.         local cur,max=UnitHealth("pet"),UnitHealthMax("pet");
  24.         if cur and max and max>0 then-- Check if we have health data
  25.             if cur<LastHealthValue then--   Has health decreased?
  26.                 if cur<=0 then--    Is pet dead?
  27.                     PlaySoundFile(AddOnPath.."Res\\PHA.ogg")
  28.                     self:AddMessage("- PET DEAD -", 1, 0, 0, nil, 3)
  29.                 elseif cur/max<=LowHealthThreshold then--   Is pet low health?
  30.                     PlaySoundFile(AddOnPath.."Res\\PHA.ogg")
  31.                     self:AddMessage("- CRITICAL PET HEALTH -", 1, 0.5, 0, nil, 3)
  32.                 end
  33.             end
  34.  
  35.             LastHealthValue=cur;--  Update tracking value
  36.         else LastHealthValue=0; end--   Reset to zero if health not available yet
  37.     else LastHealthValue=0; end--   Reset to zero if no pet
  38. 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