Advertisement
Rochet2

Item upgrade/exchange script

Jan 2nd, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.47 KB | None | 0 0
  1. local T = {}
  2. T.Items =
  3. {
  4. --  {GivenItem, ReqItem1, ReqItem2, ... ReqItemN}
  5.     {25, 35},
  6.     {25, 36},
  7.     {25, 37},
  8.     {25, 38},
  9.     {25, 39},
  10.     {25, 40}, -- Testing paging with item entry 40
  11.     {25, 40},
  12.     {25, 40},
  13.     {25, 40},
  14.     {25, 40},
  15.     {25, 40},
  16.     {25, 40},
  17.     {25, 40},
  18.     {25, 40},
  19.     {25, 40},
  20.     {25, 40},
  21.     {25, 40},
  22.     {25, 40},
  23.     {25, 40},
  24.     {25, 40},
  25.     {25, 40},
  26.     {25, 40},
  27.     {25, 40},
  28.     {25, 40},
  29.     {25, 40},
  30.     {25, 40},
  31.     {25, 40},
  32.     {25, 40},
  33.     {25, 40},
  34.     {25, 40},
  35.     {25, 40},
  36.     {25, 40},
  37.     {25, 40},
  38.     {25, 40},
  39.     {25, 40},
  40.     {25, 40},
  41.     {25, 40},
  42.     {25, 40},
  43.     {25, 40},
  44.     {25, 40},
  45.     {25, 40},
  46.     {25, 40},
  47.     {25, 40},
  48.     {25, 40},
  49.     {25, 40},
  50.     {35, 40}, -- Testing vendor with item entry 35
  51. }
  52.  
  53. T.Page = {}
  54. T.Options = 20
  55. local X = 10
  56.  
  57. function T.Count(Page)
  58.     if(not Page or Page < 1) then
  59.         return 1
  60.     else
  61.         return (Page*T.Options)
  62.     end
  63. end
  64.  
  65. function T.Max(Count, LData)
  66.     if(LData - Count >= T.Options) then
  67.         return Count+T.Options-1, true
  68.     else
  69.         return LData, false
  70.     end
  71. end
  72.  
  73. function T.Hello(pUnit, event, pPlayer)
  74.     local Items = {}
  75.     for k,v in ipairs(T.Items) do
  76.         local Add = true
  77.         for i = 2, #v do
  78.             if(not pPlayer:HasItem(v[i])) then
  79.                 Add = false
  80.                 break
  81.             end
  82.         end
  83.         if(Add) then
  84.             Items[#Items+1] = {k,v[1]}
  85.         end
  86.     end
  87.     local str = tostring(pPlayer)
  88.     if(not T.Page[str] or T.Page[str] < 0) then
  89.         T.Page[str] = 0
  90.     end
  91.     local Page = T.Page[str]
  92.     local Count = T.Count(Page)
  93.     local Max, Next = T.Max(Count, #Items)
  94.     pUnit:GossipCreateMenu(100, pPlayer, 0)
  95.     if(Next) then
  96.         pUnit:GossipMenuAddItem(7, "Next page", 3, 0, '', 0)
  97.     end
  98.     if(Page > 0) then
  99.         pUnit:GossipMenuAddItem(7, "Previous page", 4, 0, '', 0)
  100.     end
  101.     pUnit:GossipMenuAddItem(4, "Refresh", 1, 0, '', 0)
  102.     pUnit:GossipMenuAddItem(6, "Preview page's items", X, 0, '', 0)
  103.     for k = Count, Max do
  104.         local Name = WorldDBQuery("SELECT Name1 FROM items WHERE entry = "..Items[k][2]):GetColumn(0):GetString()
  105.         pUnit:GossipMenuAddItem(0, Name, X+Items[k][1], 0, 'NOTE! You will lose the items required to buy this item.', 0)
  106.     end
  107.     pUnit:GossipSendMenu(pPlayer)
  108. end
  109.  
  110. function T.Select(pUnit, event, pPlayer, id, intid, code)
  111.     local str = tostring(pPlayer)
  112.     if(intid == 3) then
  113.         T.Page[str] = T.Page[str] + 1
  114.     elseif(intid == 4) then
  115.         T.Page[str] = T.Page[str] - 1
  116.     elseif(intid == X) then
  117.         pPlayer:GossipComplete()
  118.         pUnit:VendorRemoveAllItems()
  119.         local Items = {}
  120.         for k,v in ipairs(T.Items) do
  121.             local Add = true
  122.             for i = 2, #v do
  123.                 if(not pPlayer:HasItem(v[i])) then
  124.                     Add = false
  125.                     break
  126.                 end
  127.             end
  128.             if(Add) then
  129.                 Items[#Items+1] = v[1]
  130.             end
  131.         end
  132.         local Page = T.Page[str]
  133.         local Count = T.Count(Page)
  134.         local Max, Next = T.Max(Count, #Items)
  135.         for k = Count, Max do
  136.             pUnit:VendorAddItem(Items[k], -1, 0)
  137.         end
  138.         pPlayer:SendVendorWindow(pUnit)
  139.         return
  140.     elseif(T.Items[intid-X]) then
  141.         local intid = intid-X
  142.         local Add = true
  143.         for i = 2, #T.Items[intid] do
  144.             if(not pPlayer:HasItem(T.Items[intid][i])) then
  145.                 Add = false
  146.                 break
  147.             end
  148.         end
  149.         if(Add) then
  150.             if(pPlayer:AddItem(T.Items[intid][1], 1)) then
  151.                 for i = 2, #T.Items[intid] do
  152.                     pPlayer:RemoveItem(T.Items[intid][i], 1)
  153.                 end
  154.             else
  155.                 pPlayer:SendAreaTriggerMessage("Your inventory is full")
  156.             end
  157.         else
  158.             pPlayer:SendAreaTriggerMessage("You do not have the required items")
  159.         end
  160.     end
  161.     T.Hello(pUnit, event, pPlayer)
  162. end
  163.  
  164. local ID = 180001 -- NPC entry
  165. RegisterUnitGossipEvent(ID, 1, T.Hello)
  166. RegisterUnitGossipEvent(ID, 2, T.Select)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement