Thread Tools Display Modes
10-01-19, 03:37 AM   #1
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
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.
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.

Last edited by Aur0r4 : 10-01-19 at 08:10 AM.
  Reply With Quote
10-01-19, 05:05 AM   #2
PoliteKiwi
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Oct 2019
Posts: 2
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.
  Reply With Quote
10-02-19, 02:34 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-03-19, 05:14 AM   #4
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
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
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 ...
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.
  Reply With Quote
10-03-19, 02:42 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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()
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-05-19 at 02:20 PM.
  Reply With Quote
10-04-19, 11:27 AM   #6
Janede
A Kobold Labourer
 
Janede's Avatar
Join Date: Oct 2019
Posts: 1
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
  Reply With Quote
10-04-19, 11:53 AM   #7
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
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.
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.
  Reply With Quote
10-05-19, 02:34 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Janede View Post
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-19-19, 03:58 PM   #9
Aiue
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 7
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.

Last edited by Aiue : 10-19-19 at 06:59 PM.
  Reply With Quote

WoWInterface » Classic - AddOns, Compliations, Macros » Classic - AddOn Help/Support » need help with some LUA-Texts

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off