Umm.. I did some looking around @ lua and i came up with this
local happiness, damagePercentage, loyaltyRate = GetPetHappiness()
local happy = ({"cffC41F3B", "cffFFF569", "cffABD473"})[happiness]
return '|%s%s|r',happy,Name(unit)
I am just wondering if this is the most efficient way of doing this?
You really don't want to make a temporary table like that. It's certainly convenient but you're produce garbage everytime. This is much better efficiency wise:
local happiness = GetPetHappiness()
local happy
if happiness == 1 then
happy = "C41F3B"
elseif happiness == 2 then
happy = "FFF569"
elseif happiness == 3 then
happy = "ABD473"
else
happy = "FFFFFF"
end
return '|cff%s%s|r',happy,Name(unit)
Also yours wouldn't function if happiness wasn't one of the three values. This just uses white if the pet doesn't have a happiness (vehicle situations for example)
I would like to fine tune my Targets HP text a bit.
If the target is at full then only show "Current HP | Max HP".
If the Target is friendly then only show "Current HP | Max HP" no matter what % its at.
If the target is below 100% HP then "Current HP | Max HP | HP %" . I would like the % Color coded to change as it begins to drop.
I also want the numbers to be formatted like they are currently, "20.6k" and not 20612. But be seperated by a "|" and not "/".
Here what I'm using atm :
Outline()
local s = Status(unit)
if s then
return s
end
local cur, max = HP(unit), MaxHP(unit)
if UnitIsFriend(unit,"player") then
local miss = max - cur
if miss ~= 0 then
return "|cffff7f7f%s|r || %s/%s || %s%%",Short(miss,true),Short(cur,true),Short(max,true),Percent(cur,max)
end
end
return "%s/%s || %s%%",Short(cur,true),Short(max,true),Percent(cur,max)
If the target is at full then only show "Current HP | Max HP".
If the Target is friendly then only show "Current HP | Max HP" no matter what % its at.
If the target is below 100% HP then "Current HP | Max HP | HP %" . I would like the % Color coded to change as it begins to drop.
I also want the numbers to be formatted like they are currently, "20.6k" and not 20612. But be seperated by a "|" and not "/".
local min, max = HP(unit), MaxHP(unit)
local r, g, b = HPColor(min, max)
local showPercent = (UnitIsEnemy(unit, "player") and min < max)
return "%s | %s %s|cff%02x%02x%02x%s", Short(min, "%.1f"), Short(max, "%.1f"), showPercent and "| " or "", r, g, b, showPercent and VeryShort(Percent(min, max), "%.1f").."%" or ""
local min, max = HP(unit), MaxHP(unit)
local r, g, b = HPColor(min, max)
local showPercent = (UnitIsEnemy(unit, "player") and min < max)
return "%s | %s %s|cff%02x%02x%02x%s", Short(min, "%.1f"), Short(max, "%.1f"), showPercent and "| " or "", r, g, b, showPercent and VeryShort(Percent(min, max), "%.1f").."%" or ""
Umm you're using Short wrong. The format parameter on Short is just a boolean to say if you want Short to do the format for you or not. If it's false it returns the format string and then the value to format and if it's true it returns a formatted value.
This allows a format to be avoided if it can be e.g.:
return Short(HP(unit))
Since it's the only thing being done Short can just control the format string being returned. But if you need to do something more complex where you need to set the format string yourself you pretty much need to let Short/VeryShort do the formatting themselves.
Also, you should always use || if you want a literal | in your output since it's an escape character for WoW.
You also concatenated the % on the end. You should let the C side code handle that by just passing it through as another parameter.
Here's the fixed up code.
local min, max = HP(unit), MaxHP(unit)
local r, g, b = HPColor(min, max)
local showPercent = (UnitIsEnemy(unit, "player") and min < max)
return "%s || %s %s|cff%02x%02x%02x%s%s", Short(min, true), Short(max, true), showPercent and "|| " or "", r, g, b, showPercent and VeryShort(Percent(min, max), true) or "",showPercent and '%' or ""
Since it's the only thing being done Short can just control the format string being returned. But if you need to do something more complex where you need to set the format string yourself you pretty much need to let Short/VeryShort do the formatting themselves.
Also, you should always use || if you want a literal | in your output since it's an escape character for WoW.
You also concatenated the % on the end. You should let the C side code handle that by just passing it through as another parameter.
When I called Short(min) without the second parameter it displayed the format (%.1f) instead of the value. The one I posted works fine, but fair enough on the escape char change.
Is there any particular advantage to passing the % through as another value rather than concatenating, though?
When I called Short(min) without the second parameter it displayed the format (%.1f) instead of the value.
Right because of the way Lua handles multiple returns in a list:
a,b,foo(),e,f
Let's say foo returns c,d
The above would actually only evaluate to:
a,b,c,e,f
However:
a,b,foo()
would evaulate to a,b,c,d
It's kinda silly and annoying but it's the way Lua is. In retrospect the 2nd parameter to Short should probably have defaulted to true instead of false. But it's kinda late to make that change.
Also any value except false and nil evaluates to true. So Short just did it at though you'd done Short(value,true). But the string you were passing really wasn't do anything itself.
Is there any particular advantage to passing the % through as another value rather than concatenating, though?
Passing it through produces no garbage. Concatenation produces a new string because of the way Lua handles strings.
a = a .. b
b is not just added onto a but a new string is made that replaces a. The old a has to be garbage collected. C side doesn't have the same issues.
Works great Shef. No I thinking about a missing buff text. I would like just a simple "A" is Arcane intellect or Arcane Brilliance, or Dalaran Brilliance is missing. And a "FM"on any Mage and Mage only that is missing Focus Magic.
I would like just a simple "A" is Arcane intellect or Arcane Brilliance, or Dalaran Brilliance is missing. And a "FM"on any Mage and Mage only that is missing Focus Magic.
local i = 1
local int = false
while true do
local name = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Arcane Intellect" then
int = true
break
elseif name == "Arcane Brilliance" then
int = true
break
elseif name == "Dalaran Intellect" then
int = true
break
elseif name == "Dalaran Brilliance" then
int = true
break
end
i=i+1
end
if UnitPowerType(unit) == 0 and not int then
return "A"
end
local class = Class(unit)
if class == "Mage" then
local i=1
local fm = false
while true do
local name = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Focus Magic" then
fm = true
end
i=i+1
end
if not fm then
return "FM"
end
end
Last edited by Hotan : 07/02/09 at 3:20 PM.
Reason: reveresed true/false
<string>:"PitBull4_LuaTexts:Player:Lua: FM":14: 'end' expected (to close 'function' at line 1) near '<eof>'
PitBull4-v4.0.0-beta1\ModuleHandling\TextProviderModule.lua:117: in function `UpdateFrame'
PitBull4-v4.0.0-beta1\ModuleHandling\TextProviderModule.lua:149: in function `ForceTextUpdate'
PitBull4-v4.0.0-beta1\Modules\LuaTexts\LuaTexts.lua:1191: in function <...erface\AddOns\PitBull4\Modules\LuaTexts\LuaTexts.lua:1187>
PitBull4-v4.0.0-beta1\Modules\LuaTexts\LuaTexts.lua:1260: in function <...erface\AddOns\PitBull4\Modules\LuaTexts\LuaTexts.lua:1256>
(tail call): ?:
<in C code>: ?
<string>:"safecall Dispatcher[2]":9: in function <[string "safecall Dispatcher[2]"]:5>
(tail call): ?:
AceConfigDialog-3.0-34:786: in function <...nfig-3.0\AceConfigDialog-3.0\AceConfigDialog-3.0.lua:605>
(tail call): ?:
<in C code>: ?
<string>:"safecall Dispatcher[3]":9: in function <[string "safecall Dispatcher[3]"]:5>
(tail call): ?:
AceGUI-3.0-23 (Ace3):305: in function `Fire'
...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:76: in function <...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:73>:
...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:85: in function <...AceGUI-3.0\widgets\AceGUIWidget-MultiLineEditBox.lua:82>:
Isn't the 1st still missing i = i+1 to increase the counter inside the loop? And the second have no counter at all.
Edit: Assuming it is beginners who ask for help with tags, using int = true to indicate when the buff is missing might be a bit confusing for those who aren't good at reading code.
Actually, i'm going to edit this post again because I'm still having issues with an indicator code.
It seemed to work fine this way with DogTags, but once I converted to LuaTexts it's not working properly.
I have indicators to show when Renew, Prayer of Mending, Shield, etc. are on a target in my raid, so I know when to refresh them.. However, when shield fades the indicator fades, even if they still have Weakened Soul (meaning I can't refresh the shield).
This is the code I used at first:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Weakened Soul" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
This one worked fine except for the Weakened Soul problem.
So I read through this thread more and found the HARMFUL code, and added that in, ending up with this:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
local name,_,icon = UnitAura(unit,i,"HARMFUL")
if not name then
break
elseif name == "Weakened Soul" then
shield = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
This seemed to have done the trick at first, but now it won't show all of the indicators at once if I have all 3 buffs on me.
Can someone tell me what I'm missing, if anything? Or if maybe it's just bugged? Or tell me if this is completely wrong, because Lua frustrates me and i've just been hacking my codes together with copy and paste from this thread.
Last edited by Eyrika : 07/06/09 at 8:01 PM.
Reason: l2read
Actually, i'm going to edit this post again because I'm still having issues with an indicator code.
It seemed to work fine this way with DogTags, but once I converted to LuaTexts it's not working properly.
I have indicators to show when Renew, Prayer of Mending, Shield, etc. are on a target in my raid, so I know when to refresh them.. However, when shield fades the indicator fades, even if they still have Weakened Soul (meaning I can't refresh the shield).
This is the code I used at first:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Weakened Soul" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
This one worked fine except for the Weakened Soul problem.
So I read through this thread more and found the HARMFUL code, and added that in, ending up with this:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
local name,_,icon = UnitAura(unit,i,"HARMFUL")
if not name then
break
elseif name == "Weakened Soul" then
shield = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
This seemed to have done the trick at first, but now it won't show all of the indicators at once if I have all 3 buffs on me.
Can someone tell me what I'm missing, if anything? Or if maybe it's just bugged? Or tell me if this is completely wrong, because Lua frustrates me and i've just been hacking my codes together with copy and paste from this thread.
I'd do this:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i)
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Weakened Soul" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
I just took the filter off your UnitAura call. It should get buffs and debuffs all together. Your version wasn't working right because you were trying to use one loop for both. There might be say 5 HELPFUL auras and 1 debuff. Your version would stop after it got to i = 1 because i = 2 would have no debuff.
Mixing buffs and debuffs should be safe for the purposes of what you're doing. I doubt there's a debuff called Prayer of Mending and so on.
Thank you for your suggestion, however it still doesn't appear to work It's working the same as the first code I tried and not keeping the "S" when I have no shield but still have weakened soul. I'll keep working at it and see if I can find something.
Edit: I tried another code you posted on the first page:
local i = 1
local renew,shield,mending = false,false,false
while true do
local name,_,icon = UnitAura(unit,i,"HELPFUL")
if not name then
break
elseif name == "Power Word: Shield" then
shield = true
elseif name == "Renew" then
renew = true
elseif name == "Prayer of Mending" then
mending = true
end
i = i + 1
end
local i = 1
while true do
local name,_,icon = UnitAura(unit,i,"HARMFUL")
if not name then
break
elseif name == "Weakened Soul" then
shield = true
end
i = i + 1
end
Outline()
return "%s %s %s",shield and "|cffFFFF00S|r" or '',renew and "|cff00C000R|r" or '',mending and "|cffFFFF00M|r" or ''
And so far, it's working right. I think I may have just missed one line somewhere.
I am currently using the code below for my Lua:Power text. Right now it loos like this:
Current MP | Percent
if UnitPowerType(unit) == 0 then
cur,max=Power(unit),MaxPower(unit)
return "%s | %s%%",cur,Percent(cur,max)
else
cur=Power(unit)
return cur
end
I'd like to color it so it starts out as "mage blue" (my default mana coloring)> yellow>red and I would also like to change the Current MP to short so my tag looks like this 5.6k instead of 5623. So my tag would look like this:
5.6k | 100%
Thank you in advance. I'm sure you get tons and tons of help requests. I truly appreciate your help.
*sidenote* I know nothing about Lua and this is all trial and error. Very satisfying when you figure things out on your own =)
Tastie: I'm not quite sure this is exactly what you want, and you can change the color thresholds if you want.
I also don't quite understand your choice to have the color be Power_Type defined at high levels, this is going to make it unreadable over the bar (we can make it simply not display if that is the goal).
Regarding the non-mana portion, I didn't do anything to it because I didn't see anything you wanted done there.
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
local per=Percent(cur,max)
if per>75 then
local r,g,b=PowerColor(UnitPowerType(unit))
return "|cff%02x%02x%02x%s || %s%%|r",r,g,b,Short(cur),per
elseif per>25 then
return "|cffffff00%s || %s%%|r",Short(cur),per
else
return "|cffff0000%s || %s%%|r",Short(cur),per
end
else
cur=Power(unit)
return cur
end
Tastie: I'm not quite sure this is exactly what you want, and you can change the color thresholds if you want.
I also don't quite understand your choice to have the color be Power_Type defined at high levels, this is going to make it unreadable over the bar (we can make it simply not display if that is the goal).
Regarding the non-mana portion, I didn't do anything to it because I didn't see anything you wanted done there.
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
local per=Percent(cur,max)
if per>75 then
local r,g,b=PowerColor(UnitPowerType(unit))
return "|cff%02x%02x%02x%s || %s%%|r",r,g,b,Short(cur),per
elseif per>25 then
return "|cffffff00%s || %s%%|r",Short(cur),per
else
return "|cffff0000%s || %s%%|r",Short(cur),per
end
else
cur=Power(unit)
return cur
end
Thinking about it more, maybe color wasn't the way to go. How can I modify my current code:
if UnitPowerType(unit) == 0 then
cur,max=Power(unit),MaxPower(unit)
return "%s | %s%%",cur,Percent(cur,max)
else
cur=Power(unit)
return cur
end
so that it simply looks like:
5.6k | 100%
I've tried adding Short(Power(unit)) but that doesn't seem to be working.
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
return "%s || %s%%",Short(cur),Percent(cur,max)
else
cur=Power(unit)
return cur
end
The problem with defining cur as Short(Power(unit)) is that you use cur to calculate a percent, and Short(##) isn't a number.
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
return "%s || %s%%",Short(cur),Percent(cur,max)
else
cur=Power(unit)
return cur
end
Whoops, I forgot ",true" within the Short() call. Why the default isn't true, i don't get.
use this:
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
return "%s || %s%%",Short(cur,true),Percent(cur,max)
else
cur=Power(unit)
return cur
end
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
return "%s || %s%%",Short(cur,true),Percent(cur,max)
else
cur=Power(unit)
return cur
end
my mana still displays as absolute. I can change Short(cur,true) to VeryShort(cur,true) but as my mana goes down, it still rounds up. So if I have a base mana of 5824 and it goes down to 4900, then my mana display will look like 5k rather than 4.9k. Basically what I am asking for is for my mana/power to mirror how I have my health displayed.
Sorry if I have been unclear . Having no LUA knowledge...customizing things are a tad difficult for me. And again, thanks a lot for your responses Hotan.
Tastie: I'm not seeing what you are saying, or it just doesn't work:
(a) both Short() and VeryShort() round to the nearest, rather than always rounding up.
(b) Short() doesn't touch numbers under 10k, you are going to have to circumvent the use of Short() if that is the goal. The reason for this situation is that Short() forces all numbers to be displayed in 4 characters (excluding ".") or less, and four digit numbers already do that.
I think this does what you want:
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
if cur <999 then
return "%s || %s%%",cur,Percent(cur,max)
elseif cur<9999 then
return "%.2fk || %s%%",cur/1000,Percent(cur,max)
else
return "%s || %s%%",Short(cur,true),Percent(cur,max)
end
else
cur=Power(unit)
return cur
end
This code basically is Short() with an added condition to force four digit numbers to be displayed as #.##k
This revereses the percent and absolute displays, as it is done in health, if this is what you want:
if UnitPowerType(unit) == 0 then
local cur,max=Power(unit),MaxPower(unit)
if cur <999 then
return"%s%% || %s",Percent(cur,max),cur
elseif cur<9999 then
return "%s%% || %.2fk",Percent(cur,max),cur/1000
else
return "%s%% || %s",Percent(cur,max),Short(cur,true)
end
else
cur=Power(unit)
return cur
end
Last edited by Hotan : 07/14/09 at 8:27 PM.
Reason: changed #.#k to #.##k