The basics would be something like:
Lua Code:
local maxNotifications = 3
local f = CreateFrame("Frame")
f:RegisterEvent("UNIT_HAPPINESS")
f.happiness = 0
f.happinessCount = 0
f:SetScript("OnEvent", function(self, event, ...)
local unit = ...
if unit ~= "pet" then return
end
local happiness, damagePercentage, loyaltyRate = GetPetHappiness()
if self.happinessCount > maxNotifications and self.happiness == happiness then
return
end
if happiness ~= self.happiness then
self.happinessCount = 0
end
self.happinessCount = self.happinessCount + 1
self.happiness = happiness
if happiness == 1 then
UIErrorsFrame:AddMessage("FEED YOUR PET ALREADY!!!", 1.0, 0, 0, 1.0)
elseif happiness == 2 then
UIErrorsFrame:AddMessage("Your pet is a little miffed with you!", 1.0, 1.0, 0, 1.0)
end
end)
UNIT_HAPPINESS is a rolling event so as is, this only shows a message 3 times when the happiness level changes.