06-15-20, 10:20 AM | #1 |
Logging all XP gains
Hi all,
I am making a small addon for Classic that logs all XP gains to a SavedVariables file that I can then parse later for analysis. I am struggling a bit with the SavedVariables piece. Hoping someone can help. XPlogger.toc Lua Code:
main.lua Lua Code:
However, I am not seeing the SavedVariables file being written and the XPLogger.TotalXP is reset on /reload. Any help would be appreciated. |
|
06-15-20, 10:52 AM | #2 |
You need to wait until ADDON_LOADED until your savedvariables are available
https://wow.gamepedia.com/Saving_var..._game_sessions Something like this Lua Code:
|
|
06-15-20, 12:57 PM | #3 | |
i.e. Lua Code:
|
||
06-15-20, 01:25 PM | #4 |
Yes. It is generally preferred that you know what your saved variables are before you try to use them.
|
|
06-15-20, 01:44 PM | #5 |
06-15-20, 02:12 PM | #6 |
06-15-20, 02:33 PM | #7 | |
The last piece I think is now logging each XP gain in a table. Edit: All sorted. Sharing below for those interested. Lua Code:
Will now write a parser. Last edited by Adapt : 06-15-20 at 03:39 PM. |
||
06-16-20, 12:23 AM | #8 | |
|
||
06-16-20, 08:49 AM | #9 | |
Use at your own risk, I take no responsibility. Code:
private void Button_ParseFile(object sender, RoutedEventArgs e) { string fileToParse = SelectFile("Select file to parse", "lua", "lua files(*.lua) | *.lua"); if (fileToParse == null) return; string[] lines = File.ReadAllLines(fileToParse); // Regexes Regex TotalXPRegex = new Regex(@"(\d+)"); Regex CreatureRegex = new Regex(@".* = ""(.+)"""); Regex MinimapZoneRegex = new Regex(@".* = ""(.+)"""); Regex ZoneRegex = new Regex(@".* = ""(.+)"""); Regex LevelRegex = new Regex(@"(\d+)"); Regex TimeStampRegex = new Regex(@".* = ""(.+)"""); Regex QuestOrCreature = new Regex(@".* = ""(.+)"""); Regex XPGainedRegex = new Regex(@"(\d+)"); Regex EndOfIndividualGainRegex = new Regex(@"-- \[\d+\]"); var records = new List<XPLogger> { }; var record = new XPLogger(); foreach (string line in lines) { if (line.Contains("[\"Total XP\"]")) { Match match = TotalXPRegex.Match(line); record.TotalXP = Int16.Parse(match.Groups[1].Value); continue; } if (line.Contains("[\"Creature\"]")) { Match match = CreatureRegex.Match(line); record.Creature = match.Groups[1].Value; continue; } if (line.Contains("[\"Minimap Zone\"]")) { Match match = MinimapZoneRegex.Match(line); record.MinimapZone = match.Groups[1].Value; continue; } if (line.Contains("[\"Zone\"]")) { Match match = ZoneRegex.Match(line); record.Zone = match.Groups[1].Value; continue; } if (line.Contains("[\"Level\"]")) { Match match = LevelRegex.Match(line); record.Level = Int16.Parse(match.Groups[1].Value); continue; } if (line.Contains("[\"Timestamp\"]")) { Match match = TimeStampRegex.Match(line); record.TimeStamp = match.Groups[1].Value; continue; } if (line.Contains("[\"Quest or Creature\"]")) { Match match = QuestOrCreature.Match(line); record.QuestOrCreature = match.Groups[1].Value; continue; } if (line.Contains("[\"XP Gained\"]")) { Match match = XPGainedRegex.Match(line); record.XPGained = Int16.Parse(match.Groups[1].Value); continue; } if (EndOfIndividualGainRegex.IsMatch(line)) { records.Add(record); record = new XPLogger(); } } string newFile = SaveFile("Select file to output", "csv", "csv files(*.csv) | *.csv"); if (newFile == null) return; using (var writer = new StreamWriter(newFile)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) { csv.WriteRecords(records); } } |
||
06-16-20, 11:07 PM | #10 | |
|
||
06-20-20, 11:27 PM | #11 |
To continue with this thread, is there a way to catch XP awarded through exploring a new zone? Those don't seem to get captured by CHAT_MSG_COMBAT_XP_GAIN.
Thanks |
|
WoWInterface » Developer Discussions » Lua/XML Help » Logging all XP gains |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|