Advertisement
Rochet2

Untitled

Jan 2nd, 2012
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. local T = {}
  2. T.Items =
  3. {
  4. --  {GivenItem, ReqItem1, ReqItem2, ... ReqItemN}
  5.     {25, 35, 36},
  6.     {25, 37, 38, 39},
  7.     {25, 40},
  8.     {25, 41},
  9. }
  10.  
  11. T.Page = {}
  12. T.Options = 20
  13.  
  14. function T.Count(Page)
  15.     if(not Page or Page < 1) then
  16.         return 1
  17.     else
  18.         return (Page*T.Options)
  19.     end
  20. end
  21.  
  22. function T.Max(Count, LData)
  23.     if(LData - Count >= T.Options) then
  24.         return Count+T.Options-1, true
  25.     else
  26.         return LData, false
  27.     end
  28. end
  29.  
  30. function T.Hello(pUnit, event, pPlayer)
  31.     local str = tostring(pPlayer)
  32.     if(not T.Page[str] or T.Page[str] < 0) then
  33.         T.Page[str] = 0
  34.     end
  35.     local Page = T.Page[str]
  36.     local Count = T.Count(Page)
  37.     local Max, Next = T.Max(Count, #T.Items)
  38.     pUnit:GossipCreateMenu(1000, pPlayer, 0)
  39.     -- for k, v in ipairs(T.Items) do
  40.     for k = 1, #T.Items do
  41.         local Add = true
  42.         for i = 2, #T.Items[k] do
  43.             if(not pPlayer:HasItem(T.Items[k][i])) then
  44.                 Add = false
  45.             end
  46.         end
  47.         if(Add) then
  48.             local Name = WorldDBQuery("SELECT Name1 FROM items WHERE entry = "..T.Items[k][1]):GetColumn(0):GetString()
  49.             pUnit:GossipMenuAddItem(0, Name, k, 0)
  50.         end
  51.     end
  52.     if(Next) then
  53.         pUnit:GossipMenuAddItem(7, "Next page", 490, 0, '', 0)
  54.     end
  55.     if(Page > 0) then
  56.         pUnit:GossipMenuAddItem(7, "Previous page", 491, 0, '', 0)
  57.     end
  58.     pUnit:GossipSendMenu(pPlayer)
  59. end
  60.  
  61. function T.Select(pUnit, event, pPlayer, id, intid, code)
  62.     if(T.Items[intid]) then
  63.         if(pPlayer:AddItem(T.Items[intid][1], 1)) then
  64.             for i = 2, #T.Items[intid] do
  65.                 pPlayer:RemoveItem(T.Items[intid][i], 1)
  66.             end
  67.         else
  68.             pPlayer:SendAreaTriggerMessage("Your inventory is full")
  69.         end
  70.     end
  71.     T.Hello(pUnit, event, pPlayer)
  72. end
  73.  
  74. local ID = 6948 -- NPC entry
  75. RegisterUnitGossipEvent(ID, 1, T.Hello)
  76. RegisterUnitGossipEvent(ID, 2, T.Select)
  77.  
  78. -- RegisterItemGossipEvent(ID, 1, T.Hello)
  79. -- RegisterItemGossipEvent(ID, 2, T.Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement