Thread Tools Display Modes
08-07-09, 02:15 AM   #1
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Help with creating a health tag.

So, I've been unable to find any help regarding this for the last few days and I've not found it in any layout so far to take references from.

What I want is a tag that changes color (from green to red) based on the units health, I've tried a bit with oUF.ColorGradient but it has not worked out well for me. (i.e I've done something wrong.)

If anyone would be just as so kind to help me out with this, I'd appreciate it a lot.

Regards,
Rhiren.
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote
08-07-09, 02:24 AM   #2
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
Originally Posted by Wimpface View Post
So, I've been unable to find any help regarding this for the last few days and I've not found it in any layout so far to take references from.

What I want is a tag that changes color (from green to red) based on the units health, I've tried a bit with oUF.ColorGradient but it has not worked out well for me. (i.e I've done something wrong.)

If anyone would be just as so kind to help me out with this, I'd appreciate it a lot.

Regards,
Rhiren.
oUF_Freeb uses ColorGradient and you can glance at it here if it helps.
  Reply With Quote
08-07-09, 02:27 AM   #3
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Thanks, can't believe I overlooked it.

Cheers.
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote
08-07-09, 02:33 AM   #4
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
Originally Posted by Wimpface View Post
Thanks, can't believe I overlooked it.

Cheers.
Also, don't get confused in my updateHealth function. There are 2 different ColorGradients, r,g,b applies to text and x,y,z to the health bar.
  Reply With Quote
08-07-09, 02:37 AM   #5
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
EDIT: I added "self" into the function, and now I get a different error. I'll paste the code/error below here.

Code:
oUF.Tags['[rhealth]'] = function(self, unit)
	local min, max = UnitHealth(unit), UnitHealthMax(unit)
	
	local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
	if(max ~= 0) then
		r, g, b = self.ColorGradient(min/max, .69,.31,.31, .65,.63,.35, .33,.59,.33)
	end
	
	return status and status or min ~= max and ('%s'):format(shortVal(min), shortVal(max)) or max
end

oUF.TagEvents['[rhealth]'] = 'UNIT_HEALTH'
Code:
Message: Interface\AddOns\oUF_Rhiren\tags.lua:38: Usage: UnitHealth("unit")
Time: 08/07/09 10:53:01
Count: 1
Stack: [string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:18: in function <[string "Interface\FrameXML\BasicControls.xml:<Scrip..."]:4>
[C]: ?
[C]: in function `UnitHealth'
Interface\AddOns\oUF_Rhiren\tags.lua:38: in function `func'
Interface\AddOns\oUF\elements\tags.lua:305: in function `UpdateTag'
Interface\AddOns\oUF\elements\tags.lua:178: in function `func'
Interface\AddOns\oUF\ouf.lua:484: in function <Interface\AddOns\oUF\ouf.lua:479>
(tail call): ?

Locals: (*temporary) = nil
__________________
All I see is strobe lights blinding me in my hindsight.

Last edited by Wimpface : 08-07-09 at 02:55 AM.
  Reply With Quote
08-07-09, 02:53 AM   #6
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
change self to oUF.ColorGradient

Edit: your return status needs some work, but I don't know a fix off the top of my head. *sleepy*

Last edited by Freebaser : 08-07-09 at 02:57 AM.
  Reply With Quote
08-07-09, 02:56 AM   #7
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Originally Posted by Freebaser View Post
change self to oUF.ColorGradient
Cheers, however, it does not seem to do any coloring at all now but I don't get any errors. Could it be that I'm using a "short value" function?

Code:
oUF.Tags['[rhealth]'] = function(unit)
	local min, max = UnitHealth(unit), UnitHealthMax(unit)
	
	local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
	if(max ~= 0) then
		r, g, b = oUF.ColorGradient(min/max, .69,.31,.31, .65,.63,.35, .33,.59,.33)
	end
	
	return status and status or min ~= max and ('%s'):format(shortVal(min), shortVal(max)) or max
end
__________________
All I see is strobe lights blinding me in my hindsight.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Help with creating a health tag.


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