WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Help with Hunter pet addon (WoW classic) (https://www.wowinterface.com/forums/showthread.php?t=58292)

awildgoose11 10-15-20 03:12 PM

Help with Hunter pet addon (WoW classic)
 
I am a complete noob with Lua, but the basic thing I want it to do is use the message to pop up on the screen when the "var1" from GetPetHappiness() goes from 3 to 2.

Any help would be appreciated!

Code:

local p = {}
local var1,var2,var3=GetPetHappiness()
function p.repeatloop()
    local var1,var2,var3=GetPetHappiness()
    local result
 
    result = ';repeat\n'
    repeat
        result = result .. ":var1 = " .. var1 .. '\n'
        var1,var2,var3=GetPetHappiness()
    until var1 = 2
    message('Feed your pet!')
 
    return result
end

return p


Fizzlemizz 10-15-20 05:14 PM

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.


All times are GMT -6. The time now is 05:38 PM.

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