Thread Tools Display Modes
02-11-24, 05:20 AM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 109
How do I add 2 merchants?

Code:
local addonName, addon = ...
local frameName = "HUBB_BUY"
if not _G[frameName] then
    _G[frameName] = CreateFrame("Frame")
    _G[frameName]:RegisterEvent("MERCHANT_SHOW")
end

local function Set(list)
    local set = {}
    for _, l in ipairs(list) do set[l] = true end
    return set
end

local vendors = {
 [Tuukanit] = {Distilled Fish Juice, Improvised Sushi},
 [Elder Nappa] = {Distilled Fish Juice, Improvised Sushi}
  }

local function p(msg)
    print("[HUBB_AutoBuy] " .. msg)
end

local frame = _G[frameName]
frame:SetScript("OnEvent", function(self, event, ...)
    if IsShiftKeyDown() then return end
    
    local targetName = UnitName("target")
    if not targetName then return end
    local vendor = vendors[targetName]
    if not vendor then return end

    local numItems = GetMerchantNumItems()
    for i = numItems, 1, -1 do
        local name = GetMerchantItemInfo(i)
        if vendor[name] then
            p("Buying: " .. name)
            pcall(function() BuyMerchantItem(i) end)
        end
    end
    
    local count = 0
    frame:SetScript("OnUpdate", function(self)
        count = count + 1
        if count > 10 then
            CloseMerchant()
            frame:SetScript("OnUpdate", nil)
        end
    end)
end)
Code:
local vendors = {
 [Tuukanit] = {Distilled Fish Juice, Improvised Sushi},
 [Elder Nappa] = {Distilled Fish Juice, Improvised Sushi}
  }
It's about this piece. How to add 2 or more merchants. I don't understand, nothing works =(
  Reply With Quote
02-11-24, 10:46 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Lua Code:
  1. local vendors = {
  2.     [Tuukanit] = {Distilled Fish Juice, Improvised Sushi},
  3.     [Elder Nappa] = {Distilled Fish Juice, Improvised Sushi}
  4. }

Each key should be a string and each entry table (optional for the last) needs a comma at the end:

Lua Code:
  1. local vendors = {
  2.     ["Tuukanit"] = { ["Distilled Fish Juice"] = true, ["Improvised Sushi"] = true, },
  3.     ["Elder Nappa"] = { ["Distilled Fish Juice"] = true, ["Improvised Sushi"] = true, },
  4.     ["Fred Vendor"] = { ["Distilled Fish Juice"] = true, ["Improvised Sushi"] = true, },
  5.     ["Samantha Goods"] = { ["Distilled Fish Juice"] = true, ["Improvised Sushi"] = true, },
  6.     ["Trade Ya]" = { ["Distilled Fish Juice"] = true, ["Improvised Sushi"] = true, },
  7. }
if you just added the item string into the table as values it would be created as a number ordered table eg.

Lua Code:
  1. local vendors = {
  2.     ["Tuukanit"] = { "Distilled Fish Juice", "Improvised Sushi"], },
  3.     ["Elder Nappa"] = { "Distilled Fish Juice", "Improvised Sushi", },
  4.     ["Fred Vendor"] = { "Distilled Fish Juice", "Improvised Sushi", },
  5.     ["Samantha Goods"] = { "Distilled Fish Juice", "Improvised Sushi", },
  6.     ["Trade Ya]" = { "Distilled Fish Juice", "Improvised Sushi", },
  7. }

is the same as:

Lua Code:
  1. local vendors = {
  2.     ["Tuukanit"] = { [1] = "Distilled Fish Juice", [2] = "Improvised Sushi"], },
  3.     ["Elder Nappa"] = { [1] = "Distilled Fish Juice", [2] = "Improvised Sushi", },
  4.     ["Fred Vendor"] = { [1] = "Distilled Fish Juice", [2] = "Improvised Sushi", },
  5.     ["Samantha Goods"] = { [1] = "Distilled Fish Juice", [2] = "Improvised Sushi", },
  6.     ["Trade Ya]" = { [1] = "Distilled Fish Juice", [2] = "Improvised Sushi", },
  7. }
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-11-24 at 01:34 PM.
  Reply With Quote
02-12-24, 07:42 AM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 109
Thanks it works.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How do I add 2 merchants?


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