View Single Post
04-16-24, 06:58 AM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 117
So it will be like this?
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. local frameName = "ZAMESTOTV_BUY299"
  4. if not _G[frameName] then
  5.     _G[frameName] = CreateFrame("Frame")
  6.     _G[frameName]:RegisterEvent("MERCHANT_SHOW")
  7. end
  8.  
  9. local vendors = {
  10.     ['Arvik'] = {['Skrog Liver Oil'] = true, },
  11.     ['Bukarakikk'] = {['Hunk o\' Blubber'] = true, },
  12.     ['Erugosa'] = {['Exquisite Ohn\'ahran Potato'] = true, ['Flaky Pastry Dough'] = true, ['Dark Thaldraszian Cocoa Powder'] = true, ['Four-Cheese Blend'] = true, },
  13.     ['Gracus'] = {['Greenberry'] = true, ['Fresh Dragon Fruit'] = true, ['Juicy Bushfruit'] = true, ['Dried Coldsnap Sagittate'] = true, },
  14.     ['Hanu'] = {['Eye of Bass'] = true, },
  15.     ['Head Chef Stacks'] = {['Rations: Scorpid Surprise'] = true, ['Rations: Undermine Clam Chowder'] = true, ['Rations: Westfall Stew'] = true, ['Rations: Dragonbreath Chili'] = true, },
  16.     ['Jinkutuk'] = {['Salted Fish Scraps'] = true, },
  17.     ['Junnik'] = {['Thousandbite Piranha Collar'] = true, },
  18.     ['Elder Nappa'] = {['Nappa\'s Famous Tea'] = true, },
  19.     ['Norukk'] = {['Norukk\'s "All-Purpose" Fish Powder'] = true, },
  20.     ['Qariin Dotur'] = {['Seven Spices Bruffalon'] = true, ['Dragonflame Argali'] = true, ['Thrice-Charred Mammoth Ribs'] = true, ['"Volcano" Duck'] = true, },
  21.     ['Patchu'] = {['Lunker Bits'] = true, },
  22.     ['Rokkutuk'] = {['Deepsquid Ink'] = true, },
  23.     ['Tattukiaka'] = {['Fermented Mackerel Paste'] = true, },
  24.     ['Tikukk'] = {['Island Crab Jerky'] = true, },
  25.     ['Tuukanit'] = {['Piping-Hot Orca Milk'] = true, },
  26. }  
  27.  
  28. local function PrintMessage(msg)
  29.     print("[ZAMESTOTV: Community Feast] " .. msg)
  30. end
  31.  
  32. local function BuyItemsFromVendor(vendorName)
  33.     local vendor = vendors[vendorName]
  34.     if not vendor then return end
  35.  
  36.     local numItems = GetMerchantNumItems()
  37.     for i = numItems, 1, -1 do
  38.         local name = GetMerchantItemInfo(i)
  39.         if vendor[name] then
  40.             local success = BuyMerchantItem(i)
  41.             if success then
  42.                 PrintMessage("Purchased: " .. name)
  43.             else
  44.                 PrintMessage("Failed to purchase: " .. name)
  45.             end
  46.         end
  47.     end
  48. end
  49.  
  50. local frame = _G[frameName]
  51. frame:SetScript("OnEvent", function(self, event, ...)
  52.     if IsShiftKeyDown() then return end
  53.    
  54.     local targetName = UnitName("target")
  55.     if not targetName then return end
  56.    
  57.     BuyItemsFromVendor(targetName)
  58. end)
  59.  
  60. local function AutoPurchaseSelectedItems()
  61.     local targetName = UnitName("target")
  62.     if not targetName then return end
  63.    
  64.     BuyItemsFromVendor(targetName)
  65. end
  66.  
  67. local function OnEvent(self, event, ...)
  68.     if event == "MERCHANT_SHOW" then
  69.         self:RegisterEvent("MERCHANT_UPDATE")
  70.     elseif event == "MERCHANT_UPDATE" then
  71.         self:UnregisterEvent(event)
  72.         AutoPurchaseSelectedItems()
  73.     end
  74. end
  75.  
  76. local eventWatcher = CreateFrame("Frame")
  77. eventWatcher:RegisterEvent("MERCHANT_SHOW")
  78. eventWatcher:SetScript("OnEvent", OnEvent)
  Reply With Quote