View Single Post
10-24-20, 11:55 PM   #17
Chekoz9
A Kobold Labourer
Join Date: Oct 2020
Posts: 1
Pls Help

Ok so Idk anything about programming just been modifying the script using some of your suggestions and the error is still a thing plus 2 percentages are shown in the nameplates if you guys could help me solve it or pass the right script so I can copy and paste it I would appreciatte it.

This is the script that I got so far:

-- 06/22/2015 1.0.5 toc update for 6.2
-- 04/19/2015 1.0.4 fix for lua error when chat bubbles enabled
-- 02/24/2015 1.0.3 toc update for 6.1
-- 10/14/2014 1.0.2 6.0 patch
-- 05/20/2014 1.0.1 initial release

local frequency = 0.2 -- how frequently to look for new nameplates and update visible percents
local numChildren = 0 -- number of WorldFrame's children
local overlays = {} -- indexed by overlay frame added to each nameplate's statusBar

local frame = CreateFrame("Frame",nil,UIParent)
frame.timer = 0
frame.knownChildren = 0 -- number of WorldFrame's children that we know about

-- updates the percentOverlay text on the nameplate's statusbar
local function UpdatePercent(self)
local parent = self:GetParent()
local value = parent:GetValue()
local _,maxValue = parent:GetMinMaxValues()
if maxValue and value<maxValue then
self:SetText(format("%d%%",100*value/maxValue))
else
self:SetText("") -- blank if no relevant values or value is maxValue (100% life)
end
end

-- when a nameplate shows, add it to frame.statusBars
local function ShowPercent(self)
overlays[self.percentOverlay] = 1
end

-- when a nameplate hides, remove it from frame.statusBars
local function HidePercent(self)
overlays[self.percentOverlay] = nil
self.percentOverlay:SetText("") -- blank for when nameplate reused
end

local IsNameplate = function(unit)
if type(unit) ~= "string" then return false end
if ( string.match(unit,"nameplate") ~= "nameplate" and string.match(unit,"NamePlate") ~= "NamePlate" ) then
return false
else
return true
end
end


-- look for new nameplates that don't have a percent overlay and add one
function frame:ScanNameplates(...)
for i=1,select("#",...) do
local plate = select(i,...)
local name = plate:GetName()
if name and name:match("^NamePlate") then
-- the statusBar is the first child of the first child of the nameplate
local statusBar = plate:GetChildren():GetChildren()
if not statusBar.percentOverlay then
statusBar.percentOverlay = statusBar:CreateFontString(nil,"OVERLAY","GameFontHighlightSmall")
local percent = statusBar.percentOverlay
percent:SetPoint("RIGHT")
statusBar:HookScript("OnShow",HidePercent)
statusBar:HookScript("OnHide",HidePercent)
overlays[statusBar.percentOverlay] = 1 -- add new child to next update batch
end
end
end
end

function frame:OnUpdate(elapsed)
self.timer = self.timer + elapsed
if self.timer > frequency then
self.timer = 0
-- first look for any new nameplates (if WorldFrame has a new kid, it's likely a nameplate)
numChildren = WorldFrame:GetNumChildren()
if numChildren > self.knownChildren then
self.knownChildren = numChildren
self:ScanNameplates(WorldFrame:GetChildren())
end
-- next update percents for all visible nameplate statusBars
for overlay in pairs(overlays) do
UpdatePercent(overlay)
end
end
end
frame:SetScript("OnUpdate",frame.OnUpdate)

-- Add health percent text to (unprotected) nameplates (credit: nPlates by Grimsbain)
hooksecurefunc("CompactUnitFrame_UpdateStatusText", function(frame)
if frame:IsForbidden() or ( UnitIsFriend("player",frame.displayedUnit) and not UnitIsUnit(frame.displayedUnit,"player") ) then return end
if not frame.healthBar.percent then
frame.healthBar.percent = frame.healthBar:CreateFontString(nil,"OVERLAY")
frame.healthBar.percent:SetPoint("RIGHT",frame.healthBar)
frame.healthBar.percent:SetFont(STANDARD_TEXT_FONT,12,"OUTLINE")
end
local percentcalc = ceil((UnitHealth(frame.displayedUnit) / UnitHealthMax(frame.displayedUnit)) * 100)
frame.healthBar.percent:SetFormattedText("%d%%",percentcalc)
-- frame.healthBar.percent:Show()
end)
  Reply With Quote