This is a very simple mod that shows your health/mana, target health and pet health in bars in the middle of the screen:
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.