Advertisement
Guest User

DamageTracker1

a guest
Jul 23rd, 2016
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.45 KB | None | 0 0
  1. if not DTPS_EventFrame then
  2.     DTPS_EventFrame = CreateFrame("Frame")
  3.     DamageTable={}
  4.     TimestampTable={}
  5. end
  6.  
  7. DTPS_EventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  8. DTPS_EventFrame:SetScript("OnEvent", function(self, event, ...)
  9.         if event == "COMBAT_LOG_EVENT_UNFILTERED" then
  10.             DTPS_HandleCombatEvent(...)
  11.         end
  12. end)
  13.  
  14. function DTPS_HandleCombatEvent(timestamp, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24,...)
  15.    
  16.     i=0
  17.     sum=0
  18.     calc=0
  19.     dtps=0
  20.     iconvalue=0
  21.     playerhealth=0
  22.     durationdamage = 0
  23.     damage=0
  24.     n=0
  25.     period = 5
  26.    
  27.     -- Check if it is the player who receives damage
  28.     if arg8 ~= UnitGUID("player") then
  29.         do return end
  30.     end
  31.    
  32.     -- Sort out all events that are not damage
  33.     if arg2 ~= "SWING_DAMAGE" then
  34.         if arg2 ~= "RANGE_DAMAGE" then
  35.             if arg2 ~= "SPELL_DAMAGE" then
  36.                 if arg2 ~= "SPELL_PERIODIC_DAMAGE" then
  37.                     if arg2 ~= "SPELL_BUILDING_DAMAGE" then
  38.                         if arg2 ~= "ENVIRONMENTAL_DAMAGE" then
  39.                             do return end
  40.                         end
  41.                     end
  42.                 end
  43.             end
  44.         end
  45.     end
  46.    
  47.     -- Define the argument depending on damage
  48.     if arg2 == "SWING_DAMAGE" then
  49.         damage = arg12
  50.     elseif arg2 == "RANGE_DAMAGE" or "SPELL_DAMAGE" or "SPELL_PERIODIC_DAMAGE" or "SPELL_BUILDING_DAMAGE" then
  51.         damage = arg15
  52.     elseif arg2 == "ENVIRONMENTAL_DAMAGE" then
  53.         damage = arg13
  54.     end
  55.    
  56.     --Check if the table is empty and fill the first entry
  57.     if #TimestampTable == 0 then
  58.         DamageTable[1]=damage
  59.         TimestampTable[1]=timestamp
  60.         i = 1
  61.     else
  62.         -- If table is not empty - add a new value to the beginning
  63.         for i=#TimestampTable, 1, -1 do
  64.             n = i+1
  65.             TimestampTable[n] = TimestampTable[i]
  66.             TimestampTable[1] = timestamp
  67.             DamageTable[n] = DamageTable[i]
  68.             DamageTable[1] = damage
  69.         end
  70.        
  71.         -- Delete outdated values in the end
  72.         for i=1, #TimestampTable do
  73.             if TimestampTable[i] + period < timestamp then
  74.                 DamageTable[i] = nil
  75.                 TimestampTable[i] = nil
  76.             end
  77.         end
  78.        
  79.         -- Creating damage sum and values for icons
  80.         sum = 0
  81.         for i = 1, #TimestampTable do
  82.             sum=sum+DamageTable[i]
  83.         end
  84.        
  85.         -- Defining the duration of damage
  86.         if TimestampTable[1] == TimestampTable[#TimestampTable] then
  87.             durationdamage = 1
  88.         else
  89.             durationdamage = TimestampTable[1] - TimestampTable[#TimestampTable]
  90.         end
  91.        
  92.         dtps = sum/durationdamage
  93.         playerhealth = UnitHealthMax("player")
  94.         iconvalue = dtps/playerhealth
  95.        
  96.         -- Icons values section
  97.         if iconvalue > 0 then
  98.             IC1 = true
  99.         else
  100.             IC1 = false
  101.         end
  102.         if iconvalue > 0.05 then
  103.             IC2 = true
  104.         else
  105.             IC2 = false
  106.         end
  107.         if iconvalue > 0.1 then
  108.             IC3 = true
  109.         else
  110.             IC3 = false
  111.         end
  112.         if iconvalue > 0.15 then
  113.             IC4 = true
  114.         else
  115.             IC4 = false
  116.         end
  117.         if iconvalue > 0.2 then
  118.             IC5 = true
  119.         else
  120.             IC5 = false
  121.         end
  122.         if iconvalue > 0.25 then
  123.             IC6 = true
  124.         else
  125.             IC6 = false
  126.         end
  127.         if iconvalue > 0.3 then
  128.             IC7 = true
  129.         else
  130.             IC7 = false
  131.         end
  132.         if iconvalue > 0.35 then
  133.             IC8 = true
  134.         else
  135.             IC8 = false
  136.         end
  137.         if iconvalue > 0.4 then
  138.             IC9 = true
  139.         else
  140.             IC9 = false
  141.         end
  142.         if iconvalue > 0.45 then
  143.             IC10 = true
  144.         else
  145.             IC10 = false
  146.         end
  147.         if iconvalue > 0.5 then
  148.             IC11 = true
  149.         else
  150.             IC11 = false
  151.         end
  152.         if iconvalue > 0.55 then
  153.             IC12 = true
  154.         else
  155.             IC12 = false
  156.         end
  157.         if iconvalue > 0.6 then
  158.             IC13 = true
  159.         else
  160.             IC13 = false
  161.         end
  162.         if iconvalue > 0.65 then
  163.             IC14 = true
  164.         else
  165.             IC14 = false
  166.         end
  167.         if iconvalue > 0.7 then
  168.             IC15 = true
  169.         else
  170.             IC15 = false
  171.         end
  172.         if iconvalue > 0.75 then
  173.             IC16 = true
  174.         else
  175.             IC16 = false
  176.         end
  177.         if iconvalue > 0.8 then
  178.             IC17 = true
  179.         else
  180.             IC17 = false
  181.         end
  182.         if iconvalue > 0.85 then
  183.             IC18 = true
  184.         else
  185.             IC18 = false
  186.         end
  187.         if iconvalue > 0.9 then
  188.             IC19 = true
  189.         else
  190.             IC19 = false
  191.         end
  192.         if iconvalue > 0.95 then
  193.             IC20 = true
  194.         else
  195.             IC20 = false
  196.         end
  197.         SendChatMessage(durationdamage, "WHISPER", nil , "Zakdh")
  198.         SendChatMessage(TimestampTable[1], "WHISPER", nil , "Zakdh")
  199.         SendChatMessage(TimestampTable[#TimestampTable], "WHISPER", nil , "Zakdh")
  200.         SendChatMessage(sum, "WHISPER", nil , "Zakdh")
  201.     end
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement