Tested and working with a few minor changes. If there are specific parts you don't understand, feel free to ask.
Edit: Guess I should refresh the page before replying. Leaving this here anyway, but feel free to disregard.
Code:
-- Disable ClamHolyPower if player is not a paladin.
if select(2, UnitClass("player")) ~= "PALADIN" then
return DisableAddOn("ClamHolyPower")
end
-------------------
-- CONFIGURATION --
-------------------
-- Background Configuration --
local bkr = 0 -- Background color: Red
local bkg = 0 -- Background color: Green
local bkb = 0 -- Background color: Blue
local bka = 0.60 -- Background alpha: 0 = Transparent 1 = Opaque
local hwe = false -- Hide the background when holy power is empty.
-- Indicator Configuration --
local itex = "Interface\\AddOns\\ClamHolyPower\\flatsmooth" -- Path pointing to the texture used for the indicator.
local ir = 1 -- Indicator color: Red
local ig = 0.8 -- Indicator color: Green
local ib = 0 -- Indicator color: Blue
-- Frame Configuration --
local fposx = -193.25 -- Frame position: X
local fposy = -243 -- Frame position: Y
local fwidth = 231 -- Frame width.
local fheight = 11 -- Frame height.
-----------------------
-- END CONFIGURATION --
-----------------------
-- Create ClamHolyPowerFrame
local f = CreateFrame("Frame", "ClamHolyPowerFrame", UIParent)
-- When the frame recieves an event, run the method on the frame whose
-- name matches the event name:
f:SetScript("OnEvent", function(self, event, ...) return self[event](self, event, ...) end)
-- Register for the event that fires once the initial loading process
-- has finished:
f:RegisterEvent("PLAYER_LOGIN")
function f:PLAYER_LOGIN()
-- These variables aren't needed outside of this initialization,
-- so keep them local to this function:
local maxhp = IsPlayerSpell(115675) and 5 or 3
self:SetFrameStrata("BACKGROUND")
self:SetPoint("CENTER", fposx, fposy)
self:SetWidth(fwidth)
self:SetHeight(fheight)
-- Create the background:
local bk = self:CreateTexture(nil, "BACKGROUND")
bk:SetTexture(bkr, bkg, bkb, bka)
bk:SetAllPoints(true)
self.background = bk
-- Create the indicators:
local iwidth = (fwidth - maxhp - 1) / maxhp
local iheight = fheight - 2
self.indicators = {}
for i = 1, maxhp do
local ind = self:CreateTexture(nil, "HIGH")
ind:SetTexture(itex)
-- Just anchor each indicator relative to the previous one:
if i == 1 then
ind:SetPoint("LEFT", f, 1, 0)
else
ind:SetPoint("LEFT", self.indicators[i-1], "RIGHT", 1, 0)
end
ind:SetWidth(iwidth)
ind:SetHeight(iheight)
ind:SetVertexColor(ir, ig, ib)
self.indicators[i] = ind
end
-- Don't need this anymore:
self:UnregisterEvent("PLAYER_LOGIN")
-- Only register UNIT_POWER for the player unit:
self:RegisterUnitEvent("UNIT_POWER", "player")
-- Update the power now:
self:UNIT_POWER("PLAYER_LOGIN", "player", "HOLY_POWER")
end
function f:UNIT_POWER(event, unit, powerType)
if powerType ~= "HOLY_POWER" then
-- Don't waste time updating if holy power didn't change.
return
end
local p = UnitPower("player", 9)
if hwe and p == 0 then
self:Hide()
else
self:Show()
for i = 1, #self.indicators do
if i > p then
self.indicators[i]:Hide()
else
self.indicators[i]:Show()
end
end
end
end