Thread Tools Display Modes
07-27-23, 04:42 PM   #1
Infinite-Loop-Alchemist
A Murloc Raider
 
Infinite-Loop-Alchemist's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2023
Posts: 7
"SPELL_DAMAGE" and "SPELL_PERIODIC_DAMAGE" Crit bool is nil

Ive been working on this addon for a while. here's my code.
Code:
-- Define a table to hold the highest hits data.
CritMaticData = CritMaticData or {}

local function GetGCD()
  local _, gcdDuration = GetSpellCooldown(78) -- 78 is the spell ID for Warrior's Heroic Strike
  if gcdDuration == 0 then
    return 1.5 -- Default GCD duration if not available (you may adjust this value if needed)
  else
    return gcdDuration
  end
end

local function AddHighestHitsToTooltip(self, slot)
  if (not slot) then
    return
  end

  local actionType, id = GetActionInfo(slot)
  if actionType == "spell" then
    local spellName, _, _, castTime = GetSpellInfo(id)
    if CritMaticData[spellName] then
      local cooldown = (GetSpellBaseCooldown(id) or 0) / 1000
      local effectiveCastTime = castTime > 0 and (castTime / 1000) or GetGCD()
      local effectiveTime = max(effectiveCastTime, cooldown)

      local critDPS = CritMaticData[spellName].highestCrit / effectiveTime
      local normalDPS = CritMaticData[spellName].highestNormal / effectiveTime

      local CritMaticLeft = "Highest Crit: "
      local CritMaticRight = tostring(CritMaticData[spellName].highestCrit) .. " (" .. format("%.1f", critDPS) .. " DPS)"
      local normalMaticLeft = "Highest Normal: "
      local normalMaticRight = tostring(CritMaticData[spellName].highestNormal) .. " (" .. format("%.1f", normalDPS) .. " DPS)"

      -- Check if lines are already present in the tooltip.
      local critMaticExists = false
      local normalMaticExists = false

      for i = 1, self:NumLines() do
        local gtl = _G["GameTooltipTextLeft" .. i]
        local gtr = _G["GameTooltipTextRight" .. i]
        if gtl and gtr then
          if gtl:GetText() == CritMaticLeft and gtr:GetText() == CritMaticRight then
            critMaticExists = true
          elseif gtl:GetText() == normalMaticLeft and gtr:GetText() == normalMaticRight then
            normalMaticExists = true
          end
        end
      end

      -- If lines don't exist, add them.
      if not critMaticExists then
        self:AddDoubleLine(CritMaticLeft, CritMaticRight)
        _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
        _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
      end

      if not normalMaticExists then
        self:AddDoubleLine(normalMaticLeft, normalMaticRight)
        _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
        _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
      end

      self:Show()
    end
  end
end

-- Register an event that fires when the player hits an enemy.
local f = CreateFrame("FRAME")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)
  -- Get information about the combat event.
  local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, spellID, spellName, spellSchool, amount, overhealing, absorbed, critical = CombatLogGetCurrentEventInfo()

  if eventType == "SWING_DAMAGE" then
    amount = spellID
    spellName = "Auto Attack"
    spellIcon = 6603 -- or specify the path to a melee icon, if you have one
  else
    spellName, _, spellIcon = GetSpellInfo(spellID)
  end

  -- Check if the event is a player hit or a player heal and update the highest hits/heals data if needed.
  if sourceGUID == UnitGUID("player") and destGUID ~= UnitGUID("player") and (eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE" or eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" or eventType == "SPELL_PERIODIC_DAMAGE") and amount > 0 then
    print("Event type: " .. eventType)
    print("Critical flag: " .. tostring(critical))
    if spellName then
      CritMaticData[spellName] = CritMaticData[spellName] or {
        highestCrit = 0,
        highestNormal = 0,
        highestHeal = 0,
        highestHealCrit = 0,
        spellIcon = spellIcon,
      }

      if critical then

        print("Critical flag: " .. tostring(critical))
        print("Critical hit!")
        if (eventType == "SPELL_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE") then
          print("Damage event!")
          if amount > CritMaticData[spellName].highestCrit then
            if spellName == "Auto Attack" then
              return
            end
            print(CritMaticData[spellName].highestCrit)
            CritMaticData[spellName].highestCrit = amount
            print(CritMaticData[spellName].highestCrit)
            PlaySound(888, "SFX")
            CritMatic.ShowNewCritMessage(spellName, amount)
            print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
          end

        else
          if (eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL") then
            if amount > CritMaticData[spellName].highestHealCrit then
              print(CritMaticData[spellName].highestHealCrit)
              CritMaticData[spellName].highestHealCrit = amount
              print(CritMaticData[spellName].highestHealCrit)
              PlaySound(888, "SFX")
              CritMatic.ShowNewHealCritMessage(spellName, amount)
              print("New highest crit heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHealCrit)
            end
          end
        end
      else
        if (eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL") then
          if amount > CritMaticData[spellName].highestHeal then
            if spellName == "Auto Attack" then
              return
            end
            CritMaticData[spellName].highestHeal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewHealMessage(spellName, amount)
            print("New highest normal heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHeal)
          end
        else
          if (eventType == "SPELL_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE") then
            if amount > CritMaticData[spellName].highestNormal then
              if spellName == "Auto Attack" then
                return
              end
              CritMaticData[spellName].highestNormal = amount
              PlaySound(10049, "SFX")
              CritMatic.ShowNewNormalMessage(spellName, amount)
              print("New highest normal hit for " .. spellName .. ": " .. CritMaticData[spellName].highestNormal)
            end
          end
        end
      end
    end
  end
end)

-- Register an event that fires when the addon is loaded.
local function OnLoad(self, event)
  print("CritMatic Loaded!")

  CritMaticData = _G["CritMaticData"]

  -- Add the highest hits data to the spell button tooltip.
  hooksecurefunc(GameTooltip, "SetAction", AddHighestHitsToTooltip)
end
local frame = CreateFrame("FRAME")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", OnLoad)

-- Register an event that fires when the player logs out or exits the game.
local function OnSave(self, event)
  -- Save the highest hits data to the saved variables for the addon.
  _G["CritMaticData"] = CritMaticData
end
local frame = CreateFrame("FRAME")
frame:RegisterEvent("PLAYER_LOGOUT")
frame:SetScript("OnEvent", OnSave)

local function ResetData()
  CritMaticData = {}
  print("CritMatic data reset.")
end

SLASH_CRITMATICRESET1 = '/cmreset'
function SlashCmdList.CRITMATICRESET(msg, editBox)
  ResetData()
end
  Reply With Quote
07-27-23, 06:05 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,831
You have critical as return 18 from CombatLogGetCurrentEventInfo() which would work for SWING_DAMAGE. WoWPedia says it should be 21 for SPELL_DAMAGE.

There's a side by side comparison table of return for SWING_DAMAGE and SPELL_DAMAGE on that page.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-27-23 at 06:08 PM.
  Reply With Quote
07-28-23, 07:14 AM   #3
Infinite-Loop-Alchemist
A Murloc Raider
 
Infinite-Loop-Alchemist's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2023
Posts: 7
I need the problem now ill try something and let you know if it worked
@Fizzlemizz

Last edited by Infinite-Loop-Alchemist : 07-28-23 at 07:24 AM.
  Reply With Quote
07-28-23, 10:21 AM   #4
Infinite-Loop-Alchemist
A Murloc Raider
 
Infinite-Loop-Alchemist's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2023
Posts: 7
Originally Posted by Fizzlemizz View Post
You have critical as return 18 from CombatLogGetCurrentEventInfo() which would work for SWING_DAMAGE. WoWPedia says it should be 21 for SPELL_DAMAGE.

There's a side by side comparison table of return for SWING_DAMAGE and SPELL_DAMAGE on that page.
Am I doing this right?
Code:
-- Register an event that fires when the player hits an enemy.
local f = CreateFrame("FRAME")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)

  -- Get information about the combat event.
  local eventInfo = {CombatLogGetCurrentEventInfo()}

  local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = unpack(eventInfo, 1, 11)
  local spellID, spellName, spellSchool, amount, overhealing, absorbed, critical

  if eventType == "SWING_DAMAGE" then
    spellName = "Auto Attack"
    spellID = 6603 -- or specify the path to a melee icon, if you have one
    amount, _, _, _, _, _, critical = unpack(eventInfo, 12, 18)
  else
    spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
    amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 21)
  end

  if sourceGUID == UnitGUID("player") and destGUID ~= UnitGUID("player") and amount > 0 then
    if spellName then
      CritMaticData[spellName] = CritMaticData[spellName] or {
        highestCrit = 0,
        highestNormal = 0,
        highestHeal = 0,
        highestHealCrit = 0,
        spellIcon = GetSpellTexture(spellID)
      }

      print(CombatLogGetCurrentEventInfo())

      if critical then
        if eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
          if amount > CritMaticData[spellName].highestHealCrit then
            if spellName == "Auto Attack" then
              return
            end
            CritMaticData[spellName].highestHealCrit = amount
            PlaySound(888, "SFX")
            CritMatic.ShowNewHealCritMessage(spellName, amount)
            print("New highest crit heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHealCrit)
          end
        else
          if amount > CritMaticData[spellName].highestCrit then
            if spellName == "Auto Attack" then
              return
            end
            CritMaticData[spellName].highestCrit = amount
            PlaySound(888, "SFX")
            CritMatic.ShowNewCritMessage(spellName, amount)
            print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
          end
        end
      elseif not critical then
        if eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
          if amount > CritMaticData[spellName].highestHeal then
            if spellName == "Auto Attack" then
              return
            end
            CritMaticData[spellName].highestHeal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewHealMessage(spellName, amount)
            print("New highest normal heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHeal)
          end
        else
          if amount > CritMaticData[spellName].highestNormal then
            if spellName == "Auto Attack" then
              return
            end
            CritMaticData[spellName].highestNormal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewNormalMessage(spellName, amount)
            print("New highest normal hit for " .. spellName .. ": " .. CritMaticData[spellName].highestNormal)
          end
        end
      end
    end
  end
heals crits work and heal normals work but spell normals work but not crits.
  Reply With Quote
07-28-23, 11:07 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,831
Originally Posted by Infinite-Loop-Alchemist View Post
but spell normals work but not crits.
I'm not exactly sure what you mean by this. Is it that you never see this triggered?
Lua Code:
  1. else
  2.           if amount > CritMaticData[spellName].highestCrit then
  3.             if spellName == "Auto Attack" then
  4.               return
  5.             end
  6.             CritMaticData[spellName].highestCrit = amount
  7.             PlaySound(888, "SFX")
  8.             CritMatic.ShowNewCritMessage(spellName, amount)
  9.             print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
  10.           end
  11. end

Or something else?

Edit: Taking a closer look:
Lua Code:
  1. if eventType == "SWING_DAMAGE" then
  2.     spellName = "Auto Attack"
  3.     spellID = 6603 -- or specify the path to a melee icon, if you have one
  4.     amount, _, _, _, _, _, critical = unpack(eventInfo, 12, 18)
  5.   else
  6.     spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
  7.     amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 21)
  8.   end
If the eventType is not "SWING_DAMAGE" then critical is unpacked from argument 18 not 21
Lua Code:
  1. amount, overhealing, _, _, _, absorbed, critical = unpack(eventInfo, 15, 21)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-28-23 at 11:32 AM.
  Reply With Quote
07-29-23, 07:10 AM   #6
Infinite-Loop-Alchemist
A Murloc Raider
 
Infinite-Loop-Alchemist's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2023
Posts: 7
Thank you!! but 1 problem

Originally Posted by Fizzlemizz View Post
I'm not exactly sure what you mean by this. Is it that you never see this triggered?
Lua Code:
  1. else
  2.           if amount > CritMaticData[spellName].highestCrit then
  3.             if spellName == "Auto Attack" then
  4.               return
  5.             end
  6.             CritMaticData[spellName].highestCrit = amount
  7.             PlaySound(888, "SFX")
  8.             CritMatic.ShowNewCritMessage(spellName, amount)
  9.             print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
  10.           end
  11. end

Or something else?

Edit: Taking a closer look:
Lua Code:
  1. if eventType == "SWING_DAMAGE" then
  2.     spellName = "Auto Attack"
  3.     spellID = 6603 -- or specify the path to a melee icon, if you have one
  4.     amount, _, _, _, _, _, critical = unpack(eventInfo, 12, 18)
  5.   else
  6.     spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
  7.     amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 21)
  8.   end
If the eventType is not "SWING_DAMAGE" then critical is unpacked from argument 18 not 21
Lua Code:
  1. amount, overhealing, _, _, _, absorbed, critical = unpack(eventInfo, 15, 21)
That worked but caused 1 problem now.
edit
The heals crits don't save in the tool-tip or Normal Heals. but works with spell_damage normals hits and Crits
The all messages are fix.

Code:
  if eventType == "SWING_DAMAGE" then
    spellName = "Auto Attack"
    spellID = 6603 -- or specify the path to a melee icon, if you have one
    amount, _, _, _, _, _, critical = unpack(eventInfo, 12, 18)
  elseif eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
    spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
    amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 18)
  elseif eventType == "SPELL_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" then
    spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
    amount, overhealing, _, _, _, absorbed, critical = unpack(eventInfo, 15, 21)
  end

  if sourceGUID == UnitGUID("player") and destGUID ~= UnitGUID("player") and (eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE" or eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" or eventType == "SPELL_PERIODIC_DAMAGE") and amount > 0 then
    if spellName then
      CritMaticData[spellName] = CritMaticData[spellName] or {
        highestCrit = 0,
        highestNormal = 0,
        highestHeal = 0,
        highestHealCrit = 0,
        spellIcon = GetSpellTexture(spellID)
      }

      print(CombatLogGetCurrentEventInfo())

      if eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
        if critical then
          -- When the event is a heal and it's a critical heal.
          if amount > CritMaticData[spellName].highestHealCrit then
            CritMaticData[spellName].highestHealCrit = amount
            PlaySound(888, "SFX")
            CritMatic.ShowNewHealCritMessage(spellName, amount)
            print("New highest crit heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHealCrit)
          end
        elseif not critical then
          -- When the event is a heal but it's not a critical heal.
          if amount > CritMaticData[spellName].highestHeal then
            CritMaticData[spellName].highestHeal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewHealMessage(spellName, amount)
            print("New highest normal heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHeal)
          end
        end
      elseif eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" then
        if critical then
          -- When the event is damage and it's a critical hit.
          if amount > CritMaticData[spellName].highestCrit then
            CritMaticData[spellName].highestCrit = amount
            PlaySound(888, "SFX")
            CritMatic.ShowNewCritMessage(spellName, amount)
            print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
          end
        elseif not critical then
          -- When the event is damage but it's not a critical hit.
          if amount > CritMaticData[spellName].highestNormal then
            CritMaticData[spellName].highestNormal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewNormalMessage(spellName, amount)
            print("New highest normal hit for " .. spellName .. ": " .. CritMaticData[spellName].highestNormal)
          end
        end
      end

    end

Last edited by Infinite-Loop-Alchemist : 07-29-23 at 08:42 AM.
  Reply With Quote
07-29-23, 10:52 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,831
Lua Code:
  1. elseif eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
  2.     spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
  3.     amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 18)

Pretty much the same problem (not differentiating correctly between swing and spell events). As well as the wrong positioning, here you're only retrieving args 15 to 18 and completely missing 20 and 21 (absorbed and critical)

Lua Code:
  1. elseif eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
  2.     spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
  3.     amount, overhealing,_ ,_ ,_ , absorbed, critical = unpack(eventInfo, 15, 21)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-30-23, 07:21 AM   #8
Infinite-Loop-Alchemist
A Murloc Raider
 
Infinite-Loop-Alchemist's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2023
Posts: 7
for heals its the 18th parameter for crits
1690725202.427 SPELL_HEAL false Player-4384-04EC1DF1 Cryptmender 1297 0 Player-4384-03104595 Sellys 66840 0 52985 Penance 2 4842 4842 0 true

from that site
Suffix 1st Param (15th) 2nd Param (16th) 3rd Param (17th) 4th Param (18th) 5th Param (19th) 6th Param (20th) 7th Param (21st) 8th Param (22nd) 9th Param (23rd) 10th Param (24th)
_DAMAGE amount overkill school resisted blocked absorbed critical glancing crushing isOffHand
_MISSED missType isOffHand amountMissed critical
_HEAL amount overhealing absorbed critical

i fixed that problem one more Issue. This code
Code:
-- Define a table to hold the highest hits data.
CritMaticData = CritMaticData or {}

local function GetGCD()
  local _, gcdDuration = GetSpellCooldown(78) -- 78 is the spell ID for Warrior's Heroic Strike
  if gcdDuration == 0 then
    return 1.5 -- Default GCD duration if not available (you may adjust this value if needed)
  else
    return gcdDuration
  end
end

local function AddHighestHitsToTooltip(self, slot)
  if (not slot) then
    return
  end

  local actionType, id = GetActionInfo(slot)
  if actionType == "spell" then
    local spellName, _, _, castTime = GetSpellInfo(id)
    if CritMaticData[spellName] then
      local cooldown = (GetSpellBaseCooldown(id) or 0) / 1000
      local effectiveCastTime = castTime > 0 and (castTime / 1000) or GetGCD()
      local effectiveTime = max(effectiveCastTime, cooldown)

      local critHPS = CritMaticData[spellName].highestHealCrit / effectiveTime
      local normalHPS = CritMaticData[spellName].highestHeal / effectiveTime
      local critDPS = CritMaticData[spellName].highestCrit / effectiveTime
      local normalDPS = CritMaticData[spellName].highestNormal / effectiveTime

      -- Your code here to display tooltip for healing spells
      local CritMaticHealLeft = "Highest Heal Crit: "
      local CritMaticHealRight = tostring(CritMaticData[spellName].highestHealCrit) .. " (" .. format("%.1f", critHPS) .. " HPS)"
      local normalMaticHealLeft = "Highest Heal Normal: "
      local normalMaticHealRight = tostring(CritMaticData[spellName].highestHeal) .. " (" .. format("%.1f", normalHPS) .. " HPS)"
      local CritMaticLeft = "Highest Crit: "
      local CritMaticRight = tostring(CritMaticData[spellName].highestHealCrit) .. " (" .. format("%.1f", critDPS) .. " DPS)"
      local normalMaticLeft = "Highest Normal: "
      local normalMaticRight = tostring(CritMaticData[spellName].highestHeal) .. " (" .. format("%.1f", normalDPS) .. " DPS)"

      -- Check if lines are already present in the tooltip.
      local critHealMaticExists = false
      local normalHealMaticExists = false
      local critMaticExists = false
      local normalMaticExists = false

      for i = 1, self:NumLines() do
        local gtl = _G["GameTooltipTextLeft" .. i]
        local gtr = _G["GameTooltipTextRight" .. i]

        if gtl and gtr then
          -- Healing related
          if gtl:GetText() == CritMaticHealLeft and gtr:GetText() == CritMaticHealRight then
            critHealMaticExists = true
          elseif gtl:GetText() == normalMaticHealLeft and gtr:GetText() == normalMaticHealRight then
            normalHealMaticExists = true
          end
          -- Damage related
          if gtl:GetText() == CritMaticLeft and gtr:GetText() == CritMaticRight then
            critDamageMaticExists = true
          elseif gtl:GetText() == normalMaticLeft and gtr:GetText() == normalMaticRight then
            normalDamageMaticExists = true
          end
        end
      end
        -- If lines don't exist, add them.
        if not critHealMaticExists then
          self:AddDoubleLine(CritMaticHealLeft, CritMaticHealRight)
          _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
          _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
        end

        if not normalHealMaticExists then
          self:AddDoubleLine(normalMaticHealLeft, normalMaticHealRight)
          _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
          _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
        end

        if not critMaticExists then
          self:AddDoubleLine(CritMaticLeft, CritMaticRight)
          _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
          _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
        end
      if not normalMaticExists then
        self:AddDoubleLine(normalMaticLeft, normalMaticRight)
        _G["GameTooltipTextLeft" .. self:NumLines()]:SetTextColor(1, 1, 1) -- left side color (white)
        _G["GameTooltipTextRight" .. self:NumLines()]:SetTextColor(1, 0.82, 0) -- right side color (white)
      end

      self:Show()
    end
  end
end

-- Register an event that fires when the player hits an enemy.
local f = CreateFrame("FRAME")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", function(self, event)

  -- Get information about the combat event.
  local eventInfo = { CombatLogGetCurrentEventInfo() }

  local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = unpack(eventInfo, 1, 11)
  local spellID, spellName, spellSchool, amount, overhealing, absorbed, critical

  if eventType == "SWING_DAMAGE" then
    spellName = "Auto Attack"
    spellID = 6603 -- or specify the path to a melee icon, if you have one
    amount, _, _, _, _, _, critical = unpack(eventInfo, 12, 18)
  elseif eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
    spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
    amount, overhealing, absorbed, critical = unpack(eventInfo, 15, 18)
  elseif eventType == "SPELL_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" then
    spellID, spellName, spellSchool = unpack(eventInfo, 12, 14)
    amount, overhealing, _, _, _, absorbed, critical = unpack(eventInfo, 15, 21)
  end
  --48071 Flash Heal 2 6569 6569 0 true
  --1690726298.925 SPELL_HEAL false Player-4384-04EC1DF1 Cryptmender 1297 0 Creature-0-4411-571-2846-32688-0000404538 Archmage Tenaj 68120 0 48071 Flash Heal 2 6536 6536 0 true
  --1617986113.264, "SPELL_DAMAGE", false, "Player-1096-06DF65C1", "Xiaohuli", 1297, 0, "Creature-0-4253-0-160-94-000070569B", "Cutpurse", 68168, 0, 585, "Smite", 2, 47, 19, 2, nil, nil, nil, false, false, false, false
  if sourceGUID == UnitGUID("player") and destGUID ~= UnitGUID("player") and (eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE" or eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" or eventType == "SPELL_PERIODIC_DAMAGE") and amount > 0 then
    if spellName then
      CritMaticData[spellName] = CritMaticData[spellName] or {
        highestCrit = 0,
        highestNormal = 0,
        highestHeal = 0,
        highestHealCrit = 0,
        spellIcon = GetSpellTexture(spellID)
      }

      --print(CombatLogGetCurrentEventInfo())

      if eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
        if critical then

          -- When the event is a heal and it's a critical heal.
          if amount > CritMaticData[spellName].highestHealCrit then
            CritMaticData[spellName].highestHealCrit = amount
            print("testing " .. spellName .. ": " .. CritMaticData[spellName].highestHealCrit)
            PlaySound(888, "SFX")
            CritMatic.ShowNewHealCritMessage(spellName, amount)
            print("New highest crit heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHealCrit)
          end
        elseif not critical then
          -- When the event is a heal but it's not a critical heal.
          if amount > CritMaticData[spellName].highestHeal then
            CritMaticData[spellName].highestHeal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewHealMessage(spellName, amount)
            print("New highest normal heal for " .. spellName .. ": " .. CritMaticData[spellName].highestHeal)
          end
        end
      elseif eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" then
        if critical then
          -- When the event is damage and it's a critical hit.
          if amount > CritMaticData[spellName].highestCrit then
            CritMaticData[spellName].highestCrit = amount
            PlaySound(888, "SFX")
            CritMatic.ShowNewCritMessage(spellName, amount)
            print("New highest crit hit for " .. spellName .. ": " .. CritMaticData[spellName].highestCrit)
          end
        elseif not critical then
          -- When the event is damage but it's not a critical hit.
          if amount > CritMaticData[spellName].highestNormal then
            CritMaticData[spellName].highestNormal = amount
            PlaySound(10049, "SFX")
            CritMatic.ShowNewNormalMessage(spellName, amount)
            print("New highest normal hit for " .. spellName .. ": " .. CritMaticData[spellName].highestNormal)
          end
        end
      end

    end
  end
end)

-- Register an event that fires when the addon is loaded.
local function OnLoad(self, event, addonName)
  if addonName == "CritMatic" then
    print("CritMatic Loaded!")

    CritMaticData = _G["CritMaticData"]

    -- Add the highest hits data to the spell button tooltip.
    hooksecurefunc(GameTooltip, "SetAction", AddHighestHitsToTooltip)
  end
end
local frame = CreateFrame("FRAME")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", OnLoad)

-- Register an event that fires when the player logs out or exits the game.
local function OnSave(self, event)
  -- Save the highest hits data to the saved variables for the addon.
  _G["CritMaticData"] = CritMaticData
end
local frame = CreateFrame("FRAME")
frame:RegisterEvent("PLAYER_LOGOUT")
frame:SetScript("OnEvent", OnSave)

local function ResetData()
  CritMaticData = {}
  print("CritMatic data reset.")
end

SLASH_CRITMATICRESET1 = '/cmreset'
function SlashCmdList.CRITMATICRESET(msg, editBox)
  ResetData()
end
The problem is the Tooltip displaying both heals and dps I need to make a
Code:
if
that only displays healcrits and normal heals only.

but I can think of some checks that would work but its out of scope.
Code:
if eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "SPELL_PERIODIC_DAMAGE" then
New to Lua and the WOW API I come from Javascript.

Last edited by Infinite-Loop-Alchemist : 07-30-23 at 12:19 PM.
  Reply With Quote
08-01-23, 01:06 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,831
One Possability, in your OnEvent you could do something like:

Lua Code:
  1. GameToolip.CritMaticDataShowHeals = nil
  2. if eventType == "xxx" or eventType == "yyy"  then
  3.     GameToolip.CritMaticDataShowHeals = true
  4. end

Then your Tooltip code could check for
Lua Code:
  1. self.CritMaticDataShowHeals

And if found, set whatever tooltp, clearing self.CritMaticDataShowHeals in the process if required.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-01-23 at 01:20 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » "SPELL_DAMAGE" and "SPELL_PERIODIC_DAMAGE" Crit bool is nil

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off