Thread Tools Display Modes
04-15-21, 07:14 AM   #1
max291
A Defias Bandit
Join Date: Apr 2021
Posts: 3
How does C_EncounterJournal work?

If I run this piece of code:

EJ_SelectInstance(1182)
numLoot = EJ_GetNumLoot()

for i = 1, numLoot do
itemInfo = C_EncounterJournal.GetLootInfoByIndex(i)
end

it only works after I reload my UI. So I start WoW, I get a lua error, then I reload, and now it works until I restart WoW. Why? How do I make it work without the need of reloading?

What I try to accomplish is: I want to select armour-type and stats to get items that match the stats I want. Everything works fine, except the return of items on the "first load".

People on the Discord don't seem to understand me, so I thought I might give this forum a try.
  Reply With Quote
04-15-21, 11:02 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
At what point are you running that code ? It might be that the information you are asking for isn't available at login but is available by the time the player is entering the world.

What event are you watching for before you use that code segment ?


Also, it might need the EncounterJourmal loaded ( I think its a blizzard addon) before it will work. Yes it is Blizzard_EncounterJournal. Have that as a pre-requisite of your addon so that it loads before your addon does and things may work then.
__________________

Last edited by Xrystal : 04-15-21 at 11:06 AM.
  Reply With Quote
04-15-21, 11:56 AM   #3
max291
A Defias Bandit
Join Date: Apr 2021
Posts: 3
I am running that code when someone selects via a drop-down menu what he/she looks for. So its not executed right away.

I also tried this "LoadAddOn("Blizzard_EncounterJournal")", but it didn't work.

It indeed seems to have some trouble loading the Journal because when friends test it, it usually works. I assume they have already looked or opened the journal so it's already loaded.
  Reply With Quote
04-15-21, 12:02 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Hmm can't see why it wouldn't work if it is only actioned after LoadAddOn is called and the user has interacted with the game.
__________________
  Reply With Quote
04-15-21, 12:30 PM   #5
max291
A Defias Bandit
Join Date: Apr 2021
Posts: 3
Ok, thanks for clarifying that it should work, I will play around then and see if I can get it to work.
  Reply With Quote
04-15-21, 12:53 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Originally Posted by max291 View Post
Ok, thanks for clarifying that it should work, I will play around then and see if I can get it to work.
Just having a try myself to see if I can see the problem you're having or have it working straight away.

Okay, first attempt using it as a required addon in the TOC came up with the following error with the journal.

Code:
3x ...s\Blizzard_EncounterJournal\Blizzard_LootJournal.lua:158: Usage: GetSpecializationInfoForSpecID(specID[,sex])
[string "=[C]"]: in function `GetSpecializationNameForSpecID'
[string "@Blizzard_EncounterJournal\Blizzard_LootJournal.lua"]:158: in function `GetClassButtonText'
[string "@Blizzard_EncounterJournal\Blizzard_LootJournal.lua"]:165: in function `UpdateClassButtonText'
[string "@Blizzard_EncounterJournal\Blizzard_LootJournal.lua"]:202: in function `SetClassAndSpecFilters'
[string "@Blizzard_EncounterJournal\Blizzard_LootJournal.lua"]:62: in function <...s\Blizzard_EncounterJournal\Blizzard_LootJournal.lua:61>

Locals:
(*temporary) = nil
I am assuming this is because when people click to open the Encounter Journal manually the right values are being set for the information inside to be available.

So, time to check the EncounterJournal code to see what else it does before showing the journal itself.
__________________

Last edited by Xrystal : 04-15-21 at 01:02 PM.
  Reply With Quote
04-15-21, 03:53 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
This is about the best I could do.

It seems that when you first request a look up it doesn't get it all even on callback. However, another request a short time later it will work. I tried to request it a second time on callback but it still doesn't work. But requesting it manually it does.

However, you could use the callback that returns the items ID to use the item functions GetItemInfo(itemID) to get the item details.

What the Encounter Journal does is look at the scroll list in the encounter journal for that itemID to get the index in the encounter for that item to get the original index. I tried to simulate this by storing the last index requested but it didn't work.

When it successfully finds the items and their details using the Encounter Loot function it returns a handful of items ranging from greens, blues, even oranges. However, when it didn't succeed and the event callback had to be used, the items returned at that point are the ones from the original list but also others that weren't in that initial list. This could be because of the waiting time that is in place so maybe some were ready immediately and others weren't. Saving to a savedvariables file to see if the same items do eventually appear with their details may be useful.

Anyway give this a play for testing purposes and change it to fit your requirements. At least until someone comes along with a better solution

Lua Code:
  1. local frame = CreateFrame("Frame")
  2.  
  3. local function ReportInstanceInfo(info)
  4.     if info then
  5.         print(info.itemID,info.name,info.link)
  6.     end
  7. end
  8.  
  9. local function GetInstanceLoot(instanceID)
  10.     EJ_SelectInstance(instanceID)
  11.     local numLoot = EJ_GetNumLoot()
  12.     local itemInfo = {}
  13.     for i = 1, numLoot do
  14.         local itemInfo = C_EncounterJournal.GetLootInfoByIndex(i)
  15.         if itemInfo.name then
  16.             print("Loot Data Available Now: ")
  17.             ReportInstanceInfo(itemInfo)
  18.         else
  19.             print("Waiting for Loot Data: ")
  20.         end
  21.     end
  22. end
  23.  
  24. local function SlashCommands(msg, editbox)
  25.     local emptyvar,emptyvar, cmd, args = string.find(msg, "%s?(%w+)%s?(.*)")
  26.     if cmd == "inst" then
  27.         GetInstanceLoot(args)
  28.     elseif cmd == "help" then
  29.         print("Syntax: /xls (help/inst ####)")
  30.     end
  31. end
  32. SLASH_XLS1, SLASH_XLS2 = '/xls', '/xui_lootsearcher'
  33. SlashCmdList["XLS"] = SlashCommands
  34.  
  35.  
  36. frame:RegisterEvent("ADDON_LOADED")
  37. frame:RegisterEvent("EJ_LOOT_DATA_RECIEVED")           
  38. frame:SetScript("OnEvent",function(self,event,...)
  39.     local args = { ... }
  40.     if event == "EJ_LOOT_DATA_RECIEVED" then
  41.         print("Loot Data Received: ",args[1])
  42.         local itemID = args[1]
  43.         if itemID then
  44.             local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
  45. itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expacID, setID, isCraftingReagent
  46.    = GetItemInfo(itemID)
  47.             print(itemID,itemName,itemLink)
  48.         end
  49.     end
  50. end)
__________________
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How does C_EncounterJournal work?

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