View Single Post
12-12-20, 02:19 AM   #2
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
You need to register yourself for the AH events
I copy paste my code

-- AH events
self:RegisterEvent("AUCTION_HOUSE_CLOSED");
self:RegisterEvent("AUCTION_HOUSE_SHOW");

self:RegisterEvent("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED");
self:RegisterEvent("ITEM_SEARCH_RESULTS_UPDATED");
self:RegisterEvent("COMMODITY_SEARCH_RESULTS_UPDATED");

if ( event == "AUCTION_HOUSE_BROWSE_RESULTS_UPDATED" ) then
--AHB_Data["function LogTextLine"](event);
local bri = C_AuctionHouse.GetBrowseResults();
local tempBrowseResults= { };
for _, v in pairs(bri) do
local ik = v["itemKey"];
local id = ik["itemID"];
local ilvl = ik["itemLevel"];
local iki = C_AuctionHouse.GetItemKeyInfo(ik);
local itemName = nil;
if ( iki ) then itemName = iki["itemName"]; end
local q = v["totalQuantity"];
local p = v["minPrice"];
if ( itemName ) then
AHB_Data["function LogTextLine"](string.format("browse results updated - id:[%d] - ilvl:[%d] - name:[%s] - q:[%.2f] - p:[%.2f]",id,ilvl,itemName,q,p));
if ( ahBrowseResultsNew[itemName] == nil ) then ahBrowseResultsNew[itemName] = {}; end
local silvl = string.format("%d",ilvl);
ahBrowseResultsNew[itemName][silvl] = { id, ilvl, itemName, q, p };
-- if we have directly enquired for this item, mark it as done
--if ( ahBrowseResults[itemName] ) then
-- ahBrowseResults[itemName][silvl] = { 0 };
--end
-- if we are refreshing the list from Excel
-- clear out this entry so we do nto ask again
-- this may not work for entries with multiple ilvls
if ( #ahAuctionHouseListItemsFromExcel > 0 ) then
for i=1, #ahAuctionHouseListItemsFromExcel do
if ( ahAuctionHouseListItemsFromExcel[i] == itemName ) then
AHB_Data["function LogTextLine"](string.format("clearing excel item list query - name:[%s] ilvl:[%d]",itemName,ilvl));
ahAuctionHouseListItemsFromExcel[i] = "";
break;
end
end
end -- manual update from excel
end -- if itemName
end -- for all browse results in list
end

if ( event == "ITEM_SEARCH_RESULTS_UPDATED" ) then
--AHB_Data["function LogTextLine"](event);
local ik = ...;
--for k,v in pairs(ik) do
-- AHB_Data["function LogTextLine"](string.format("%s - [%s]",tostring(k),tostring(v)));
--end
local id = ik["itemID"];
-- 6/12/2020 - bug where ilvl is 0 for an item
-- if ilvl = 0 we cannot enter it into our tables
local ilvl = ik["itemLevel"];
-- local isuffix = ik["itemSuffix"];
local iki = C_AuctionHouse.GetItemKeyInfo(ik);
--for k,v in pairs(iki) do
-- AHB_Data["function LogTextLine"](string.format("%s - [%s]",tostring(k),tostring(v)));
--end
local itemName = nil;
if ( iki ) then itemName = iki["itemName"]; end
--AHB_Data["function LogTextLine"](string.format("%s - id:[%d] name:[%s] ilvl:[%d]",event,id,tostring(itemName),ilvl));
local numResults = C_AuctionHouse.GetNumItemSearchResults(ik);
-- weird case getting 0 results
if ( itemName and ilvl > 0 and numResults > 0 ) then
-- in the same list we assume ilvl is the same
-- and depending on sort order we need to get smallest price
local minPrice = -1;
local qAtMinPrice = 0;
for i = 1, numResults do
local v = C_AuctionHouse.GetItemSearchResultInfo( ik, i );
local q = v["quantity"];
local p = v["buyoutAmount"];
if ( minPrice == -1 or p < minPrice ) then minPrice = p; qAtMinPrice = q; end
end
AHB_Data["function LogTextLine"](string.format("item search updated - id:[%d] - ilvl:[%d] - name:[%s] - q:[%.2f] - p:[%.2f]",id,ilvl,itemName,qAtMinPrice,minPrice));
if ( ahBrowseResultsNew[itemName] == nil ) then ahBrowseResultsNew[itemName] = {}; end
local silvl = string.format("%d",ilvl);
ahBrowseResultsNew[itemName][silvl] = { id, ilvl, itemName, qAtMinPrice, minPrice };
end
end

-- [====[
if ( event == "COMMODITY_SEARCH_RESULTS_UPDATED" ) then
--AHB_Data["function LogTextLine"](event);
local id = ...;
local ik = C_AuctionHouse.MakeItemKey(id);
local ilvl = ik["itemLevel"];
--local ilvl = 1; -- hardcode ilvl 1 for commodities
local iki = C_AuctionHouse.GetItemKeyInfo(ik);
local itemName = nil;
if ( iki ) then itemName = iki["itemName"]; end
local numResults = C_AuctionHouse.GetNumCommoditySearchResults(id);
if ( itemName and numResults > 0 ) then
local minPrice = -1;
local qAtMinPrice;
for i = 1, numResults do
local v = C_AuctionHouse.GetCommoditySearchResultInfo( id, i );
local id2 = v["itemID"];
q = v["quantity"];
local p = v["unitPrice"];
if ( minPrice == -1 or p < minPrice ) then minPrice = p; qAtMinPrice = q; end
end
AHB_Data["function LogTextLine"](string.format("commodity search updated - id:[%d] - ilvl:[%d] - name:[%s] - q:[%.2f] - p:[%.2f]",id,ilvl,itemName,qAtMinPrice,minPrice));
if ( ahBrowseResultsNew[itemName] == nil ) then ahBrowseResultsNew[itemName] = {}; end
local silvl = string.format("%d",ilvl);
ahBrowseResultsNew[itemName][silvl] = { id, ilvl, itemName, qAtMinPrice, minPrice };
end
end
--]====]
  Reply With Quote