Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. -- Copyright (c) 2019 "Cowboy" Ben Alman
  2. -- Licensed under the MIT license
  3.  
  4. local frameName = "CB_VENDOR_AUTO_BUY_FRAME"
  5. if not _G[frameName] then
  6. _G[frameName] = CreateFrame("Frame")
  7. _G[frameName]:RegisterEvent("MERCHANT_SHOW")
  8. end
  9.  
  10. local function Set(list)
  11. local set = {}
  12. for _, l in ipairs(list) do set[l] = true end
  13. return set
  14. end
  15.  
  16. local vendors = {
  17. ["Qia"] = Set {
  18. "Pattern: Runecloth Gloves",
  19. "Pattern: Runecloth Bag"
  20. }
  21. }
  22.  
  23. local function p(msg)
  24. print("[CB_VendorAutoBuy] " .. msg)
  25. end
  26.  
  27. local frame = _G[frameName]
  28. frame:SetScript("OnEvent", function(self, event, ...)
  29. if IsShiftKeyDown() then return end
  30.  
  31. local targetName = UnitName("target")
  32. if not targetName then return end
  33. local vendor = vendors[targetName]
  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. p("Buying: " .. name)
  41. pcall(function() BuyMerchantItem(i) end)
  42. end
  43. end
  44.  
  45. local count = 0
  46. frame:SetScript("OnUpdate", function(self)
  47. count = count + 1
  48. if count > 10 then
  49. CloseMerchant()
  50. frame:SetScript("OnUpdate", nil)
  51. end
  52. end)
  53. end)
  54.  
  55. p("loaded!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement