View Single Post
05-11-20, 11:50 AM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Okay .. after playing with my little project addon for a little while I came up with the following results.

Events:
AUCTION_HOUSE_BROWSE_RESULTS_UPDATED - Triggered when you click Search
AUCTION_HOUSE_NEW_RESULTS_RECEIVED - Triggered when you click on a specific item on the list


Functions:
local results = C_AuctionHouse.GetBrowseResults()
Used after AUCTION_HOUSE_BROWSE_RESULTS_UPDATED returns a table with the following as example entries
Lua Code:
  1. {
  2.             ["itemKey"] = {
  3.                 ["itemLevel"] = 0,
  4.                 ["itemSuffix"] = 0,
  5.                 ["itemID"] = 159827,
  6.                 ["battlePetSpeciesID"] = 0,
  7.             },
  8.             ["totalQuantity"] = 20,
  9.             ["minPrice"] = 100,
  10.             ["containsOwnerItem"] = false,
  11.         }, -- [4]
  12.         {
  13.             ["itemKey"] = {
  14.                 ["itemLevel"] = 1,
  15.                 ["itemSuffix"] = 0,
  16.                 ["itemID"] = 54456,
  17.                 ["battlePetSpeciesID"] = 0,
  18.             },
  19.             ["totalQuantity"] = 1,
  20.             ["minPrice"] = 100,
  21.             ["containsOwnerItem"] = false,
  22.         }, -- [16]


local itemKeyInfo = C_AuctionHouse.GetItemKeyInfo(itemKey)
Used after AUCTION_HOUSE_NEW_RESULTS_RECEIVED returns the following table
The following are two tables, one commodity, one item
Lua Code:
  1. {
  2.                     ["isPet"] = false,
  3.                     ["itemName"] = "Bomb-samdi Mojo Bombs",
  4.                     ["isCommodity"] = true,
  5.                     ["isEquipment"] = false,
  6.                     ["iconFileID"] = 463515,
  7.                     ["quality"] = 2,
  8.                 }, -- [2]
  9.  
  10.                 {
  11.                     ["isPet"] = false,
  12.                     ["itemName"] = "Mournful Essence",
  13.                     ["isCommodity"] = false,
  14.                     ["isEquipment"] = false,
  15.                     ["iconFileID"] = 132871,
  16.                     ["quality"] = 1,
  17.                 }, -- [2]


You can then use the following function to find out what auctions there are relating to that item

Lua Code:
  1. local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  2.             local separateOwnerItems = true
  3.             C_AuctionHouse.SendSearchQuery(itemKey, sorts, separateOwnerItems)

This then results in either an ITEM_SEARCH_RESULTS_UPDATED event call or COMMODITY_SEARCH_RESULTS_UPDATED event call.

For Items ..
Lua Code:
  1. local itemKey, auctionID = ...
  2.             local numResults = C_AuctionHouse.GetNumItemSearchResults(itemKey)
  3.             for index = 1, numResults do        
  4.                 local result = C_AuctionHouse.GetItemSearchResultInfo(itemKey, index)
  5.                 ....
  6.             end

Resulting in the following table contents
Lua Code:
  1. {
  2.                     ["itemKey"] = {
  3.                         ["itemLevel"] = 1,
  4.                         ["itemSuffix"] = 0,
  5.                         ["itemID"] = 54456,
  6.                         ["battlePetSpeciesID"] = 0,
  7.                     },
  8.                     ["containsOwnerItem"] = false,
  9.                     ["buyoutAmount"] = 100,
  10.                     ["itemLink"] = "|cffffffff|Hitem:54456::::::::110:264::::::|h[Mournful Essence]|h|r",
  11.                     ["quantity"] = 1,
  12.                     ["containsSocketedItem"] = false,
  13.                     ["owners"] = {
  14.                         "Riannia", -- [1]
  15.                     },
  16.                     ["containsAccountItem"] = false,
  17.                     ["timeLeft"] = 2,
  18.                     ["auctionID"] = 2092193565,
  19.                 }, -- [1]


For Commodities ..
Lua Code:
  1. local itemID = ...
  2.             local numResults = C_AuctionHouse.GetNumCommoditySearchResults(itemID)
  3.             for index = 1,numResults do
  4.                 local result = C_AuctionHouse.GetCommoditySearchResultInfo(itemID, index)
  5.                 ....
  6.             end

Which results in the following table of data
Lua Code:
  1. {
  2.                     ["containsOwnerItem"] = false,
  3.                     ["timeLeftSeconds"] = 27423,
  4.                     ["quantity"] = 20,
  5.                     ["itemID"] = 159827,
  6.                     ["owners"] = {
  7.                         "Galdrena", -- [1]
  8.                         "Rhys", -- [2]
  9.                     },
  10.                     ["unitPrice"] = 100,
  11.                     ["containsAccountItem"] = false,
  12.                     ["numOwnerItems"] = 0,
  13.                     ["auctionID"] = 2092122023,
  14.                 }, -- [1]

It is then the case of accessing the table contents as per normal for display purposes.

This of course still relies on you making that initial search and clicking the button and isn't automated at all. I suspect there is a way of doing this periodically using other functions. But whichever way you use auction house api ( if there is more than one way ) you will ultimately end up with repeating event calls for commodity and item updates after you have requested an auction search query.

I then added the following to automate searching for a specific set of items and then one of the items in the list generated.. it didn't work quite right but will give an idea of what is possible but it does mean you don't have to click and select to get information out. You just have to have opened the auction house window to start it off.

Lua Code:
  1. if event == "AUCTION_HOUSE_SHOW" then  
  2.  
  3.         local searchString = "Netherweave"
  4.         local minLevel = nil
  5.         local maxLevel = nil
  6.         local filtersArray = nil
  7.         local filterData = { classID = LE_ITEM_CLASS_CONTAINER, subClassID = nil, inventoryType = nil }
  8.         local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  9.        
  10.         local query = {};
  11.         query.searchString = searchString;
  12.         query.minLevel = minLevel;
  13.         query.maxLevel = maxLevel;
  14.         query.filters = filtersArray;
  15.         query.itemClassFilters = filterData;
  16.         query.sorts = sorts
  17.        
  18.         XrystalUI_Auctioneer_Info = {}
  19.         print("Sending Browse Query Automatically")
  20.         C_AuctionHouse.SendBrowseQuery(query);        
  21.        
  22.     elseif event == "AUCTION_HOUSE_BROWSE_RESULTS_UPDATED" then
  23.        
  24.         -- Get the first 500 items
  25.         local results = C_AuctionHouse.GetBrowseResults()
  26.        
  27.          local itemKey = results[1].itemKey
  28.          local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  29.          local separateOwnerItems = true
  30.          print("Automatically searching for item ", itemKey)
  31.          C_AuctionHouse.SendSearchQuery(itemKey, sorts, separateOwnerItems)
  32.                
  33.         -- Store for later retrieval
  34.         XrystalUI_Auctioneer_Info["BrowseResults"] = results



So my final version of my addon file is as follows:
Lua Code:
  1. XrystalUI_Auctioneer_Info = XrystalUI_Auctioneer_Info or {}
  2.  
  3. local function OnEvent(self, event, ...)
  4.    
  5.     if event == "AUCTION_HOUSE_SHOW" then  
  6.  
  7.         local searchString = "Netherweave"
  8.         local minLevel = nil
  9.         local maxLevel = nil
  10.         local filtersArray = nil
  11.         local filterData = { classID = LE_ITEM_CLASS_CONTAINER, subClassID = nil, inventoryType = nil }
  12.         local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  13.        
  14.         local query = {};
  15.         query.searchString = searchString;
  16.         query.minLevel = minLevel;
  17.         query.maxLevel = maxLevel;
  18.         query.filters = filtersArray;
  19.         query.itemClassFilters = filterData;
  20.         query.sorts = sorts
  21.        
  22.         XrystalUI_Auctioneer_Info = {}
  23.         print("Sending Browse Query Automatically")
  24.         C_AuctionHouse.SendBrowseQuery(query);        
  25.        
  26.     elseif event == "AUCTION_HOUSE_BROWSE_RESULTS_UPDATED" then
  27.        
  28.         -- Get the first 500 items
  29.         local results = C_AuctionHouse.GetBrowseResults()
  30.        
  31.          local itemKey = results[1].itemKey
  32.          local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  33.          local separateOwnerItems = true
  34.          print("Automatically searching for item ", itemKey)
  35.          C_AuctionHouse.SendSearchQuery(itemKey, sorts, separateOwnerItems)
  36.        
  37.        
  38.         -- Store for later retrieval
  39.         XrystalUI_Auctioneer_Info["BrowseResults"] = results
  40.        
  41.     elseif event == "AUCTION_HOUSE_NEW_RESULTS_RECEIVED" then
  42.         local itemKey = ...
  43.         if ( itemKey ) then
  44.            
  45.             -- Retrieve Info about this item
  46.             local itemKeyInfo = C_AuctionHouse.GetItemKeyInfo(itemKey)
  47.            
  48.             -- Store for later retrieval
  49.             XrystalUI_Auctioneer_Info["NewResults"] = XrystalUI_Auctioneer_Info["NewResults"] or {}
  50.             XrystalUI_Auctioneer_Info["NewResults"]["itemKey"] = {}
  51.             XrystalUI_Auctioneer_Info["NewResults"]["itemKey"].Key = itemKey
  52.             XrystalUI_Auctioneer_Info["NewResults"]["itemKey"].Info = itemKeyInfo
  53.            
  54.             -- Request more details about this item's auctions
  55.             local sorts = { sortOrder = Enum.AuctionHouseSortOrder.Price, reverseSort = false }
  56.             local separateOwnerItems = true
  57.             C_AuctionHouse.SendSearchQuery(itemKey, sorts, separateOwnerItems)
  58.            
  59.         end
  60.        
  61.     elseif event == "ITEM_SEARCH_RESULTS_UPDATED" then
  62.         local itemKey, auctionID = ...
  63.         local itemID = itemKey.itemID
  64.         if itemKey then
  65.            
  66.             -- Get the number of auctions for this itemKey
  67.             local numResults = C_AuctionHouse.GetNumItemSearchResults(itemKey)
  68.  
  69.             -- Store for later retrieval
  70.             XrystalUI_Auctioneer_Info["ItemSearchResults"] = XrystalUI_Auctioneer_Info["ItemSearchResults"] or {}
  71.             XrystalUI_Auctioneer_Info["ItemSearchResults"][itemID] = {}
  72.             XrystalUI_Auctioneer_Info["ItemSearchResults"][itemID].itemKey = itemKey
  73.             XrystalUI_Auctioneer_Info["ItemSearchResults"][itemID].auctionID = auctionID
  74.             XrystalUI_Auctioneer_Info["ItemSearchResults"][itemID].Auctions = {}
  75.  
  76.             -- Get the auction entries for this item
  77.             for index = 1, numResults do        
  78.                 local result = C_AuctionHouse.GetItemSearchResultInfo(itemKey, index)
  79.                
  80.                 -- Add this entry to our list of auctions
  81.                 table.insert(XrystalUI_Auctioneer_Info["ItemSearchResults"][itemID].Auctions,result)
  82.             end
  83.  
  84.            
  85.         end
  86.                
  87.     elseif event == "COMMODITY_SEARCH_RESULTS_UPDATED" then
  88.         local itemID = ...
  89.         if itemID then
  90.            
  91.             -- Get the number of auctions for this commodity item
  92.             local numResults = C_AuctionHouse.GetNumCommoditySearchResults(itemID)
  93.            
  94.             -- Store for later retrieval
  95.             XrystalUI_Auctioneer_Info["CommoditiesSearchResults"] = XrystalUI_Auctioneer_Info["CommoditiesSearchResults"] or {}
  96.             XrystalUI_Auctioneer_Info["CommoditiesSearchResults"][itemID] = {}
  97.             XrystalUI_Auctioneer_Info["CommoditiesSearchResults"][itemID].Auctions = {}
  98.            
  99.             -- Get the auction entries for this commodity
  100.             for index = 1,numResults do
  101.                 local result = C_AuctionHouse.GetCommoditySearchResultInfo(itemID, index)
  102.                 table.insert(XrystalUI_Auctioneer_Info["CommoditiesSearchResults"][itemID].Auctions,result)
  103.             end
  104.         end
  105.     end
  106. end
  107.  
  108. local f = CreateFrame("Frame")
  109. f:RegisterEvent("AUCTION_HOUSE_SHOW")
  110. f:RegisterEvent("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED")
  111. f:RegisterEvent("AUCTION_HOUSE_NEW_RESULTS_RECEIVED") -- [itemKey]
  112. f:RegisterEvent("ITEM_SEARCH_RESULTS_UPDATED")
  113. f:RegisterEvent("COMMODITY_SEARCH_RESULTS_UPDATED")
  114. f:SetScript("OnEvent", OnEvent)

Hopefully this will help lead you to identifying what you need to do to make your addon work as close to its original design as possible. Printing out the results are as simple as accessing the relevant part of the table returned.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote