Quantcast
WoWInterface - View Single Post - Logging all XP gains
View Single Post
06-16-20, 12:23 AM   #8
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 454
Originally Posted by Adapt View Post
Thanks. Seems for some reason I needed to restart client, not just /reload.

The last piece I think is now logging each XP gain in a table.

Edit: All sorted. Sharing below for those interested.

Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2. local defaults = {
  3.     TotalXP = 0,
  4.     TotalXPEvents = 0,
  5.     IndividualGains = {},
  6. }
  7.  
  8. EventFrame:RegisterEvent("ADDON_LOADED")
  9. EventFrame:RegisterEvent("CHAT_MSG_COMBAT_XP_GAIN")
  10. EventFrame:SetScript("OnEvent",
  11.     function(self, event, ...)
  12.         if event == "CHAT_MSG_COMBAT_XP_GAIN" then
  13.             local arg1 = ...
  14.  
  15.             local DateTime = date("%d/%m/%y %H:%M:%S")
  16.             local XPGained = string.match(string.match(arg1, "%d+ experience"), "%d+")
  17.             local Creature = string.match(arg1, "(%a+) dies")
  18.             local QuestOrCreature = "Creature"
  19.             if Creature == nil then
  20.                 QuestOrCreature = "Quest"
  21.             end
  22.            
  23.             -- Increment number of XP events
  24.             CharacterDB.TotalXPEvents = CharacterDB.TotalXPEvents + 1
  25.             print('Total XP events ' .. CharacterDB.TotalXPEvents)
  26.        
  27.             -- Add to total XP gained
  28.             CharacterDB.TotalXP = CharacterDB.TotalXP + tonumber(XPGained)
  29.             print('Total XP ' .. CharacterDB.TotalXP)
  30.  
  31.             -- Setup table for new individual XP gain
  32.             local NewGain = {}
  33.             NewGain["Timestamp"] = DateTime
  34.             NewGain["XP Gained"] = XPGained
  35.             NewGain["Zone"] = GetZoneText()
  36.             NewGain["Minimap Zone"] = GetMinimapZoneText()
  37.             NewGain["Level"] = UnitLevel("player")
  38.             NewGain["Total XP"] = CharacterDB.TotalXP
  39.             NewGain["Quest or Creature"] = QuestOrCreature
  40.             NewGain["Creature"] = Creature
  41.  
  42.             -- Log individual XP gain statistics
  43.             table.insert(CharacterDB.IndividualGains, NewGain)
  44.  
  45.         elseif event == "ADDON_LOADED" then
  46.             local addon = ...
  47.             if addon == "XPLogger" then
  48.                 CharacterDB = CharacterDB or defaults
  49.                 print('----------------')
  50.                 print('XPLogger loaded')
  51.                 print('Total XP ' .. CharacterDB.TotalXP)
  52.                 print('Total XP events ' .. CharacterDB.TotalXPEvents)
  53.                 print('----------------')
  54.  
  55.                 self:UnregisterEvent(event)
  56.             end
  57.         end
  58.     end)

Will now write a parser.
I'd be interested in see your parser. I've been curious about parsing saved variables for a while.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote