PHP код:
--Made By Frugle
local OnTargetChange = CreateFrame("FRAME", "OnTargetChange")
OnTargetChange:RegisterEvent("PLAYER_TARGET_CHANGED")
local function targetHandler(self, event, ...)
UpdateHealth("target", "t")
UpdateMana("target", "t")
end
OnTargetChange:SetScript("OnEvent", targetHandler)
local hpHandlerFrame = CreateFrame("FRAME", "hpHandlerFrame")
hpHandlerFrame:RegisterEvent("UNIT_HEALTH")
local function hpHandler(self, event, ...)
local unitid = ...
if unitid == "target" then
UpdateHealth(unitid, "t")
end
if unitid == "player" then
UpdateHealth(unitid, "s")
end
end
hpHandlerFrame:SetScript("OnEvent", hpHandler)
local powerHandlerFrame = CreateFrame("FRAME", "energyHandlerFrame")
powerHandlerFrame:RegisterEvent("UNIT_MANA")
powerHandlerFrame:RegisterEvent("UNIT_RAGE")
powerHandlerFrame:RegisterEvent("UNIT_FOCUS")
powerHandlerFrame:RegisterEvent("UNIT_ENERGY")
powerHandlerFrame:RegisterEvent("UNIT_RUNIC_POWER")
local function powerHandler(self, event, ...)
local unitid = ...
if unitid == "target" then
UpdateMana(unitid, "t")
end
if unitid == "player" then
UpdateMana(unitid, "s")
end
end
powerHandlerFrame:SetScript("OnEvent", powerHandler)
function UpdateHealth(unitid, who)
if who == "t" then
if SimplePercent["tarhp"] == false then
ChangeFrame(hpFrame, false)
return
end
if not hpFrame:IsShown() then return end
local hp = UnitHealth(unitid)
local maxhp = UnitHealthMax(unitid)
local finalhp
if hp == 0 or UnitIsDeadOrGhost(unitid) then
perhp = 0
finalhp = 0
elseif hp == maxhp then
finalhp = 100
else
local floatper = hp / maxhp
local perhp = floatper * 100
finalhp = math.ceil(perhp)
end
if hpFrame.OldFinalHp == finalhp then return end
hpFrame.OldFinalHp = finalhp
local finalhpstring = tostring(finalhp) .. "%"
hpFrame:SetText(finalhpstring)
local stringwidth = hpFrame:GetStringWidth(finalhpstring)
hpFrame.PointXos = (stringwidth) * -1
hpFrame:SetPoint("LEFT", TargetFrame, "LEFT", hpFrame.PointXos, hpFrame.PointYos)
elseif who == "s" then
if SimplePercent["plyhp"] == false then
ChangeFrame(selfhpFrame, false)
return
end
if not selfhpFrame:IsShown() then return end
local hp = UnitHealth(unitid)
local maxhp = UnitHealthMax(unitid)
local finalhp
if hp == 0 or UnitIsDeadOrGhost(unitid) then
perhp = 0
finalhp = 0
elseif hp == maxhp then
finalhp = 100
else
local floatper = hp / maxhp
local perhp = floatper * 100
finalhp = math.ceil(perhp)
end
if selfhpFrame.OldFinalHp == finalhp then return end
selfhpFrame.OldFinalHp = finalhp
local finalhpstring = tostring(finalhp) .. "%"
selfhpFrame:SetText(finalhpstring)
local stringwidth = selfhpFrame:GetStringWidth(finalhpstring)
selfhpFrame.PointXos = 0
selfhpFrame:SetPoint("LEFT", PlayerFrame, "RIGHT", selfhpFrame.PointXos, selfhpFrame.PointYos)
end
end
function UpdateMana(unitid, who)
if who == "t" then
if SimplePercent["tarmana"] == false then
ChangeFrame(manaFrame, false)
return
end
if not manaFrame:IsShown() then return end
local mana = UnitPower(unitid)
local maxmana = UnitPowerMax(unitid)
local finalmana
if mana == 0 or UnitIsDeadOrGhost(unitid) then
permana = 0
finalmana = 0
elseif mana == maxmana then
finalmana = 100
elseif maxmana == 100 then
finalmana = mana
else
local floatper = mana / maxmana
local permana = floatper * 100
finalmana = math.ceil(permana)
end
if manaFrame.OldFinalHp == finalmana then return end
manaFrame.OldFinalHp = finalmana
local finalmanastring = tostring(finalmana) .. "%"
manaFrame:SetText(finalmanastring)
local stringwidth = manaFrame:GetStringWidth(finalmanastring)
manaFrame.PointXos = (stringwidth) * -1
manaFrame:SetPoint("LEFT", TargetFrame, "LEFT", manaFrame.PointXos, manaFrame.PointYos)
elseif who == "s" then
if SimplePercent["plymana"] == false then
ChangeFrame(selfmanaFrame, false)
return
end
if not selfmanaFrame:IsShown() then return end
local mana = UnitPower(unitid)
local maxmana = UnitPowerMax(unitid)
local finalmana
if mana == 0 or UnitIsDeadOrGhost(unitid) then
permana = 0
finalmana = 0
elseif mana == maxmana then
finalmana = 100
elseif maxmana == 100 then
finalmana = mana
else
local floatper = mana / maxmana
local permana = floatper * 100
finalmana = math.ceil(permana)
end
if selfmanaFrame.OldFinalHp == finalmana then return end
selfmanaFrame.OldFinalHp = finalmana
local finalmanastring = tostring(finalmana) .. "%"
selfmanaFrame:SetText(finalmanastring)
local stringwidth = selfmanaFrame:GetStringWidth(finalmanastring)
selfmanaFrame.PointXos = 0
selfmanaFrame:SetPoint("LEFT", PlayerFrame, "RIGHT", selfmanaFrame.PointXos, selfmanaFrame.PointYos)
end
end
local stringwidth
local hpFrame = TargetFrame:CreateFontString("hpFrame", "OVERLAY")
hpFrame:SetFontObject(PlayerFrameHealthBarText:GetFontObject())
hpFrame:SetText("100%")
hpFrame:SetJustifyH("LEFT")
hpFrame:SetJustifyV("TOP")
hpFrame.PointXos = 0
hpFrame.PointYos = 5
stringwidth = hpFrame:GetStringWidth(hpFrame:GetText())
hpFrame.PointXos = (stringwidth) * -1
hpFrame:SetPoint("LEFT", TargetFrame, "LEFT", hpFrame.PointXos, hpFrame.PointYos)
local selfhpFrame = PlayerFrame:CreateFontString("selfhpFrame", "OVERLAY")
selfhpFrame:SetFontObject(PlayerFrameHealthBarText:GetFontObject())
selfhpFrame:SetText("100%")
selfhpFrame:SetJustifyH("RIGHT")
selfhpFrame:SetJustifyV("TOP")
selfhpFrame.PointXos = 0
selfhpFrame.PointYos = 5
stringwidth = selfhpFrame:GetStringWidth(selfhpFrame:GetText())
selfhpFrame.PointXos = 0
selfhpFrame:SetPoint("LEFT", PlayerFrame, "RIGHT", selfhpFrame.PointXos, selfhpFrame.PointYos)
local manaFrame = TargetFrame:CreateFontString("manaFrame", "OVERLAY")
manaFrame:SetFontObject(PlayerFrameHealthBarText:GetFontObject())
manaFrame:SetText("100%")
manaFrame:SetJustifyH("LEFT")
manaFrame:SetJustifyV("TOP")
manaFrame.PointXos = 0
manaFrame.PointYos = -8
stringwidth = manaFrame:GetStringWidth(manaFrame:GetText())
manaFrame.PointXos = (stringwidth) * -1
manaFrame:SetPoint("LEFT", TargetFrame, "LEFT", manaFrame.PointXos, manaFrame.PointYos)
local selfmanaFrame = PlayerFrame:CreateFontString("selfmanaFrame", "OVERLAY")
selfmanaFrame:SetFontObject(PlayerFrameHealthBarText:GetFontObject())
selfmanaFrame:SetText("100%")
selfmanaFrame:SetJustifyH("RIGHT")
selfmanaFrame:SetJustifyV("TOP")
selfmanaFrame.PointXos = 0
selfmanaFrame.PointYos = -8
stringwidth = selfmanaFrame:GetStringWidth(selfmanaFrame:GetText())
selfmanaFrame.PointXos = 0
selfmanaFrame:SetPoint("LEFT", PlayerFrame, "RIGHT", selfmanaFrame.PointXos, selfmanaFrame.PointYos)
stringwidth = nil
function ChangeFrame(frame, what)
if what == false then
if frame:IsVisible() then
frame:Hide()
end
else
if not frame:IsVisible() then
frame:Show()
end
end
end
SLASH_CHANGESHIT1 = "/sp"
SLASH_CHANGESHIT2 = "/simplepercent"
local function handler(msg, editbox)
if msg == "player health" then
if SimplePercent["plyhp"] == false then
SimplePercent["plyhp"] = true
ChangeFrame(selfhpFrame, true)
print("Player health percent is now visible.")
else
SimplePercent["plyhp"] = false
ChangeFrame(selfhpFrame, false)
print("Player health percent is now hidden.")
end
elseif msg == "player mana" then
if SimplePercent["plymana"] == false then
SimplePercent["plymana"] = true
ChangeFrame(selfmanaFrame, true)
print("Player mana percent is now visible.")
else
SimplePercent["plymana"] = false
ChangeFrame(selfmanaFrame, false)
print("Player mana percent is now hidden.")
end
elseif msg == "target health" then
if SimplePercent["tarhp"] == false then
SimplePercent["tarhp"] = true
ChangeFrame(hpFrame, true)
print("Target health percent is now visible.")
else
SimplePercent["tarhp"] = false
ChangeFrame(hpFrame, false)
print("Target health percent is now hidden.")
end
elseif msg == "target mana" then
if SimplePercent["tarmana"] == false then
SimplePercent["tarmana"] = true
ChangeFrame(manaFrame, true)
print("Target mana percent is now visible.")
else
SimplePercent["tarmana"] = false
ChangeFrame(manaFrame, false)
print("Target mana percent is now hidden.")
end
else
print("You can toggle percent visiblity with this command")
print("Syntax: /sp <player or target> <health or mana> | Example: /sp target health")
end
end
SlashCmdList["CHANGESHIT"] = handler
local AddonLoadedHandler = CreateFrame("FRAME", "AddonLoadedHandler")
AddonLoadedHandler:RegisterEvent("ADDON_LOADED")
local function AddonLoaded(self, event, ...)
local addon = ...
if addon == "SimplePercent" then
if SimplePercent == nil then
SimplePercent = {}
SimplePercent["plyhp"] = true
SimplePercent["plymana"] = true
SimplePercent["tarhp"] = true
SimplePercent["tarmana"] = true
else
ChangeFrame(selfhpFrame, SimplePercent["plyhp"])
ChangeFrame(selfmanaFrame, SimplePercent["plymana"])
ChangeFrame(hpFrame, SimplePercent["tarhp"])
ChangeFrame(manaFrame, SimplePercent["tarmana"])
end
end
end
AddonLoadedHandler:SetScript("OnEvent", AddonLoaded)