Thread Tools Display Modes
12-01-10, 08:18 PM   #1
Vranx
A Flamescale Wyrmkin
 
Vranx's Avatar
Join Date: May 2008
Posts: 101
MiniHealthbar

This is a very simple mod that shows your health/mana, target health and pet health in bars in the middle of the screen:
http://wow.curse.com/downloads/wow-a...iheathbar.aspx
It no longer works with the current patch and I haven't seen any oUF huds I can use either. It is a very small mod, can anyone tell me what is wrong with it?

Code:
function SetMinihealthbarColor(tex, hp, colorSet)
	local r,g,b;
	if hp > 0.75 then
		r = colorSet[1];
		g = colorSet[2];
		b = colorSet[3];
	elseif hp > 0.5 then
		local f = ((hp - 0.5) * 4);
		r = colorSet[1] * f + colorSet[4] * (1 - f);
		g = colorSet[2] * f + colorSet[5] * (1 - f);
		b = colorSet[3] * f + colorSet[6] * (1 - f);
	elseif hp > 0.25 then
		local f = ((hp - 0.25) * 4);
		r = colorSet[4] * f + colorSet[7] * (1 - f);
		g = colorSet[5] * f + colorSet[8] * (1 - f);
		b = colorSet[6] * f + colorSet[9] * (1 - f);
	else
		r = colorSet[7];
		g = colorSet[8];
		b = colorSet[9];
	end
	tex:SetGradient("VERTICAL", r,g,b, r,g,b);
end

function SetMinihealthbarText(text, value)
	if value > 0.99 then
		text:SetText("--")
	elseif value < 0.01 then
		text:SetText("")
	else
		text:SetText(string.format("%i", value * 100))
	end
end

local function HasNormalPowerLevel()
	local type = UnitPowerType("player");
	if type == 0 then --Mana
		if UnitPower("player") < UnitPowerMax("player") then return false; end
	elseif type == 1 then --Rage
		if UnitPower("player") > 0 then return false; end
	elseif type == 0 then --Energy
		if UnitPower("player") < UnitPowerMax("player") then return false; end
	elseif type == 6 then --Runic Power
		if UnitPower("player") > 0 then return false; end
	end
	return true;
end

local function UpdateBar(name, value, max, colorSet, absNum)
	if absNum == nil then absNum = false; end
	local frame = getglobal(name);
	local tex = getglobal(name .. "Texture");
	local text = getglobal(name .. "Text");
	local per = value / max;
	if value == 0 then
		frame:Hide();
	else
		frame:Show();
		SetMinihealthbarColor(tex, per, colorSet);
		tex:SetHeight(frame:GetHeight() * per);
		if absNum then
			SetMinihealthbarText(text, value/100);
		else
			SetMinihealthbarText(text, per);
		end
	end
end

local AllyColorSet = {0,1,0, 1,1,0, 1,0,0};
local EnemyColorSet = {1,0,0, 1,1,0, 0,1,0};
local PowerColorSets = {
	{0,0,1, 0,0,1, 0,0,1}, --Mana
	{1,0,0, 1,0,0, 1,0,0}, --Rage
	{1,1,1, 1,1,1, 1,1,1}, --Focus...
	{0,1,1, 0,1,1, 0,1,1}, --Energy
	{1,1,1, 1,1,1, 1,1,1}, --Happyness...
	{1,1,1, 1,1,1, 1,1,1}, --Runes...
	{0.5,0.5,1, 0.5,0.5,1, 0.5,0.5,1}, --Runic Power
	{1,1,1, 1,1,1, 1,1,1}} --???...
	

function UpdateMiniHealthBar()
	if UnitHealth("player") < UnitHealthMax("player") or not HasNormalPowerLevel() then
		local type = UnitPowerType("player");
		MiniHealthbarFrame:Show();
		UpdateBar("MiniHealthbarSelf", UnitHealth("player"), UnitHealthMax("player"), AllyColorSet);
		UpdateBar("MiniHealthbarPet", UnitHealth("pet"), UnitHealthMax("pet"), AllyColorSet);
		if UnitIsEnemy("player", "target") then
			UpdateBar("MiniHealthbarTarget", UnitHealth("target"), UnitHealthMax("target"), EnemyColorSet);
		else
			UpdateBar("MiniHealthbarTarget", UnitHealth("target"), UnitHealthMax("target"), AllyColorSet);
		end
		UpdateBar("MiniHealthbarPrimPower", UnitPower("player"), UnitPowerMax("player"), PowerColorSets[type+1], type == 3);
		
		if type ~= 0 and UnitPowerMax("player", 0) > 0 then
			--Has Mana as well as other power (rage/energy for druid)
			UpdateBar("MiniHealthbarSecPower", UnitPower("player", 0), UnitPowerMax("player", 0), PowerColorSets[1]);
		else
			MiniHealthbarSecPower:Hide();
		end
		
		local deathCount = 0;
		--[[ deathCount is broken, so disabled.
		if UnitIsDeadOrGhost("player") then deathCount = deathCount + 1; end
		for i = 1, 4 do
			if UnitIsDeadOrGhost("party" .. i) then deathCount = deathCount + 1; end
		end
		for i = 1, 40 do
			if UnitIsDeadOrGhost("raid" .. i) then deathCount = deathCount + 1; end
		end
		--]]
		
		if deathCount > 0 then
			local bd = MiniHealthbarDeathCounter:GetBackdrop();
			MiniHealthbarDeathCounter:SetHeight(bd.tileSize * deathCount);
			MiniHealthbarDeathCounter:Show();
		else
			MiniHealthbarDeathCounter:Hide();
		end
	else
		MiniHealthbarFrame:Hide();
	end
end

function MiniHealthbarFrame_OnEvent()
	UpdateMiniHealthBar();
end

function MiniHealthbarFrame_OnLoad()
	this:RegisterEvent("UNIT_HEALTH"); 
	this:RegisterEvent("UNIT_MANA"); 
	this:RegisterEvent("UNIT_RAGE"); 
	this:RegisterEvent("UNIT_ENERGY");
	this:RegisterEvent("UNIT_RUNIC_POWER");
	this:RegisterEvent("PLAYER_TARGET_CHANGED");
	UpdateMiniHealthBar();
end
Any help would be appreciated.
  Reply With Quote
12-01-10, 08:57 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You seem to have not posted the XML, but it's got the global "this" issue and the UnitPowerType() function has changed.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-01-10, 09:52 PM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,366
Try this.

Fixed a couple obvious bugs I saw apart from API,
but it won't support alternate powertypes (holy power, soul shards, eclipse etc) without some extra work.

Added hunters at least and should work for the rest like before.

Edit:
Btw now that I have your ear you may want to update the author on Power Auras Classic.
I was developing it for about a year (wow 2.4 to 3)
But it's been at least as long since Smacker has had it with major code changes (basically a rewrite) and features.
Attached Files
File Type: zip MiniHealthbar-1.0-40000.zip (2.7 KB, 880 views)

Last edited by Dridzt : 12-01-10 at 10:01 PM.
  Reply With Quote
12-01-10, 10:20 PM   #4
Vranx
A Flamescale Wyrmkin
 
Vranx's Avatar
Join Date: May 2008
Posts: 101
I was hoping all the errors would be in the Lua file.

TYVM Dridzt. I show the holy power, etc on my oUF_Neav frames, this is perfect for just seeing minimal info center screen. Will change the author name tomorrow.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » MiniHealthbar


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