Thread Tools Display Modes
12-31-06, 01:22 PM   #1
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
Status bar gradient

im trying to make a health bar using a status bar, and what im wondering, is there some way to make a status bar thats all green when its at 100%, and all red at 0%, and everything in between would follow the gradient from green to red. (I hope you understand what im trying to say lol)
  Reply With Quote
12-31-06, 02:20 PM   #2
FOR
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 3
Originally Posted by Riraito
im trying to make a health bar using a status bar, and what im wondering, is there some way to make a status bar thats all green when its at 100%, and all red at 0%, and everything in between would follow the gradient from green to red. (I hope you understand what im trying to say lol)
ehr, you can set the color on a StatusBar via myStatusBar:SetStatusBarColor(r, g, b, a)

So, I guess that if you could figure out the appropriate values of r, g, and b based on your health percentage, you could do that.

HTH,
F.O.R.
  Reply With Quote
12-31-06, 04:50 PM   #3
Neuro
A Theradrim Guardian
 
Neuro's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 60
Actually, this wouldn't be too hard to do at all.

local f = CreateFrame("Frame", nil, UIParent);
f:RegisterEvent("UNIT_HEALTH");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:SetScript("OnEvent", function() DoHealthBarColor() end )

function DoHealthBarColor()
local h = UnitHealth("player") / UnitHealthMax("player")
PlayerFrameHealthBar:SetStatusBarColor(1-h, h, 0, 1);
end

That should work, barring any minor typos.
  Reply With Quote
12-31-06, 06:12 PM   #4
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
ah thanks neuro thats just what I was asking,

Edit: nvm im a dumbass lol

Last edited by Riraito : 12-31-06 at 07:59 PM.
  Reply With Quote
12-31-06, 06:48 PM   #5
Neuro
A Theradrim Guardian
 
Neuro's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2006
Posts: 60
That's just the formula for determining color. It's in r, g, b format, so (1-h, h, 0) means that your red goes up as your health goes down (1-h is the inverse of h), and h means your green goes down as your health goes down.

Actually, looking at that code, while it does exactly what you asked it to do, it's not very pretty. A better version might be:

local f = CreateFrame("Frame", nil, UIParent);
f:RegisterEvent("UNIT_HEALTH");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:SetScript("OnEvent", function() DoHealthBarColor() end )

function DoHealthBarColor()
local h = UnitHealth("player") / UnitHealthMax("player")
local r,g=math.min(1.5 - (h*1.5),1), math.min(1.5*h, 1);
PlayerFrameHealthBar:SetStatusBarColor(r, g, 0, 1);
end


The formula for determining the color, "local r,g=math.min(1.5 - (h*1.5),1), math.min(1.5*h, 1)", is a bit prettier.
  Reply With Quote
12-31-06, 08:02 PM   #6
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
lol about my second post, I was gonna ask what does 1-h mean because I thought it was a dash, then I realised it was a minus symbol so I figured it out, now im wondering, what makes the second one you posted better? I would have thought the first one was better because itsshorter and looks cleaner imo, but I trust your judgement better lol

Last edited by Riraito : 12-31-06 at 09:07 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Status bar gradient


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