Advertisement
Guest User

DamageTracker

a guest
Jul 23rd, 2016
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.04 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.    
  26.     -- Check if it is the player who receives damage
  27.     if arg8 ~= UnitGUID("player") then
  28.         do return end
  29.     end
  30.    
  31.     -- Sort out all events that are not damage
  32.     if arg2 ~= "SWING_DAMAGE" then
  33.         if arg2 ~= "RANGE_DAMAGE" then
  34.             if arg2 ~= "SPELL_DAMAGE" then
  35.                 if arg2 ~= "SPELL_PERIODIC_DAMAGE" then
  36.                     if arg2 ~= "SPELL_BUILDING_DAMAGE" then
  37.                         if arg2 ~= "ENVIRONMENTAL_DAMAGE" then
  38.                             do return end
  39.                         end
  40.                     end
  41.                 end
  42.             end
  43.         end
  44.     end
  45.    
  46.     -- Define the argument depending on damage
  47.     if arg2 == "SWING_DAMAGE" then
  48.         damage = arg12
  49.     elseif arg2 == "RANGE_DAMAGE" or "SPELL_DAMAGE" or "SPELL_PERIODIC_DAMAGE" or "SPELL_BUILDING_DAMAGE" then
  50.         damage = arg15
  51.     elseif arg2 == "ENVIRONMENTAL_DAMAGE" then
  52.         damage = arg13
  53.     end
  54.    
  55.     --Check if the table is empty and fill the first entry
  56.     if #TimestampTable == 0 then
  57.         DamageTable[1]=damage
  58.         TimestampTable[1]=timestamp
  59.         i = 1
  60.     else
  61.         -- If table is not empty - add a new value to the end
  62.         i = #TimestampTable + 1
  63.         TimestampTable[i] = timestamp
  64.         DamageTable[i] = damage
  65.     end
  66.    
  67.     -- Rewrite the tables shifting values and keys and deleting duplicate values
  68.     calc = 0
  69.     for i=1, #TimestampTable do
  70.         if TimestampTable[i] + 5 < timestamp then
  71.             n = calc + 1
  72.             calc = math.min(n, #TimestampTable)
  73.         end
  74.     end
  75.    
  76.     for i=1, calc-1 do
  77.         if TimestampTable[i] + 5 < timestamp then
  78.             TimestampTable[i] = nil
  79.             DamageTable[i] = nil
  80.         end
  81.     end
  82.    
  83.     for i=1, #TimestampTable do
  84.         if TimestampTable[i] == nil then
  85.             TimestampTable[i] = TimestampTable[calc]
  86.             DamageTable[i] = DamageTable[calc]
  87.             TimestampTable[calc] = nil
  88.             DamageTable[calc] = nil
  89.             calc = calc + 1
  90.         end
  91.     end
  92.    
  93.     -- Creating damage sum and values for icons
  94.     sum = 0
  95.     for i = 1, #TimestampTable do
  96.         sum=sum+DamageTable[i]
  97.     end
  98.    
  99.     -- Defining the duration of damage
  100.     if TimestampTable[1] == TimestampTable[#TimestampTable] then
  101.         durationdamage = 1
  102.     else
  103.         durationdamage = TimestampTable[#TimestampTable] - TimestampTable[1]
  104.     end
  105.    
  106.     dtps = sum/durationdamage
  107.     playerhealth = UnitHealthMax("player")
  108.     iconvalue = dtps/playerhealth
  109.    
  110.     -- Icons values section
  111.     if iconvalue > 0 then
  112.         IC1 = true
  113.     else
  114.         IC1 = false
  115.     end
  116.     if iconvalue > 0.05 then
  117.         IC2 = true
  118.     else
  119.         IC2 = false
  120.     end
  121.     if iconvalue > 0.1 then
  122.         IC3 = true
  123.     else
  124.         IC3 = false
  125.     end
  126.     if iconvalue > 0.15 then
  127.         IC4 = true
  128.     else
  129.         IC4 = false
  130.     end
  131.     if iconvalue > 0.2 then
  132.         IC5 = true
  133.     else
  134.         IC5 = false
  135.     end
  136.     if iconvalue > 0.25 then
  137.         IC6 = true
  138.     else
  139.         IC6 = false
  140.     end
  141.     if iconvalue > 0.3 then
  142.         IC7 = true
  143.     else
  144.         IC7 = false
  145.     end
  146.     if iconvalue > 0.35 then
  147.         IC8 = true
  148.     else
  149.         IC8 = false
  150.     end
  151.     if iconvalue > 0.4 then
  152.         IC9 = true
  153.     else
  154.         IC9 = false
  155.     end
  156.     if iconvalue > 0.45 then
  157.         IC10 = true
  158.     else
  159.         IC10 = false
  160.     end
  161.     if iconvalue > 0.5 then
  162.         IC11 = true
  163.     else
  164.         IC11 = false
  165.     end
  166.     if iconvalue > 0.55 then
  167.         IC12 = true
  168.     else
  169.         IC12 = false
  170.     end
  171.     if iconvalue > 0.6 then
  172.         IC13 = true
  173.     else
  174.         IC13 = false
  175.     end
  176.     if iconvalue > 0.65 then
  177.         IC14 = true
  178.     else
  179.         IC14 = false
  180.     end
  181.     if iconvalue > 0.7 then
  182.         IC15 = true
  183.     else
  184.         IC15 = false
  185.     end
  186.     if iconvalue > 0.75 then
  187.         IC16 = true
  188.     else
  189.         IC16 = false
  190.     end
  191.     if iconvalue > 0.8 then
  192.         IC17 = true
  193.     else
  194.         IC17 = false
  195.     end
  196.     if iconvalue > 0.85 then
  197.         IC18 = true
  198.     else
  199.         IC18 = false
  200.     end
  201.     if iconvalue > 0.9 then
  202.         IC19 = true
  203.     else
  204.         IC19 = false
  205.     end
  206.     if iconvalue > 0.95 then
  207.         IC20 = true
  208.     else
  209.         IC20 = false
  210.     end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement