Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------
- -- Initilization --
- -------------------
- -- Diasble AddOn if not a DK.
- -- if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then return end
- local addonName, addonTable = ...
- -----------------------
- -- Local Definitions --
- -----------------------
- -- AddOn Frame
- local frame = CreateFrame("Frame", addonName.."Frame", UIParent)
- -- Table to hold all of the damage events and their timestamp
- local damageTable = {}
- -- OnUpdate Interval
- local updateInterval = 0.1
- -- GUID Types
- local knownTypes = {
- "player",
- "world object",
- "NPC",
- "pet",
- "vehicle"
- }
- -- Upsourcing
- local pairs = pairs
- local time = time
- local tonumber = tonumber
- local strsub = strsub
- -- Player GUID
- local playerGUID
- -- Index to name the key for the damageTable
- local eventIndex = 0
- ----------
- -- Core --
- ----------
- -- Setup font display
- local fontString = frame:CreateFontString(addonName.."FontString", "OVERLAY", "GameFontHighlight")
- fontString:SetFont(STANDARD_TEXT_FONT, 25, "OUTLINE")
- fontString:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
- -- OnEvent function to handle all the registered events firing.
- frame:SetScript("OnEvent", function(self, event, ...)
- if event == "PLAYER_LOGIN" then
- -- Get and set the playerGUID for use later.
- playerGUID = UnitGUID("player")
- -- Unregister PLAYER_LOGIN as it is no longer needed.
- frame:UnregisterEvent("PLAYER_LOGIN")
- elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
- eventIndex = eventIndex + 1
- local t = time()
- local _, eventType, _, sourceGUID, _, _, _, destGUID = ...
- local maskedTypeBit = tonumber(strsub(sourceGUID, 5, 5), 16) % 8
- if eventType == "SWING_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
- local _, _, _, _, _, _, _, _, _, _, _, amount = ...
- damageTable[eventIndex] = {t, amount}
- elseif eventType == "SPELL_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
- local _, _, _, _, _, _, _, _, _, _, _, _, _, _, amount = ...
- damageTable[eventIndex] = {t, amount}
- elseif eventType == "SPELL_PERIODIC_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
- local _, _, _, _, _, _, _, _, _, _, _, _, _, _, amount = ...
- damageTable[eventIndex] = {t, amount}
- end -- if eventType
- end -- if event
- end)
- -- OnUpdate function to constantly poll the damageTable and make sure the damage text is up to date.
- local totalTime = 0
- local totalDamage = 0
- frame:SetScript("OnUpdate", function(self, elapsed)
- totalTime = totalTime + elapsed
- if totalTime >= updateInterval then
- local t = time() - 5
- for k, v in pairs(damageTable) do
- if v[1] < t then
- damageTable[k] = nil
- else
- totalDamage = totalDamage + v[2]
- end -- if k < t...
- end -- for k, v...
- if totalDamage > 0 then
- fontString:SetText(totalDamage)
- else
- fontString:SetText("")
- end
- totalDamage = 0
- totalTime = 0
- end -- if totalTime
- end)
- ------------
- -- Events --
- ------------
- frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- frame:RegisterEvent("PLAYER_LOGIN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement