View Single Post
04-10-17, 08:54 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Tracking player's spell usage

Hi all,

Yeah... it's me again

For this time, I am trying to make an addon that tracks player's spell usage and here is what I have got so far.

Lua Code:
  1. local SkillFlow = CreateFrame("Frame");
  2. SkillFlow:RegisterEvent("PLAYER_REGEN_ENABLED");
  3. SkillFlow:RegisterEvent("PLAYER_REGEN_DISABLED");
  4. SkillFlow:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
  5.  
  6. SkillFlow.regenEnabled = true;
  7. SkillFlow.queue = {};
  8. SkillFlow.queueSize = 10;
  9.  
  10. function SkillFlow:PLAYER_REGEN_ENABLED()
  11.     self.regenEnabled = true;
  12. end
  13.  
  14. function SkillFlow:PLAYER_REGEN_DISABLED()
  15.     self.regenEnabled = false;
  16. end
  17.  
  18. function SkillFlow:OnEvent(event, ...)
  19.     self[event](self, event, ...);
  20. end
  21.  
  22. function SkillFlow:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
  23.     local _, subEvent, _, sourceGUID, _, _, _, _, _, _, _ = ...;
  24.  
  25.     if sourceGUID == UnitGUID("player") then
  26.         if subEvent == "SPELL_CAST_SUCCESS" and not self.regenEnabled then
  27.             local spellName = select(13, ...);
  28.            
  29.             if #self.queue < self.queueSize then
  30.                 table.insert(self.queue, spellName);
  31.             else
  32.                 for i = 1, #self.queue - 1 do
  33.                     self.queue[i] = self.queue[i + 1];
  34.                 end
  35.  
  36.                 self.queue[self.queueSize] = spellName;
  37.             end
  38.  
  39.             -- DUBUGGING ----------------------------------------
  40.             print("\n======== Skill Flow ========");
  41.             for i = 1, #self.queue do
  42.                 print(string.format("%d: %s", i, self.queue[i]));
  43.             end
  44.             print("============================");
  45.             -----------------------------------------------------
  46.         end
  47.     end
  48. end
  49.  
  50. SkillFlow:SetScript("OnEvent", SkillFlow.OnEvent);

There are basically two main problems that I am concerned:

1. The first spell fired before the combat won't be tracked and I know that is because of this line:

Code:
if type == "SPELL_CAST_SUCCESS" and not self.regenEnabled then
However, if I get rid of not self.regenEnabled, it even tracks for spell-casts done during non-combat situation.

2. Also tracks for spells fired via ExtraActionButton and so on. Since I am expecting to track player's spell only, I would like these kind of spells to be ignored.

In my personal opinion, COMBAT_LOG_EVENT (not COMBAT_LOG_EVENT_UNFILTERED) would do some job here, but I can't find further references regarding this.
(COMBAT_LOG_EVENT info page on wowwiki doesn't seem to cover this as well )

Any suggestions, please?

Thank you!
  Reply With Quote