WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Classic - AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=179)
-   -   need help with some LUA-Texts (https://www.wowinterface.com/forums/showthread.php?t=57562)

Aur0r4 10-01-19 03:37 AM

need help with some LUA-Texts
 
Hello guys, for my Yulu UI Classic I need some help creating some LUA texts, because I can't do it myself.

The following is needed for PitBull Unit Frames:

1.)
HP in percent - with a colored gradient - 100% green - 50% yellow - 1% red (hide text when >99% cur HP)

2.)
Current HP | Maximum HP
Cur HP -> Green | Max HP -> dark green
| = white

3.)
Current mana/rage/energy | Maximum mana/rage/energy
| = white

Can someone with LUA experience help me create these three scripts?

Thank you very much.

PoliteKiwi 10-01-19 05:05 AM

It is entirely more difficult than you think. If you can't diy, then the end product is just going to be all someone else's work (judging by how you called it LUA and not Lua).

You can color text by encasing it with a color code...

"|cAARRGGBBTextHere|r"

This string reads, color RR GG BB AA (in hex) 'TextHere' then return to previous color (usually white aka |cFFFFFFFF). In most cases, your AA (alpha) will be FF.

So you can wrap pretty much any output text in the script with |c...|r and it should color correctly. That is unless they have it colored already and use string.format... then it's slightly more difficult for a newbie.

SDPhantom 10-02-19 02:34 PM

Here's how I usually handle the health gradient.
Code:

("|cff%02x%02x00"):format(math.ceil(math.max(math.min(2*(1-percent),1),0)*255),math.ceil(math.max(math.min(2*percent,1),0)*255));
Note: percent is a float value clamped between 0 and 1. This scales the percent up and clamps it afterward to produce |cffffff00 at 0.5 rather than |cff808000.

Aur0r4 10-03-19 05:14 AM

Thank you SDPhantom!
Sadly I get an error with your script. Are you using it in classic or retail?

edit: Just tested it for myself: Even in retail I get an error :confused:
In retail I'm using DogTag 3.0 for the texts like percentHP

Code:

[(~IsMaxHP ? ~Dead ? Outline PercentHP:Round:HPColor)]
Sadly DogTexts are not supported in Pitbull4 Classic :( ...

SDPhantom 10-03-19 02:42 PM

It's pure Lua code to get a UI color escape from a percentage value. Works fine on the live Lua demo.
I don't know anything about Pitbull4, never used it.

Edit: From the documentation on LuaTexts, this is the conversion from your DogTag3 script.
Code:

local cur,max=HP(unit),MaxHP(unit);
local r,g,b=HPColor(cur,max);
Outline();
return (cur>0 and cur<max) and "|cff%02x%02x%02x%.0f%%|r" or "",r,g,b,100*cur/max;

Edit: Fixed typo; corrected MaxHP()

Janede 10-04-19 11:27 AM

1)
Code:

local s = Status(unit)
if s then
  return s
end
local cur,max=HP(unit),MaxHP(unit);
if cur == max then
 Alpha(0)
end
local r,g,b=HPColor(cur,max);
  return "|cff%02x%02x%02x%.0f%%|r" or "",r,g,b,100*cur/max;

The gradient is basically from SDPhantom's second post, except that HPMax has to be called MaxHP.

2)
Code:

local s = Status(unit)
if s then
  return s
end
return "|cff00ff00%s|r|||cff006400%s",HP(unit),MaxHP(unit)

3)
Code:

local _,power_name = UnitPowerType(unit)
local r,g,b = PowerColor(power_name)
local max = MaxPower(unit)
if max > 0 then
  return "|cff%02x%02x%02x%s|r | |cff%02x%02x%02x%s",r,g,b,Short(Power(unit),true),r,g,b,Short(max,true)
end

There you go :)

Aur0r4 10-04-19 11:53 AM

Love is when your girlfriend sits down all day long and gets to grips with Lua just because you can't handle it yourself. <3

Thanks, honey.

SDPhantom 10-05-19 02:34 PM

Quote:

Originally Posted by Janede (Post 334147)
Code:

return "|cff%02x%02x%02x%.0f%%|r" or "",r,g,b,100*cur/max;

Since you split out the special handling for max HP, the highlighted section is no longer necessary.
The reason it was there in the first place was taking advantage of Lua's behavior of its logic operators to create an inline conditional statement. With the condition removed, the false-side return is just extra baggage.

Note: If you want to try this for yourself later, keep in mind the true-side return has to result in a true evaluation as well, or it'll fall through and give the false-side return instead.

Aiue 10-19-19 03:58 PM

I may be a bit late to the party, but quite a while back, I created a library for what I believe is the very purpose here: LibPrism. Only have it on WowAce at the moment, though. Should probably do something about that.

Edit: Will show up on WoWInterface as well, once approved. Assuming, of course, it does not get rejected. Which I would find odd, but I suppose it could still happen regardless.

Edit 2: Just realized I uploaded the wrong package. It has since been repackaged with a fix for RGB gradients. Will reupload a proper one once I'm able.

Edit 3: Now on WoWInterface. Packager is creating a fresh package as I write this. Unless something goes wrong, it should be uploaded shortly.


All times are GMT -6. The time now is 11:01 AM.

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