Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local T = {}
- T.Items =
- {
- -- {GivenItem, ReqItem1, ReqItem2, ... ReqItemN}
- {25, 35},
- {25, 36},
- {25, 37},
- {25, 38},
- {25, 39},
- {25, 40}, -- Testing paging with item entry 40
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {25, 40},
- {35, 40}, -- Testing vendor with item entry 35
- }
- T.Page = {}
- 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.Hello(pUnit, event, pPlayer)
- local Items = {}
- for k,v in ipairs(T.Items) do
- local Add = true
- for i = 2, #v do
- if(not pPlayer:HasItem(v[i])) then
- Add = false
- break
- end
- end
- if(Add) then
- Items[#Items+1] = {k,v[1]}
- end
- end
- local str = tostring(pPlayer)
- 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)
- pUnit:GossipCreateMenu(100, pPlayer, 0)
- if(Next) then
- pUnit:GossipMenuAddItem(7, "Next page", 3, 0, '', 0)
- end
- if(Page > 0) then
- pUnit:GossipMenuAddItem(7, "Previous page", 4, 0, '', 0)
- end
- pUnit:GossipMenuAddItem(4, "Refresh", 1, 0, '', 0)
- pUnit:GossipMenuAddItem(6, "Preview page's items", X, 0, '', 0)
- for k = Count, Max do
- local Name = WorldDBQuery("SELECT Name1 FROM items WHERE entry = "..Items[k][2]):GetColumn(0):GetString()
- pUnit:GossipMenuAddItem(0, Name, X+Items[k][1], 0, 'NOTE! You will lose the items required to buy this item.', 0)
- end
- pUnit:GossipSendMenu(pPlayer)
- end
- function T.Select(pUnit, event, pPlayer, id, intid, code)
- local str = tostring(pPlayer)
- if(intid == 3) then
- T.Page[str] = T.Page[str] + 1
- elseif(intid == 4) then
- T.Page[str] = T.Page[str] - 1
- elseif(intid == X) then
- pPlayer:GossipComplete()
- pUnit:VendorRemoveAllItems()
- local Items = {}
- for k,v in ipairs(T.Items) do
- local Add = true
- for i = 2, #v do
- if(not pPlayer:HasItem(v[i])) then
- Add = false
- break
- end
- end
- if(Add) then
- Items[#Items+1] = v[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
- pUnit:VendorAddItem(Items[k], -1, 0)
- end
- pPlayer:SendVendorWindow(pUnit)
- return
- elseif(T.Items[intid-X]) then
- local intid = intid-X
- local Add = true
- for i = 2, #T.Items[intid] do
- if(not pPlayer:HasItem(T.Items[intid][i])) then
- Add = false
- break
- end
- end
- if(Add) then
- if(pPlayer:AddItem(T.Items[intid][1], 1)) then
- for i = 2, #T.Items[intid] do
- pPlayer:RemoveItem(T.Items[intid][i], 1)
- end
- else
- pPlayer:SendAreaTriggerMessage("Your inventory is full")
- end
- else
- pPlayer:SendAreaTriggerMessage("You do not have the required items")
- end
- end
- T.Hello(pUnit, event, pPlayer)
- end
- local ID = 180001 -- NPC entry
- RegisterUnitGossipEvent(ID, 1, T.Hello)
- RegisterUnitGossipEvent(ID, 2, T.Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement