Advertisement
Guest User

Untitled

a guest
Mar 17th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. -------------------
  2. -- Initilization --
  3. -------------------
  4.     -- Diasble AddOn if not a DK.
  5.     -- if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then return end
  6.  
  7.     local addonName, addonTable = ...
  8.    
  9. -----------------------
  10. -- Local Definitions --
  11. -----------------------
  12.     -- AddOn Frame
  13.     local frame = CreateFrame("Frame", addonName.."Frame", UIParent)
  14.    
  15.     -- Table to hold all of the damage events and their timestamp
  16.     local damageTable = {}
  17.    
  18.     -- OnUpdate Interval
  19.     local updateInterval = 0.1
  20.    
  21.     -- GUID Types
  22.     local knownTypes = {
  23.         "player",
  24.         "world object",
  25.         "NPC",
  26.         "pet",
  27.         "vehicle"
  28.     }
  29.    
  30.     -- Upsourcing
  31.     local pairs = pairs
  32.     local time = time
  33.     local tonumber = tonumber
  34.     local strsub = strsub
  35.    
  36.     -- Player GUID
  37.     local playerGUID
  38.    
  39.     -- Index to name the key for the damageTable
  40.     local eventIndex = 0
  41.  
  42. ----------
  43. -- Core --
  44. ----------
  45.     -- Setup font display
  46.     local fontString = frame:CreateFontString(addonName.."FontString", "OVERLAY", "GameFontHighlight")
  47.     fontString:SetFont(STANDARD_TEXT_FONT, 25, "OUTLINE")
  48.     fontString:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  49.    
  50.     -- OnEvent function to handle all the registered events firing.
  51.     frame:SetScript("OnEvent", function(self, event, ...)
  52.         if event == "PLAYER_LOGIN" then
  53.             -- Get and set the playerGUID for use later.
  54.             playerGUID = UnitGUID("player")
  55.             -- Unregister PLAYER_LOGIN as it is no longer needed.
  56.             frame:UnregisterEvent("PLAYER_LOGIN")
  57.         elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  58.             eventIndex = eventIndex + 1
  59.             local t = time()
  60.             local _, eventType, _, sourceGUID, _, _, _, destGUID = ...
  61.             local maskedTypeBit = tonumber(strsub(sourceGUID, 5, 5), 16) % 8
  62.             if eventType == "SWING_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
  63.                 local _, _, _, _, _, _, _, _, _, _, _, amount = ...
  64.                 damageTable[eventIndex] = {t, amount}
  65.             elseif eventType == "SPELL_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
  66.                 local _, _, _, _, _, _, _, _, _, _, _, _, _, _, amount = ...
  67.                 damageTable[eventIndex] = {t, amount}
  68.             elseif eventType == "SPELL_PERIODIC_DAMAGE" and destGUID == playerGUID and knownTypes[maskedTypeBit] == "NPC" then
  69.                 local _, _, _, _, _, _, _, _, _, _, _, _, _, _, amount = ...
  70.                 damageTable[eventIndex] = {t, amount}
  71.             end -- if eventType
  72.         end -- if event
  73.     end)
  74.  
  75.     -- OnUpdate function to constantly poll the damageTable and make sure the damage text is up to date.
  76.     local totalTime = 0
  77.     local totalDamage = 0
  78.     frame:SetScript("OnUpdate", function(self, elapsed)
  79.         totalTime = totalTime + elapsed
  80.         if totalTime >= updateInterval then
  81.             local t = time() - 5
  82.             for k, v in pairs(damageTable) do
  83.                 if v[1] < t then
  84.                     damageTable[k] = nil
  85.                 else
  86.                     totalDamage = totalDamage + v[2]
  87.                 end -- if k < t...
  88.             end -- for k, v...
  89.            
  90.             if totalDamage > 0 then
  91.                 fontString:SetText(totalDamage)
  92.             else
  93.                 fontString:SetText("")
  94.             end
  95.            
  96.             totalDamage = 0
  97.             totalTime = 0
  98.         end -- if totalTime
  99.     end)
  100.    
  101. ------------
  102. -- Events --
  103. ------------
  104.     frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  105.     frame:RegisterEvent("PLAYER_LOGIN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement