Not quite - I wasn't sure what the following was for so my updated version doesn't have it in
Lua Code:
if IsShiftKeyDown() then return end
Give this a go. As a reminder, event watching only frames technically don't need to be named.
I have clearly separated the sections of the code you posted so that it makes it easier to see which items you can put in separate files if and when you need to. At the moment it's small enough in the one file.
Lua Code:
local addonName, addon = ...
---------------------------
-- Vendor Related Set up --
---------------------------
local vendors = {
['Arvik'] = {['Skrog Liver Oil'] = true, },
['Bukarakikk'] = {['Hunk o\' Blubber'] = true, },
['Erugosa'] = {['Exquisite Ohn\'ahran Potato'] = true, ['Flaky Pastry Dough'] = true, ['Dark Thaldraszian Cocoa Powder'] = true, ['Four-Cheese Blend'] = true, },
['Gracus'] = {['Greenberry'] = true, ['Fresh Dragon Fruit'] = true, ['Juicy Bushfruit'] = true, ['Dried Coldsnap Sagittate'] = true, },
['Hanu'] = {['Eye of Bass'] = true, },
['Head Chef Stacks'] = {['Rations: Scorpid Surprise'] = true, ['Rations: Undermine Clam Chowder'] = true, ['Rations: Westfall Stew'] = true, ['Rations: Dragonbreath Chili'] = true, },
['Jinkutuk'] = {['Salted Fish Scraps'] = true, },
['Junnik'] = {['Thousandbite Piranha Collar'] = true, },
['Elder Nappa'] = {['Nappa\'s Famous Tea'] = true, },
['Norukk'] = {['Norukk\'s "All-Purpose" Fish Powder'] = true, },
['Qariin Dotur'] = {['Seven Spices Bruffalon'] = true, ['Dragonflame Argali'] = true, ['Thrice-Charred Mammoth Ribs'] = true, ['"Volcano" Duck'] = true, },
['Patchu'] = {['Lunker Bits'] = true, },
['Rokkutuk'] = {['Deepsquid Ink'] = true, },
['Tattukiaka'] = {['Fermented Mackerel Paste'] = true, },
['Tikukk'] = {['Island Crab Jerky'] = true, },
['Tuukanit'] = {['Piping-Hot Orca Milk'] = true, },
}
-----------------------
-- Utility Functions --
-----------------------
local function PrintMessage(msg)
print("[ZAMESTOTV: Community Feast] " .. msg)
end
--------------------------------
-- The actual purchasing part --
--------------------------------
local function BuyItemsFromVendor(vendorName)
local vendor = vendors[vendorName]
if not vendor then return end
local numItems = GetMerchantNumItems()
for i = numItems, 1, -1 do
local name = GetMerchantItemInfo(i)
if vendor[name] then
local success = BuyMerchantItem(i)
if success then
PrintMessage("Purchased: " .. name)
else
PrintMessage("Failed to purchase: " .. name)
end
end
end
end
----------------------
-- Event Management --
----------------------
local function AutoPurchaseSelectedItems()
local targetName = UnitName("target")
if not targetName then return end
BuyItemsFromVendor(targetName)
end
local function OnEvent(self, event, ...)
if event == "MERCHANT_SHOW" then
self:RegisterEvent("MERCHANT_UPDATE")
elseif event == "MERCHANT_UPDATE" then
self:UnregisterEvent(event)
AutoPurchaseSelectedItems()
end
end
local eventWatcher = CreateFrame("Frame")
eventWatcher:RegisterEvent("MERCHANT_SHOW")
eventWatcher:SetScript("OnEvent", OnEvent)