Thread Tools Display Modes
11-16-11, 06:26 AM   #1
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Text "Heatlh bar"

Lets say I wanted a healthbar made completely out of text, and for every 10% it would add another letter, it doesn't have to be different, just one like this:

[++++++++++] 100%

[+] 10%

[+++] 30%
What is the founding principle of doing this? How would I be able to make a letter "repeat" with the proper variable?
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
11-16-11, 07:44 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Sounds like the following will help give you an idea.

http://www.wowpedia.org/API_strrep

eg.
string.rep(s, n)

health.rep("x",maxhealth/curhealth)

or something somewhat similar
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
11-16-11, 07:46 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Here's some code that would return the string you proposed.

lua Code:
  1. function GetHealthTextBar(unit,base,fmt,char)
  2.     local pcnt=UnitHealth(unit)/UnitHealthMax(unit);
  3.     return (fmt or "[%s] %.0f%%"):format((char or "="):rep(math.floor(pcnt*(base or 10))),pcnt*100);
  4. end

unit is required. base, format, and char are optional.
  • unit - UnitID of target to query health of.
  • base - Width of the status bar in chars when full.
    default: 10
  • format - Format string in which the status bar is constructed.
    The first argument is a repeated string consisting of the bar itself, the second is a float value representing the health percentage.
    default: "[%s] %.0f%%"
  • char - String to be repeated that makes up the text bar.
    default: "="
__________________
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 : 11-16-11 at 07:49 AM.
  Reply With Quote
11-16-11, 08:04 AM   #4
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
You know, honestly, that little amount you just wrote actually taught me a LOT of what I've been wondering about recently?

Thanks SOO much!
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
11-17-11, 04:53 AM   #5
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I suggest that you always have 10 +, Sth like

[++++++++++]

That way the bar does not jump all the time. But not sure if applying the text color to the format string of phantom is that easy to add. Here are the functions that may be needed.

lua Code:
  1. --calc hex color from rgb
  2.   local function RGBPercToHex(r, g, b)
  3.     r = r <= 1 and r >= 0 and r or 0
  4.     g = g <= 1 and g >= 0 and g or 0
  5.     b = b <= 1 and b >= 0 and b or 0
  6.     return string.format("%02x%02x%02x", r*255, g*255, b*255)
  7.   end
  8.  
  9.   --green col
  10.   "|c00"..RGBPercToHex(0,1,0).."+|r"
  11.   --gray col
  12.   "|c00"..RGBPercToHex(0.3,0.3,0.3).."+|r"
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 11-17-11 at 05:16 AM.
  Reply With Quote
11-17-11, 01:42 PM   #6
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
I was actually just about to ask about that today!

Reading my mind Zork!

Thanks a lot!
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
11-17-11, 01:52 PM   #7
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Hellz yeah

[♥♥♥♥♥♥♥♥]
  Reply With Quote
11-17-11, 02:50 PM   #8
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
This is what I came up with (this is in an openrdx script, so all functions are confined to that script only besides "text").

lua Code:
  1. function RGBPercToHex(r, g, b)
  2.     r = r <= 1 and r >= 0 and r or 0
  3.     g = g <= 1 and g >= 0 and g or 0
  4.     b = b <= 1 and b >= 0 and b or 0
  5.     return string.format("%02x%02x%02x", r*255, g*255, b*255)
  6. end
  7. function GetPlayerHealthBar()
  8.     local cpercent = unit:FracHealth() * 100;
  9.     local mpercent = unit:MissingHealth() / unit:MaxHealth() * 100 + 10
  10.     if cpercent <= 99 then
  11.         return ("[|c00"..RGBPercToHex(0,1,0).."%s|r|c00"..RGBPercToHex(0.3,0.3,0.3).."%s|r] %.0f%%"):format(("="):rep(math.floor(cpercent*(0.1))),("="):rep(math.floor(mpercent*(0.1))),cpercent);
  12.     else
  13.         return ("[%s] %.0f%%"):format(("="):rep(math.floor(cpercent*(0.1))),cpercent);
  14.     end
  15. end
  16. text = GetPlayerHealthBar();

Any suggestions or improvements anyone can see off-the-bat in that?

In action (muwahhaahhaha):

__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **

Last edited by unlimit : 11-17-11 at 03:27 PM.
  Reply With Quote
11-17-11, 04:20 PM   #9
Paolo242
An Aku'mai Servant
 
Paolo242's Avatar
Join Date: Jul 2010
Posts: 31
I'm too colorblind for that idea...

Isn't OUF_Hank along the lines of what you're looking for?

http://www.wowinterface.com/download...-oUF_Hank.html

Last edited by Paolo242 : 11-17-11 at 04:22 PM.
  Reply With Quote
11-17-11, 04:45 PM   #10
Buddie
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 14
I did something similar almost a year ago in ouf, I can post the (terrible) code if you want.


http://i.imgur.com/QNJar.jpg
http://i.imgur.com/CSoCk.jpg

Last edited by Buddie : 11-17-11 at 04:47 PM.
  Reply With Quote
11-17-11, 05:50 PM   #11
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
I like it a lot, Buddie! You should upload it as an oUF ;P I'm sure people would love that, and I would personally love to see your code!

I'm just making it for my own sick boredom, not really looking for other peoples though, Pablo242!
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
11-17-11, 05:53 PM   #12
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I would suggest, if a color code isn't variable, you shouldn't waste CPU time on a function call for it.

This would turn (0,1,0) to "|cff00ff00" and (0.3,0.3,0.3) to about "|cff4d4d4d".

lua Code:
  1. function GetHealthTextBar(unit,base,fmt,char)
  2.     local pcnt=UnitHealth(unit)/UnitHealthMax(unit);
  3.     return (fmt or "[%s] %3$.0f%%"):format(
  4.         (char or "="):rep(math.floor(pcnt*(base or 10)))
  5.         ,(char or "="):rep(math.ceil((1-pcnt)*(base or 10)))
  6.         ,pcnt*100
  7.     );
  8. end

This is a modified version so you could send it a colored format string to achieve the same effect.
Code:
GetHealthTextBar(unit,10,"[|cff00ff00%s|cff4d4d4d%s|r] %.0f%%","=");
The default format string changed to skip the second string argument, notice the added "3$" after the format escape char "%". This tells string.format() to select the 3rd argument directly, which allows the default to retain the old function.
__________________
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 : 11-17-11 at 05:55 PM.
  Reply With Quote
11-17-11, 06:12 PM   #13
unlimit
Lookin' Good
 
unlimit's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 484
Man, you people blow my mind sometimes. I hardly know what I'm doing, wish I could say I knew how to do it like you guys
__________________


kúdan: im playing pantheon
JRCapablanca: no youre not
** Pantheon has been Banned. **
  Reply With Quote
11-18-11, 05:44 AM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I was programming since I was a kid. Easily 20 years of experience there. The last 8 years was spent writing in Lua. And yes, that includes pre-WoW experience with Lua.
__________________
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 : 11-18-11 at 05:47 AM.
  Reply With Quote
11-18-11, 07:02 AM   #15
Buddie
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 14
Originally Posted by unlimit View Post
I like it a lot, Buddie! You should upload it as an oUF ;P I'm sure people would love that, and I would personally love to see your code!

I'm just making it for my own sick boredom, not really looking for other peoples though, Pablo242!
I don't think I could be bothered with cleaning it up, adding more features, maintaining it etc. It never worked how I wanted it to so I gave up.

http://pastebin.com/bU8CzPsU
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Text "Heatlh bar"


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