Thread Tools Display Modes
10-06-09, 06:38 AM   #1
Arcage
A Murloc Raider
Join Date: Oct 2008
Posts: 6
Orb colour change with health

Hi Guys,

I'm sry if this has been covered, I've just spend close to 2hrs scowering through pages of code and replies.

Is there a way to make the health colour change with the values (in my case it would be the orb colour (rothui)).
Meaning at 100 = class colour, 75 = yellow, 50 = orange, 25 = red (prehaps changing the animation/background texture). Ideally with a smooth transition bewteen colours.

I saw a few posts talking about min/max health, though being new to Lua code I'm not sure they were referring to this or more the text colour.
I get in the situation when multimob grinding, my health gets to 25% and I havent even noticed because it;'s still the same colour, and the swirl animation tends to hide somewhat the empty orb.

If I'm not in the right area, please let me know.

Keep up the great work.
  Reply With Quote
10-06-09, 07:37 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This can be done.

Adjust this function with a color calculation: d3o2_updatePlayerHealth

Fully OK (100%) = green color.
Green color is in RGB = 0,1,0

Nearly dead = red color.
Red color is in RGB = 1,0,0

Thus:
Code:
    local calc_perc = min/max
    local calc_red
    local calc_green
    
    -- 100% = 0,1,0
    -- 75%  = 0.5,1,0
    -- 50%  = 1,1,0
    -- 25%  = 1,0.5,0
    -- 0%   = 1,0,0
    
    if calc_perc >= 0.5 then
      calc_green = 1
    else
      calc_green = calc_perc*2
    end
    
    if calc_perc <= 0.5 then
      calc_red = 1
    else
      calc_red = (1-calc_perc)*2
    end   
Now lets apply the color to the orb:
Code:
--colorize the orb filling
self.Health.Filling:SetVertexColor(calc_red,calc_green,0,1)
--add color to the galaxies aswell
self.gal1:SetVertexColor(calc_red,calc_green,0,1)
self.gal2:SetVertexColor(calc_red,calc_green,0,1)
self.gal3:SetVertexColor(calc_red,calc_green,0,1)
Final function could look like:

Code:
  --update player health func
  local function d3o2_updatePlayerHealth(self, event, unit, bar, min, max)
    local d = floor(min/max*100)
    self.Health.Filling:SetHeight((min / max) * self.Health:GetWidth())
    self.Health.Filling:SetTexCoord(0,1,  math.abs(min / max - 1),1)
    if useglow == 1 then
      self.pm1:SetAlpha((min/max)/fog_smoother)
      self.pm2:SetAlpha((min/max)/fog_smoother)
    end
    if usegalaxy == 1 then
      self.gal1:SetAlpha(min/max)
      self.gal2:SetAlpha(min/max)
      self.gal3:SetAlpha(min/max)
    end
    if d <= 25 and min > 1 then
      self.LowHP:Show()
    else
      self.LowHP:Hide()
    end
    
    local calc_perc = min/max
    local calc_red
    local calc_green
    
    -- 100% = 0,1,0
    -- 75%  = 0.5,1,0
    -- 50%  = 1,1,0
    -- 25%  = 1,0.5,0
    -- 0%   = 1,0,0
    
    if calc_perc >= 0.5 then
      calc_green = 1
    else
      calc_green = calc_perc*2
    end
    
    if calc_perc <= 0.5 then
      calc_red = 1
    else
      calc_red = (1-calc_perc)*2
    end    
    
    --colorize the orb filling
    self.Health.Filling:SetVertexColor(calc_red,calc_green,0,1)
    --add color to the galaxies aswell
    self.gal1:SetVertexColor(calc_red,calc_green,0,1)
    self.gal2:SetVertexColor(calc_red,calc_green,0,1)
    self.gal3:SetVertexColor(calc_red,calc_green,0,1)
    
  end
__________________
| 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 : 10-06-09 at 07:58 AM.
  Reply With Quote
10-06-09, 08:51 AM   #3
Arcage
A Murloc Raider
Join Date: Oct 2008
Posts: 6
Tyvm for the quick response zork.

with my limited (rapidly increasing ^^ ) knowledge of lua, would I be correct in thinking:

Code:
    local calc_perc = min/max
    local calc_red
    local calc_green
    
    -- 100% = 0
    -- 75%  = 0.5,1,0
    -- 50%  = 1,1,0
    -- 25%  = 1,0.5,0
    -- 0%   = 1,0,0
    
    if calc_perc >= 0.5 then
      calc_green = 1
    else
      calc_green = calc_perc*2
    end
    
    if calc_perc <= 0.5 then
      calc_red = 1
    else
      calc_red = (1-calc_perc)*2
    end
would make the default (full) colour the class colour, based on the
Code:
  -- healthcolor defines what healthcolor will be used
  -- 0 = class color, 1 = red, 2 = green, 3 = blue, 4 = yellow, 5 = runic
  local healthcolor = 0
arguement mentioned eariler in the code, or does this addition require you to use the RGB code sequence?
I'm ok with green as default colour tbh, just wondering if this code still pulls in rules from previous lines or it's a independant cmd.

Also at 25% would it be asking for trouble to add a cmd to lighten to glow of the orb, to make it more promenent.
using the
Code:
local fog_smoother = 1
rule.

Hope you understand what i mean, as I dont know the all the lingo.

Appreciate your patience and help.

for the moment I'll try the above code you have supplied once I get home, and see how it looks.

EDIT: Just looking at some RGB values, and it seems the ones in the code are a lot more simple than other RGB codes I've seen: Example

Just to confirm, the RGB in this code is based on the opacity for each colour?
0 = not visible 0.25 = 25% opacity of that colour for example?

cheers.

Last edited by Arcage : 10-06-09 at 09:08 AM.
  Reply With Quote
10-06-09, 09:14 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
You only need to adjust the UpdatePlayerHealth function. (Replace it with the one I posted)
This function is called each time the health of the player changes.

Other values will become obsolete, especially those that are set at startup.
The only thing that should be adjusted is the initial Healthcolor value at startup.

RGB in the real world is from 0 to 255. In WoW its from 0 to 1 or for you, from 0/255 to 255/255.

Just try my function, it should work.

My healhcolor value in my config is just an index number that is used to find the correct line in the orb-table. It has nothing to do with color values. But the color value inside that line on the table does.

example:
Code:
  local orbtab = {
    [0] = {r = player_class_color.r*0.8, g = player_class_color.g*0.8,   b = player_class_color.b*0.8, scale = 0.9, z = -12, x = -0.5, y = -0.8, anim = "SPELLS\WhiteRadiationFog.m2"}, -- class color
    [1] = {r = 0.8, g = 0, b = 0, scale = 0.8, z = -12, x = 0.8, y = -1.7, anim = "SPELLS\\RedRadiationFog.m2"}, -- red
    [2] = {r = 0.2, g = 0.8, b = 0, scale = 0.75, z = -12, x = 0, y = -1.1, anim = "SPELLS\\GreenRadiationFog.m2"}, -- green
    [3] = {r = 0, g = 0.35,   b = 0.9, scale = 0.75, z = -12, x = 1.2, y = -1, anim = "SPELLS\\BlueRadiationFog.m2"}, -- blue
    [4] = {r = 0.9, g = 0.7, b = 0.1, scale = 0.75, z = -12, x = -0.3, y = -1.2, anim = "SPELLS\\OrangeRadiationFog.m2"}, -- yellow
    [5] = {r = 0.1, g = 0.8,   b = 0.7, scale = 0.9, z = -12, x = -0.5, y = -0.8, anim = "SPELLS\\WhiteRadiationFog.m2"}, -- runic
  }
That color value for green should be 0,1,0 (RGB) for what you are looking to do and healthcolor should be set to 2 (healthcolor = 2).
__________________
| 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 : 10-06-09 at 09:20 AM.
  Reply With Quote
10-06-09, 11:55 AM   #5
Arcage
A Murloc Raider
Join Date: Oct 2008
Posts: 6
Hi Zork,

I tried this and it looks sweet tbh, thank you.
though it's created a problem.

I'll detail what I did, as it's probably my fault.

I had both rBottomBarStyler, and roth IU, not rly knowing any better (cause RBBS has /cmds that seemed easier to work with.

As this code didnt work at first, I realised there is probably a conflict there.

I deleted RBBS addon, and set local use_rbottombarstyler = 0 (as it was originally)

With code added, I reloaded to find I now have a sexy green health orb that changes colour as it depletes, and also glows red under 25% (nice touch btw).

although I have no mana orb now. I have the blue orb yes, but it's not registering my mana value at all, so there is no text, and stays full when I use mana.

it's probably something daft, but staring at the code isnt helping, and as I didnt change anything in the "power" part of the code, I cant see where this issue lies..

Any help would be appreciated.

cheers

EDIT:

oUF_D3Orbs\oUF_D3Orbs.lua:294: attempt to call method 'SetVertexColor' (a nil value)
oUF-1.3.21\elements\health.lua:98: in function `func'
oUF-1.3.21\ouf.lua:506: in function <Interface\AddOns\oUF\ouf.lua:501>
(tail call): ?:

i pulled this error out of it. not sure if it's related (though I tend to think so).

Last edited by Arcage : 10-06-09 at 12:08 PM. Reason: additional info
  Reply With Quote
10-06-09, 12:46 PM   #6
Arcage
A Murloc Raider
Join Date: Oct 2008
Posts: 6
update:

I replaced the code back to what it was:
Code:
  --update player health func
  local function d3o2_updatePlayerHealth(self, event, unit, bar, min, max)
    local d = floor(min/max*100)
    self.Health.Filling:SetHeight((min / max) * self.Health:GetWidth())
    self.Health.Filling:SetTexCoord(0,1,  math.abs(min / max - 1),1)
    if useglow == 1 then
      self.pm1:SetAlpha((min/max)/fog_smoother)
      self.pm2:SetAlpha((min/max)/fog_smoother)
    end
    if usegalaxy == 1 then
      self.gal1:SetAlpha(min/max)
      self.gal2:SetAlpha(min/max)
      self.gal3:SetAlpha(min/max)
    end
    if d <= 25 and min > 1 then
      self.LowHP:Show()
    else
      self.LowHP:Hide()
    end
  end
and it's back to normal.

Question is..what part of the addition is causing this to happen?

I did try adding the last "end" cmd, but this just removed the orbs all together.

I'll keep playing and let you know if I figure it out...

best way to learn eh ^^
  Reply With Quote
10-07-09, 03:10 AM   #7
Arcage
A Murloc Raider
Join Date: Oct 2008
Posts: 6
well with no success as yet, I'll checking the code in SciTE (not that I rly know what I'm doing).

It's odd that this addition would affect the mana values.

any Ideas are appreciated.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Orb colour change with health

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