View Single Post
07-25-16, 05:20 AM   #22
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Same as j3rem1e.

I have been asking this few months ago and zork tried his best to enlighten me, but I was so stupid to understand his effort...

I was damn busy for last couple of months finishing my work and finally back here to solve this old problem.

Tried with haste's method:

Lua Code:
  1. Health:SetReverseFill(true)
  2. Health.PostUpdate = function(Health, unit, min, max)
  3.    Health:SetValue(max - Health:GetValue())
  4. end

as well as Monolit's method which I modified a bit to match my taste:
(BUT, I definitely left a contribution comment!)

Lua Code:
  1. A.CreateHealthBar = function(f, unit)
  2.     local Health;
  3.  
  4.     if unit == "player" or unit == "targettarget" then
  5.         Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  6.     elseif unit == "target" then
  7.         Health = A.ReverseStatusBar(f);
  8.         Health.PostUpdate = A.PostUpdateHealth;
  9.     end
  10.  
  11.     Health:SetFrameLevel(Health:GetFrameLevel() + 1);
  12.     Health:SetStatusBarTexture(HEALTH_BAR);
  13.     Health:SetStatusBarColor(0.85, 0.86, 0.84, 1);
  14.  
  15.     if unit == "player" then
  16.         Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1);
  17.         Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  18.     elseif unit == "target" then
  19.         Health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
  20.         Health:SetSize(f:GetWidth() - 12, f:GetHeight() - 12);
  21.     elseif unit == "targettarget" then
  22.         Health:SetPoint("TOP", f, "TOP", 0, -1);
  23.         Health:SetSize(f:GetWidth() - 22, f:GetHeight() - 12);
  24.     end
  25.  
  26.     Health.bg = Health:CreateTexture(nil, "BACKGROUND");
  27.     Health.bg:SetAllPoints(true);
  28.     Health.bg:SetTexture(BACKDROP);
  29.     Health.bg:SetVertexColor(0.08, 0.08, 0.08, 1);
  30.  
  31.     f.Health = Health;
  32.     f.Health.bg = Health.bg;
  33. end
  34.  
  35. -- Thanks to Monolit from WoWInterface for sharing this code!
  36. local StatusBarUpdaterOnUpdate;
  37. local StatusBarOnChanged;
  38. A.ReverseStatusBar = function(f, unit)
  39.     local statusbar = CreateFrame("Statusbar", f:GetName() .. "HealthBar", f);
  40.     statusbar.updater = CreateFrame("Frame", nil, statusbar);
  41.     statusbar.updater:Hide();
  42.     statusbar.updater:SetScript("OnUpdate", StatusBarUpdaterOnUpdate);
  43.  
  44.     statusbar:SetScript("OnSizeChanged", StatusBarOnChanged);
  45.     statusbar:SetScript("OnValueChanged", StatusBarOnChanged);
  46.     statusbar:SetScript("OnMinMaxChanged", StatusBarOnChanged);
  47.  
  48.     return statusbar;
  49. end
  50.  
  51. StatusBarUpdaterOnUpdate = function(updater)
  52.     updater:Hide();
  53.  
  54.     local b = updater:GetParent();
  55.  
  56.     local tex = b:GetStatusBarTexture();
  57.     tex:ClearAllPoints();
  58.     tex:SetPoint("BOTTOMRIGHT");
  59.     tex:SetPoint("TOPLEFT", b, "TOPRIGHT", (b:GetValue() / select(2, b:GetMinMaxValues()) - 1) * b:GetWidth(), 0);
  60.  
  61.     local d = select(2, b:GetMinMaxValues());
  62.  
  63.     local x;
  64.  
  65.     if d ~= 0 then
  66.         x = (b:GetValue() / (d - 1)) * b:GetWidth();
  67.     end
  68.  
  69.     tex:SetPoint("TOPLEFT", b, "TOPRIGHT", x, 0);
  70. end
  71.  
  72. StatusBarOnChanged = function(statusbar)
  73.     statusbar.updater:Show();
  74. end
  75.  
  76. A.PostUpdateHealth = function(statusbar, unit, min, max)
  77.     if UnitIsDeadOrGhost(unit) then
  78.         statusbar:SetValue(0);
  79.     end
  80. end

Unfortunately, those two approaches does not seem to work for me either...

Could we please get some help regarding this?

Thank you!

Last edited by Layback_ : 07-25-16 at 05:27 AM.
  Reply With Quote