Alscara

smelt.lua

Jun 19th, 2015
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 KB | None | 0 0
  1. -- config
  2. local modalId = 1003
  3. local choice = {}
  4. local recipes = {
  5.     [1] = {name = "Iron Ingot", subname = "iron ore", count = 1, storage = 40011, level = 30, tries = 2, id = 18337,
  6.         needed = {
  7.             [1] = {name = "iron ore", id = 5880, count = 2}
  8.         }
  9.     },
  10.     [2] = {name = "Iron Ingot", subname = "piece of iron", count = 1, storage = 40011, level = 20, tries = 1, id = 18337,
  11.         needed = {
  12.             [1] = {name = "pieces of iron", id = 2225, count = 5}
  13.         }
  14.     },
  15.     [3] = {name = "Iron Ore", count = 3, storage = 40011, level = 10, tries = 1, id = 5880,
  16.         needed = {
  17.             [1] = {name = "vein of ore", id = 18429, count = 1}
  18.         }
  19.     },
  20.     [4] = {name = "Huge Chunk of Crude Iron", count = 1, storage = 40011, level = 40, tries = 3, id = 5892,
  21.         needed = {
  22.             [1] = {name = "iron ingots", id = 18337, count = 5}
  23.         }
  24.     },
  25.     [5] = {name = "Piece of Iron", subname = "nails", count = 1, storage = 40011, level = 10, tries = 1, id = 2225,
  26.         needed = {
  27.             [1] = {name = "nails", id = 8309, count = 2}
  28.         }
  29.     },
  30.     [6] = {name = "Pieces of Iron", subname = "metal spike", count = 2, storage = 40011, level = 10, tries = 1, id = 2225,
  31.         needed = {
  32.             [1] = {name = "metal spike", id = 11215, count = 1}
  33.         }
  34.     },
  35.     [7] = {name = "Pieces of Iron", subname = "gear wheel", count = 5, storage = 40011, level = 10, tries = 1, id = 2225,
  36.         needed = {
  37.             [1] = {name = "gear wheel", id = 9690, count = 1}
  38.         }
  39.     },
  40.     [8] = {name = "Pieces of Iron", subname = "spiked iron ball", count = 3, storage = 40011, level = 10, tries = 1, id = 2225,
  41.         needed = {
  42.             [1] = {name = "spiked iron ball", id = 11325, count = 1}
  43.         }
  44.     },
  45.     [9] = {name = "Piece of Royal Steel", count = 1, storage = 40012, level = 60, tries = 4, id = 5887,
  46.         needed = {
  47.             [1] = {name = "iron ore", id = 5880, count = 1},
  48.             [2] = {name = "gold ore", id = 6547, count = 1}
  49.         }
  50.     },
  51.     [10] = {name = "Piece of Draconian Steel", count = 1, storage = 40012, level = 50, tries = 3, id = 5889,
  52.         needed = {
  53.             [1] = {name = "dragon shield", id = 2516, count = 1}
  54.         }
  55.     },
  56.     [11] = {name = "Piece of Hell Steel", count = 1, storage = 40012, level = 40, tries = 2, id = 5888,
  57.         needed = {
  58.             [1] = {name = "iron ores", id = 5880, count = 3},
  59.             [2] = {name = "soul orbs", id = 5944, count = 3}
  60.         }
  61.     },
  62.     [12] = {name = "Gold Ore", count = 2, storage = 40012, level = 10, tries = 1, id = 6547,
  63.         needed = {
  64.             [1] = {name = "pulverized ore", id = 18427, count = 1}
  65.         }
  66.     },
  67.     [13] = {name = "Gold Nugget", count = 1, storage = 40012, level = 20, tries = 2, id = 2157,
  68.         needed = {
  69.             [1] = {name = "gold ore", id = 6547, count = 3}
  70.         }
  71.     },
  72.     [14] = {name = "Gold Ingot", count = 1, storage = 40012, level = 30, tries = 3, id = 9971,
  73.         needed = {
  74.             [1] = {name = "gold nuggets", id = 2157, count = 5}
  75.         }
  76.     },
  77.    
  78.  
  79. }
  80. local training = {
  81.     [40011] = "Basic Smelting",
  82.     [40012] = "Advanced Smelting",
  83. }
  84. function Player:hasReq(recipe)
  85.     for i = 1, #recipe.needed do
  86.         if self:getItemCount(recipe.needed[i].id) < recipe.needed[i].count then
  87.             return false
  88.         end
  89.     end
  90.     return true
  91. end
  92.  
  93. function Player:sendProductWindow()
  94.     local window = ModalWindow(modalId, "Smelting", "Expand the item you want to produce to view the requirements.\nYou are trained in the following specialties:\n")
  95.     local choices = 0
  96.     local temp = 0
  97.     for i = 40011, 40012 do
  98.         if self:getCSkill(training[i]) >= 10 then
  99.             temp = temp + 1
  100.             window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
  101.         end
  102.     end
  103.     if temp == 0 then
  104.         window:setMessage(window:getMessage() .. "No specialty training.\n")
  105.     end
  106.     for i = 1, #recipes do
  107.         if recipes[i].subname then
  108.             if recipes[i].count > 1 then
  109.                 window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
  110.             else
  111.                 window:addChoice(i, recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
  112.             end
  113.         else
  114.             if recipes[i].count > 1 then
  115.                 window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"])
  116.             else
  117.                 window:addChoice(i, recipes[i]["name"])
  118.             end
  119.         end
  120.         choices = choices + 1
  121.     end
  122.     if choices > 0 then
  123.         window:addButton(1, "Expand")
  124.         window:setDefaultEnterButton(1)
  125.     end
  126.     window:addButton(2, "Exit")
  127.     window:setDefaultEscapeButton(2)
  128.     window:sendToPlayer(self)
  129.     return true
  130. end
  131.  
  132. function Player:sendRecipeWindow(product)
  133.     local window = ModalWindow(modalId + 1, product["name"], "To produce this item, you need:\n")
  134.    
  135.     for i = 1, #product.needed do
  136.         window:setMessage(window:getMessage() .. product.needed[i].count .. " " .. product.needed[i].name .. " (" .. self:getItemCount(product.needed[i].id) .. ")\n")
  137.     end
  138.     if product.storage then
  139.         local lev = self:getCSkill(training[product.storage])
  140.         window:setMessage(window:getMessage() .. training[product.storage] .. " " .. product.level .. " (" .. lev .. ")\n")
  141.     end
  142.     for j = 1, #product.needed do
  143.         if self:getItemCount(product.needed[j].id) < product.needed[j].count or (product.storage and self:getCSkill(training[product.storage]) < product.level) then
  144.             return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
  145.         end
  146.     end
  147.     window:addButton(1, "Make It!")
  148.     window:setDefaultEnterButton(1)
  149.     window:addButton(2, "Back")
  150.     window:setDefaultEscapeButton(2)
  151.     window:sendToPlayer(self)
  152.     return true
  153. end
  154.  
  155. function Player:productWindowChoice(windowId, buttonId, choiceId)
  156.     local p = self:getGuid()
  157.     if windowId == modalId then
  158.         if buttonId == 1 then
  159.             choice[p] = choiceId
  160.             self:sendRecipeWindow(recipes[choiceId])
  161.             return true
  162.         else
  163.             choice[p] = nil
  164.             return false
  165.         end
  166.     end
  167.     return false
  168. end
  169.  
  170. function Player:recipeWindowChoice(windowId, buttonId, choiceId)
  171.     local p = self:getGuid()
  172.     if windowId == modalId + 1 then
  173.         if buttonId == 1 then
  174.             for i = 1, #recipes[choice[p]].needed do
  175.                 self:removeItem(recipes[choice[p]].needed[i].id, recipes[choice[p]].needed[i].count)
  176.             end
  177.             self:addItem(recipes[choice[p]].id, recipes[choice[p]].count)
  178.             self:sendTextMessage(MESSAGE_INFO_DESCR, "You have crafted " .. recipes[choice[p]].count .. " " .. recipes[choice[p]].name .. "!")
  179.             self:addCSkillTries(training[recipes[choice[p]].storage], recipes[choice[p]].tries)
  180.             return self:hasReq(recipes[choice[p]]) and self:sendRecipeWindow(recipes[choice[p]]) or self:sendProductWindow()
  181.         elseif buttonId == 2 then
  182.             self:sendProductWindow()
  183.         end
  184.         return false
  185.     end
  186.    
  187.     return false
  188. end
Advertisement
Add Comment
Please, Sign In to add comment