View Single Post
10-15-20, 05:14 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
The basics would be something like:
Lua Code:
  1. local maxNotifications = 3
  2. local f = CreateFrame("Frame")
  3. f:RegisterEvent("UNIT_HAPPINESS")
  4. f.happiness = 0
  5. f.happinessCount = 0
  6. f:SetScript("OnEvent", function(self, event, ...)
  7.     local unit = ...
  8.         if unit ~= "pet" then return
  9.     end
  10.     local happiness, damagePercentage, loyaltyRate = GetPetHappiness()
  11.     if self.happinessCount > maxNotifications and self.happiness == happiness then
  12.         return
  13.     end
  14.     if happiness ~= self.happiness then
  15.         self.happinessCount = 0
  16.     end
  17.     self.happinessCount = self.happinessCount + 1
  18.     self.happiness = happiness
  19.     if happiness == 1 then
  20.         UIErrorsFrame:AddMessage("FEED YOUR PET ALREADY!!!", 1.0, 0, 0, 1.0)
  21.     elseif happiness == 2 then
  22.         UIErrorsFrame:AddMessage("Your pet is a little miffed with you!", 1.0, 1.0, 0, 1.0)
  23.     end
  24. end)
UNIT_HAPPINESS is a rolling event so as is, this only shows a message 3 times when the happiness level changes.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote