View Single Post
05-04-15, 11:22 AM   #1
zaifon
A Defias Bandit
Join Date: May 2015
Posts: 3
Issues regarding UNIT_SPELLCAST_SUCCEEDED

Hey,

Basically this is my first attempt at an addon, it's pretty basic and is supposed to show the amount of Chain Heal bounces for each cast, with multistrikes separated. I've got some previous programming experience, but this is the first time dabbling with Lua. I'll start with explaining the issue and then pasting in the code below.

The basic idea is two event listeners, one on UNIT_SPELLCAST_SUCCEEDED and then one on 'COMBAT_LOG_EVENT'. I think I've managed these ones pretty well, but the succeeded event fires before all the combat log collecting has been done. So I figured that the data gathering is taking too long and with no connection between the two events, they'll work asynchronously. Solution seems to be either to speed up the combat log events or make them fire off one another (somehow).

Here's the code:
Lua Code:
  1. -- Register Frame
  2. function CHC:registerFrame()
  3.     local CHCatcher_EventFrame = CreateFrame("Frame")
  4.     CHC:setEventHandlers(CHCatcher_EventFrame)
  5. end
  6.  
  7. -- Register Events
  8. function CHC:setEventHandlers(Catcher)
  9.     print("EventListener activated")
  10.     Catcher:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  11.     Catcher:RegisterEvent("COMBAT_LOG_EVENT")
  12.     CHC:handleEvents(Catcher)
  13. end
  14.  
  15. function CHC:handleEvents(Catcher)
  16.     Catcher:SetScript("OnEvent", function(self, event, ...)
  17.         if event == "UNIT_SPELLCAST_SUCCEEDED" then
  18.             CHC:spellCast_Succeeded(...)
  19.         elseif event == "COMBAT_LOG_EVENT" then
  20.             CHC:filterTheCombatLog(...)
  21.         end
  22.     end)
  23. end

With the successful cast function..

Lua Code:
  1. function CHC:spellCast_Succeeded(...)
  2.     local unitID, spell, rank, lineID, spellID = select(1, ...)
  3.  
  4.     -- Only do stuff on chain heal casts that succeed
  5.     if spellId == 1064 or spell == "Chain Heal" then
  6.         print("Finished casting " .. spell)
  7.     end
  8. end

And the combat log filtering.

Lua Code:
  1. function CHC:filterTheCombatLog(...)
  2.     local type = select(2, ...)
  3.  
  4.     -- Check if combat log event is a heal
  5.     if type == "SPELL_HEAL" then
  6.         local spellId, spellName, spellSchool = select(12, ...)
  7.  
  8.         -- If the heal event matches chain heal and all that.
  9.         if spellId == 1064 or spellName == "Chain Heal" then
  10.  
  11.             -- Check if the heal was a multistrike
  12.             -- Save those separately
  13.             if select(19, ...) == true then
  14.                 rawChainHealData.history.multistrikes = rawChainHealData.history.multistrikes + 1
  15.                 print("Multistrike #" .. rawChainHealData.history.multistrikes)
  16.             else
  17.                 rawChainHealData.history.targets = rawChainHealData.history.targets + 1
  18.                 print("Hit #" .. rawChainHealData.history.targets .. " at " .. select(1, ...))
  19.             end
  20.  
  21.             -- Save some of the data for later use.
  22.             local spellData = {
  23.                 timestamp = select(1, ...),
  24.                 target = select(9, ...),
  25.                 source = select(5, ...),
  26.                 amount = select(15, ...),
  27.                 overhealing = select(16, ...),
  28.                 multistrike = select(19, ...)
  29.             }
  30.             table.insert(rawChainHealData.history.data, spellData)
  31.         end
  32.     end
  33. end

Here's some sample output:


And full code can be viewed here (pastebin)

Thanks for your time!
  Reply With Quote