Hey guys, Just need a little bit of help here i have a target health bar and a player health bar, Currently the Player health bar is filled out and working as intended.. but the Target bar is not.. Right now its just visible and Does not fill in.. Its just an empty box.. Is anyone able to explain to me how to add in the target frame..
Picture to explain what i mean.. I actually have no idea how to remove the default UI, if someone could help with that, it would also be exteremly helpful!
Here is my current Healthbar code.. If you think something could be change to make this more optimal please let me know how i can change things..
Code:
function CreateHealthbar(unit)
local bar = CreateFrame('StatusBar', nil, UIParent)
bar:SetMovable(true)
bar:EnableMouse(true)
bar:RegisterForDrag("LeftButton")
bar:SetScript("OnDragStart", bar.StartMoving)
bar:SetScript("OnDragStop", bar.StopMovingOrSizing)
bar:SetPoint('CENTER')
bar.unit = unit -- Variable for the unitID to watch so we only have to change it in one location
-- Style it
bar:SetSize(200, 23)
bar:SetBackdrop({bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]]})
bar:SetStatusBarTexture([[Interface\TARGETINGFRAME\UI-StatusBar]], 'ARTWORK') --Background image
bar:SetOrientation('HORIZONTAL')
bar:SetBackdropColor(144/255, 47/255, 223/255, 1)
local fill = bar:GetStatusBarTexture()
fill:SetVertexColor(0.0,0.3,0.0)
local spark = bar:CreateTexture(nil, 'ARTWORK', nil, 3)
spark:SetTexture([[Interface\CastingBar\UI-CastingBar-Spark]]) -- Image at the end of the Healthbar to specify where current health..
spark:SetBlendMode('ADD')
spark:SetPoint('CENTER', fill, 'RIGHT')
spark:SetSize(8, 23)
--Overlay, This is needed in order to add a border to the health bar
local overlay = CreateFrame('frame', nil, bar)
overlay:SetAllPoints()
local border = overlay:CreateTexture(nil, 'OVERLAY', nil, 2)
border:SetPoint('CENTER')
border:SetWidth(bar:GetWidth()) -- Add +# past () to make it larger
border:SetHeight(bar:GetHeight()) -- ^
border:SetTexture([[Interface\AddOns\WoWUI\Background\NaTUI_HealthFrame]])
bar.border = border
bar:SetScript('OnEvent', function(self, event, ...)
if event == 'UNIT_MAXHEALTH' then
self:SetMinMaxValues(0, UnitHealthMax(self.unit)) -- Update max value for the bar
elseif event == 'UNIT_HEALTH' or event == 'UNIT_HEALTH_FREQUENT' then
self:SetValue(UnitHealth(self.unit)) -- Update current value for the bar to reflect our health
elseif event == 'PLAYER_ENTERING_WORLD' then -- Update everything after a loading screen
self:SetMinMaxValues(0, UnitHealthMax(self.unit))
self:SetValue(UnitHealth(self.unit))
end
end)
-- Register events for the unit we're interested in, creates the update of the Health bar
bar:RegisterUnitEvent('UNIT_MAXHEALTH', bar.unit)
bar:RegisterUnitEvent('UNIT_HEALTH', bar.unit)
bar:RegisterUnitEvent('UNIT_HEALTH_FREQUENT', bar.unit)
bar:RegisterEvent('PLAYER_ENTERING_WORLD')
-- Add some text
local pctText = bar:CreateFontString(nil, 'OVERLAY')
pctText:SetFont('Fonts\\FRIZQT__.ttf', 10, "THINOUTLINE")
pctText:SetPoint('LEFT', bar, 'LEFT', 2, 0)
pctText:SetTextColor(1, 1, 1)
pctText:SetShadowOffset(1, -1)
local maxText = bar:CreateFontString(nil, 'OVERLAY')
maxText:SetFont('Fonts\\FRIZQT__.ttf', 10, "THINOUTLINE")
maxText:SetPoint('LEFT', border, 'RIGHT', -35, 0)
maxText:SetTextColor(1, 1, 1)
maxText:SetShadowOffset(1, -1)
local name = bar:CreateFontString(nil, 'OVERLAY')
name:SetFont('Fonts\\FRIZQT__.ttf', 10, "THINOUTLINE")
name:SetPoint('CENTER', border, 2, 0)
name:SetTextColor(1, 1, 1)
name:SetShadowOffset(1, -1)
--sets player name in health bar
local PlayerName = UnitName(bar.unit)
name:SetText(PlayerName)
--Update text when our value changes
local function UpdateText(self) -- Set percentage and maxhealth text
local currentHealth, maxHealth = UnitHealth(self.unit), UnitHealthMax(self.unit)
pctText:SetFormattedText('%d%%', ceil(100 * currentHealth / maxHealth))
maxText:SetText(AbbreviateLargeNumbers(maxHealth))
end
bar:SetScript('OnValueChanged', UpdateText) -- Keeps the text on the screen updated.
bar:SetScript('OnMinMaxChanged', UpdateText)
end
local PlayerBar = CreateHealthbar('Player')
local TargetBar = CreateHealthbar('Target')