PHP код:
local combatframe, frame, Litedpsdb, delay, summons, playerGUID, Lite, check, Lite_onUpdate, Litedpstime =
CreateFrame("Frame"), CreateFrame("Frame",nil,UIParent), 0, 0, {}, UnitGUID("player")
if not LiteDPSDB then LiteDPSDB = {} end
local function Lite_savePosition()
if not LiteDPSDB.Pos then LiteDPSDB.Pos = {} end
LiteDPSDB.Pos.point, _, LiteDPSDB.Pos.rpoint, LiteDPSDB.Pos.x, LiteDPSDB.Pos.y = Lite:GetPoint()
end
local function Lite_CreateBar()
Lite = CreateFrame("Frame", nil, UIParent)
Lite:SetMovable(true)
Lite:SetWidth(100)
Lite:SetHeight(30)
if LiteDPSDB.Pos then Lite:SetPoint(LiteDPSDB.Pos.point, UIParent, LiteDPSDB.Pos.rpoint, LiteDPSDB.Pos.x, LiteDPSDB.Pos.y)
else Lite:SetPoint("CENTER", UIParent, "CENTER")
end
Lite:SetFrameStrata("BACKGROUND")
Lite:SetClampedToScreen(true)
Lite:EnableMouse(true)
Lite:SetScript("OnMouseDown",function(self,button) if button == "LeftButton" then self:StartMoving() end end)
Lite:SetScript("OnMouseUp",function(self,button) if button == "LeftButton" then self:StopMovingOrSizing() Lite_savePosition() end end)
Lite.text = Lite:CreateFontString(nil,"ARTWORK","GameFontNormalHuge")
Lite.text:SetFont(STANDARD_TEXT_FONT,15,"OUTLINE")
Lite.text:SetTextColor(0.46,0.53,0.6,1)
Lite.text:SetPoint("LEFT",Lite,"LEFT",0,0)
Lite.text:SetText("Lite: DPS")
Lite.text:Show()
Lite:Show()
end
local LiteDPSEvents = {
["SWING_DAMAGE"] = true,
["RANGE_DAMAGE"] = true,
["SPELL_DAMAGE"] = true,
["SPELL_PERIODIC_DAMAGE"] = true,
["DAMAGE_SHIELD"] = true,
["DAMAGE_SPLIT"] = true,
["SPELL_EXTRA_ATTACKS"] = true,
["SPELL_BUILDING_DAMAGE"] = true,
}
local function Lite_COMBAT_LOG_EVENT_UNFILTERED(...)
if not playerGUID then playerGUID = UnitGUID("player") end
if arg2 == "SPELL_SUMMON" and arg3 == playerGUID and not summons[arg6] then summons[arg6] = true end
if LiteDPSEvents[arg2] and (arg3 == playerGUID or arg3 == UnitGUID("pet") or summons[arg3]) then
if arg2 == "SWING_DAMAGE" then Litedpsdb = Litedpsdb + arg9
else Litedpsdb = Litedpsdb + arg12
end
if not Litedpstime then Litedpstime = GetTime() end
local actime = (GetTime() - Litedpstime == 0 and 1) or GetTime() - Litedpstime
Lite.text:SetText(Litedpsdb.."|cff66cdaa ("..string.format("%."..(1 or 0).."f", (Litedpsdb/actime))..")")
end
end
local function checkCombat()
if UnitAffectingCombat("pet") then return true end
for i=1,GetNumRaidMembers() do if UnitAffectingCombat("raid"..i) or UnitAffectingCombat("raidpet"..i) then return true end end
for i=1,GetNumPartyMembers() do if UnitAffectingCombat("party"..i) or UnitAffectingCombat("partypet"..i) then return true end end
end
local function newfight()
if checkCombat() then if not check then Lite_onUpdate(true) end
else if check then Lite_onUpdate() end Litedpsdb, summons, Litedpstime, check = 0, {}
end
end
Lite_onUpdate = function(arg)
if arg then combatframe:SetScript("OnUpdate", function(self,elapsed)
delay = delay + elapsed if delay >= 1 then newfight() delay = 0 end end) check = true
else combatframe:SetScript("OnUpdate", nil) check = nil
end
end
local function Lite_OnLoad(self)
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
if not Lite then Lite_CreateBar() end
end
local eventhandler = {
["VARIABLES_LOADED"] = function(self) Lite_OnLoad(self) end,
["COMBAT_LOG_EVENT_UNFILTERED"] = function(self,...) Lite_COMBAT_LOG_EVENT_UNFILTERED(...) end,
["PLAYER_REGEN_ENABLED"] = function(self,...) newfight() end,
["PLAYER_REGEN_DISABLED"] = function(self,...) Lite_onUpdate() end,
}
local function Lite_OnEvent(self,event,...) eventhandler[event](self,...) end
frame:SetScript("OnEvent",Lite_OnEvent)
frame:RegisterEvent("VARIABLES_LOADED")