View Single Post
05-24-18, 07:19 PM   #2
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
That should do it, up to you to check more thoroughly to see if using SetStatusBarColor on nameplates doesn't taint anything in a bad way though (and to check whether it doesn't leave random other nameplates colored wrong, but it shouldn't.)

lua Code:
  1. hooksecurefunc("CompactUnitFrame_UpdateHealth", function(frame)
  2.     if frame.optionTable.colorNameBySelection and not frame:IsForbidden() then
  3.         local healthPercentage = ceil((UnitHealth(frame.displayedUnit) / UnitHealthMax(frame.displayedUnit) * 100))
  4.        
  5.         if C_NamePlate.GetNamePlateForUnit(frame.unit) == C_NamePlate.GetNamePlateForUnit("player") then
  6.             if healthPercentage == 100 then
  7.                 frame.healthBar:SetStatusBarColor(0, 1, 0)
  8.             elseif healthPercentage < 100 and healthPercentage >= 75 then
  9.                 frame.healthBar:SetStatusBarColor(0.6, 0.8, 0.19)
  10.             elseif healthPercentage < 75 and healthPercentage >= 50 then
  11.                 frame.healthBar:SetStatusBarColor(1, 1, 0)
  12.             elseif healthPercentage < 50 and healthPercentage >= 25 then
  13.                 frame.healthBar:SetStatusBarColor(1, 0.64, 0)
  14.             elseif healthPercentage < 25 then
  15.                 frame.healthBar:SetStatusBarColor(1, 0, 0)
  16.             end
  17.         end
  18.     end
  19. end)

Hacky, but eh. Not like that other script was any better.

Last edited by Ammako : 05-24-18 at 07:22 PM.
  Reply With Quote