Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ID = 36 -- NPC entry
- local Check = false -- true: Do not show items the player can't buy, false: show all vendor items in the list, even if the player does not have the mats.
- local T = {}
- T.Items =
- {
- -- {{GivenItem, Amount}, {ReqItem1, Amount}, {ReqItem2, Amount}, ... {ReqItemN, Amount}}
- {{25, 1}, {35, 1}},
- {{25, 1}, {36, 1}},
- {{25, 1}, {37, 1}},
- {{25, 1}, {38, 1}},
- {{25, 1}, {39, 1}},
- {{25, 2}, {40, 3}, {38, 1}, {39, 1}, {36, 4}}, -- Testing multiple req items
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{25, 1}, {40, 1}},
- {{35, 2}, {40, 1}}, -- Testing vendor with item entry 35
- }
- T.Page = {}
- T.Buy = {}
- T.Options = 20
- local X = 10
- function T.Count(Page)
- if(not Page or Page < 1) then
- return 1
- else
- return (Page*T.Options)
- end
- end
- function T.Max(Count, LData)
- if(LData - Count >= T.Options) then
- return Count+T.Options-1, true
- else
- return LData, false
- end
- end
- function T.Name(Entry)
- return WorldDBQuery("SELECT Name FROM item_template WHERE entry = "..Entry):GetString(0)
- end
- function T.Hello(event, player, creature)
- local Items = {}
- for k,v in ipairs(T.Items) do
- local Add = true
- for i = 2, #v do
- if(Check and (not player:HasItem(v[i][1]) or player:GetItemCount(v[i][1]) < v[i][2])) then
- Add = false
- break
- end
- end
- if(Add) then
- Items[#Items+1] = {k, v[1][1], v[1][2]}
- end
- end
- local str = tostring(player)
- if(not T.Page[str] or T.Page[str] < 0) then
- T.Page[str] = 0
- end
- local Page = T.Page[str]
- local Count = T.Count(Page)
- local Max, Next = T.Max(Count, #Items)
- if(Next) then
- player:GossipMenuAddItem(7, "Next page", 0, 3, false, '', 0)
- end
- if(Page > 0) then
- player:GossipMenuAddItem(7, "Previous page", 0, 4, false, '', 0)
- end
- player:GossipMenuAddItem(4, "Refresh", 0, 1, false, '', 0)
- player:GossipMenuAddItem(1, "Preview page's items", 0, X, false, '', 0)
- for k = Count, Max do
- local Amount = ""
- if(Items[k][3] > 1) then
- Amount = Items[k][3].." "
- end
- local Name = T.Name(Items[k][2])
- player:GossipMenuAddItem(3, Amount..Name, 0, X+Items[k][1], false, '', 0)
- end
- player:GossipSendMenu(100, creature)
- end
- function T.Select(event, player, creature, id, intid, code)
- local str = tostring(player)
- if(intid == 3) then
- T.Page[str] = T.Page[str] + 1
- elseif(intid == 4) then
- T.Page[str] = T.Page[str] - 1
- elseif(intid == 5) then
- print(event, player, creature, id, T.Buy[str], code)
- T.Select(666, player, creature, id, T.Buy[str], code)
- return
- elseif(intid == X) then
- player:GossipComplete()
- VendorRemoveAllItems(creature:GetEntry())
- local Items = {}
- for k,v in ipairs(T.Items) do
- local Add = true
- for i = 2, #v do
- if(Check and (not player:HasItem(v[i][1]) or player:GetItemCount(v[i][1]) < v[i][2])) then
- Add = false
- break
- end
- end
- if(Add) then
- Items[#Items+1] = v[1][1]
- end
- end
- local Page = T.Page[str]
- local Count = T.Count(Page)
- local Max, Next = T.Max(Count, #Items)
- for k = Count, Max do
- AddVendorItem(creature:GetEntry(), Items[k], -1, 0, 0)
- end
- player:SendListInventory(creature)
- return
- elseif(T.Items[intid-X]) then
- if(event ~= 666) then
- T.Buy[str] = intid
- player:SendBroadcastMessage("You need these items to purchase:")
- for i = 2, #T.Items[intid-X] do
- local Name = T.Name(T.Items[intid-X][i][1])
- player:SendBroadcastMessage(T.Items[intid-X][i][2].." \124cff00B0E4\124Hitem:"..T.Items[intid-X][i][1]..":0:0:0:0:0:0:0:0\124h["..Name.."]\124h\124r")
- end
- local Name = T.Name(T.Items[intid-X][1][1])
- player:GossipMenuAddItem(1, "Buy "..T.Items[intid-X][1][2].." "..Name, 0, 5, false, "Buying "..T.Items[intid-X][1][2].." "..Name.."!", 0)
- player:GossipMenuAddItem(6, "Show price", 0, intid, false, '', 0)
- player:GossipMenuAddItem(7, "Back..", 0, 1, false, '', 0)
- player:GossipSendMenu(100, creature)
- return
- else
- local intid = intid-X
- local Add = true
- for i = 2, #T.Items[intid] do
- if(not player:HasItem(T.Items[intid][i][1]) or player:GetItemCount(T.Items[intid][i][1]) < T.Items[intid][i][2]) then
- Add = false
- break
- end
- end
- if(Add) then
- local Done = 0
- for k = 1, T.Items[intid][1][2] do
- if(player:AddItem(T.Items[intid][1][1], 1)) then
- Done = Done + 1
- else
- -- player:RemoveItem(T.Items[intid][1][1], Done)
- player:SendAreaTriggerMessage("Your inventory is too full")
- break
- end
- end
- if(Done == T.Items[intid][1][2]) then
- for i = 2, #T.Items[intid] do
- player:RemoveItem(T.Items[intid][i][1], T.Items[intid][i][2])
- end
- else
- T.Select(0, player, creature, id, intid+X, code)
- return
- end
- else
- player:SendAreaTriggerMessage("You do not have the required items")
- if(not Check) then
- T.Select(0, player, creature, id, intid+X, code)
- return
- end
- end
- end
- end
- T.Hello(event, player, creature)
- end
- RegisterCreatureGossipEvent(ID, 1, T.Hello)
- RegisterCreatureGossipEvent(ID, 2, T.Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement