Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local NPC_Entry = 180001
- local T = {}
- function T.Load(pPlayer)
- T[tostring(pPlayer:GetGUID())] = {}
- local Query = WorldDBQuery("SELECT entry, name1 FROM items;")
- if(Query == nil) then
- return
- else
- for i = 1, Query:GetRowCount() do
- T[tostring(pPlayer:GetGUID())][i] = {Query:GetColumn(0):GetLong(), Query:GetColumn(1):GetString()}
- Query:NextRow()
- end
- end
- end
- function T.Hello(pUnit, event, pPlayer)
- pUnit:GossipCreateMenu(100, pPlayer, 0)
- T.Load(pPlayer)
- local GUID = tostring(pPlayer:GetGUID())
- for k,v in ipairs(T[GUID]) do
- pUnit:GossipMenuAddItem(0, v[2], k, 0, '', 0)
- if(k == 29) then
- pUnit:GossipMenuAddItem(7, "Next page", #T[GUID]+2, 0, '', 0)
- pUnit:GossipMenuAddItem(7, "Jump to page", #T[GUID]+math.floor(#T[GUID]/30)+2, 1, 'Jump to a page 1-'..math.floor(#T[GUID]/30)+1, 0)
- break
- end
- end
- pUnit:GossipSendMenu(pPlayer)
- end
- function T.Select(pUnit, event, pPlayer, id, intid, code)
- -- print(intid)
- local GUID = tostring(pPlayer:GetGUID())
- if(intid == #T[GUID]+1) then
- T.Hello(pUnit, event, pPlayer)
- return
- elseif(intid == #T[GUID]+math.floor(#T[GUID]/30)+2) then
- local code = tonumber(code)
- local A = false
- if(code == nil or code <= 0) then
- T.Hello(pUnit, event, pPlayer)
- return
- end
- local code = math.ceil(code)
- if(code > math.floor(#T[GUID]/30)+1) then
- T.Hello(pUnit, event, pPlayer)
- return
- end
- T.Select(pUnit, event, pPlayer, 0, #T[GUID]+code, 0)
- return
- elseif(intid > #T[GUID]) then
- pUnit:GossipCreateMenu(100, pPlayer, 0)
- local X = (30*(intid-#T[GUID]-1)) -- not sure what this was, but it seems important :3
- for i = X, #T[GUID] do
- pUnit:GossipMenuAddItem(0, T[GUID][i][2], i, 0, '', 0)
- if(i-X == 29) then
- if(i < #T[GUID]) then
- pUnit:GossipMenuAddItem(7, "Next page", intid+1, 0, '', 0)
- end
- break
- end
- end
- pUnit:GossipMenuAddItem(7, "Previous page", intid-1, 0, '', 0)
- pUnit:GossipSendMenu(pPlayer)
- else
- -- normal scripts.
- -- {
- -- example
- pPlayer:AddItem(T[GUID][intid][1], 1)
- -- }
- -- return to current menu, avoid glitch and dont exit gossip:
- if(intid < 30) then
- T.Hello(pUnit, event, pPlayer)
- else
- T.Select(pUnit, event, pPlayer, 0, math.floor(intid/30)+#T[GUID]+1, 0)
- end
- end
- end
- RegisterUnitGossipEvent(NPC_Entry, 1, T.Hello)
- RegisterUnitGossipEvent(NPC_Entry, 2, T.Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement