This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Live
PTR
10.2.7
PTR
10.2.6
Beta
Some more LUA help... (Solved)
Post Reply
Return to board index
Post by
Nipah
*sighs* I've really tried to get this to work properly, but it seems to be beyond my abilities... so I come here, Wowhead, where all my questions get answered!
I have the following LUA code in my Stuf (unit frame addon) text:
note: its been quite butchered by me, so if its missing/has an extra "end" or something, its my fault
function(unit, cache, textframe)
local petlove, petlovecolor, peticon
local petlove, _, _ = GetPetHappiness()
local pettype = UnitCreatureType("pet")
if (petlove == 3) then petlovecolor = "|c0000ff1f" peticon = "V"
else if (petlove == 2) then petlovecolor = "|c00ffee1f" peticon = "P"
else if (petlove == 1) then petlovecolor = "|c00ff0000" peticon = "F"
else petlovecolor = "|c00FFFFFF"
end end end end
return petlovecolor..peticon.."|r" end
note2: I had a check for "if pettype ~= "Beast" then end" in the beginning, but it didn't do anything, and adding a "return "" " to it was the same effect...
This shows a little symbol based on my Hunter's pet's happiness (thanks to a symbols font, naturally)... the problem comes when I play my Warlock or Death Knight (my bankers who have pets). I have "Frequent Updates" checked off because otherwise it doesn't update often enough, and when it finds out that my pets don't have happiness, it makes my game chop whenever I move around (though the framerate doesn't drop). If I disable this chunk of text, it works fine... and it works flawlessly on my Hunter, so its just a matter of getting it to not do anything if pettype ~= "Beast".
I have the following for my pet's XP (on mouseover), and it works no problem... so a way to combine the "if not beast, do nothing" would be fantastic... I just can't seem to get it to work properly for whatever reason.
note: this can probably also be tweaked, but its working, so I don't really care.
function(unit, cache, textframe)
local level = UnitLevel("pet")
local exp, maxxp = GetPetExperience()
local pettype = UnitCreatureType("pet")
if pettype == "Beast" and level ~= 85 then
return "%s/%s", exp, maxxp
else
end end
Post by
Safturento
for the first one, try this:
function(unit, cache, textframe)
if select(2, UnitClass("player")) ~= "HUNTER" then return end
local petlove, _, _ = GetPetHappiness()
if (petlove == 3) then
return "|c0000ff1fV|r"
else if (petlove == 2) then
return "|c0000ff1fP|r"
else if (petlove == 1) then
return "|c00ff0000F|r"
else
return end
end
end
and try this for the second one:
function(unit, cache, textframe)
if select(2, UnitClass("player")) ~= "HUNTER" then return end
local exp, maxxp = GetPetExperience()
if UnitLevel("pet") ~= 85 then
return "%s/%s", exp, maxxp
else
return end
end
end
Post by
Nipah
Thanks for the help Saft!
With a bit of tweaking, I got this to work:
function(unit, cache, textframe)
local petlove, _, _ = GetPetHappiness()
local pettype = UnitCreatureType("pet")
if pettype ~= "Beast" then return end
if (petlove == 3) then
return "|c0000ff1fV|r"
else if (petlove == 2) then
return "|c00ffee1fP|r"
else if (petlove == 1) then
return "|c00ff0000F|r"
else
return end
end end
end
It didn't seem to like checking on my character class (which seemed to me to be a spot on idea... wish I had thought of it!), so I rigged it to just check on the pet type instead (same goes for the pet XP... I'm sure it would work if tweaked, but I've been logging on/off on my various characters for the past 30m or so, and its getting old).
Thanks again for providing me with the help I needed to get this to work... And as a bonus, I'll have this post to reference if I should happen to lose this code sometime along the line.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.