Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- config
- local modalId = 1003
- local choice = {}
- local recipes = {
- [1] = {name = "Iron Ingot", subname = "iron ore", count = 1, storage = 40011, level = 30, tries = 2, id = 18337,
- needed = {
- [1] = {name = "iron ore", id = 5880, count = 2}
- }
- },
- [2] = {name = "Iron Ingot", subname = "piece of iron", count = 1, storage = 40011, level = 20, tries = 1, id = 18337,
- needed = {
- [1] = {name = "pieces of iron", id = 2225, count = 5}
- }
- },
- [3] = {name = "Iron Ore", count = 3, storage = 40011, level = 10, tries = 1, id = 5880,
- needed = {
- [1] = {name = "vein of ore", id = 18429, count = 1}
- }
- },
- [4] = {name = "Huge Chunk of Crude Iron", count = 1, storage = 40011, level = 40, tries = 3, id = 5892,
- needed = {
- [1] = {name = "iron ingots", id = 18337, count = 5}
- }
- },
- [5] = {name = "Piece of Iron", subname = "nails", count = 1, storage = 40011, level = 10, tries = 1, id = 2225,
- needed = {
- [1] = {name = "nails", id = 8309, count = 2}
- }
- },
- [6] = {name = "Pieces of Iron", subname = "metal spike", count = 2, storage = 40011, level = 10, tries = 1, id = 2225,
- needed = {
- [1] = {name = "metal spike", id = 11215, count = 1}
- }
- },
- [7] = {name = "Pieces of Iron", subname = "gear wheel", count = 5, storage = 40011, level = 10, tries = 1, id = 2225,
- needed = {
- [1] = {name = "gear wheel", id = 9690, count = 1}
- }
- },
- [8] = {name = "Pieces of Iron", subname = "spiked iron ball", count = 3, storage = 40011, level = 10, tries = 1, id = 2225,
- needed = {
- [1] = {name = "spiked iron ball", id = 11325, count = 1}
- }
- },
- [9] = {name = "Piece of Royal Steel", count = 1, storage = 40012, level = 60, tries = 4, id = 5887,
- needed = {
- [1] = {name = "iron ore", id = 5880, count = 1},
- [2] = {name = "gold ore", id = 6547, count = 1}
- }
- },
- [10] = {name = "Piece of Draconian Steel", count = 1, storage = 40012, level = 50, tries = 3, id = 5889,
- needed = {
- [1] = {name = "dragon shield", id = 2516, count = 1}
- }
- },
- [11] = {name = "Piece of Hell Steel", count = 1, storage = 40012, level = 40, tries = 2, id = 5888,
- needed = {
- [1] = {name = "iron ores", id = 5880, count = 3},
- [2] = {name = "soul orbs", id = 5944, count = 3}
- }
- },
- [12] = {name = "Gold Ore", count = 2, storage = 40012, level = 10, tries = 1, id = 6547,
- needed = {
- [1] = {name = "pulverized ore", id = 18427, count = 1}
- }
- },
- [13] = {name = "Gold Nugget", count = 1, storage = 40012, level = 20, tries = 2, id = 2157,
- needed = {
- [1] = {name = "gold ore", id = 6547, count = 3}
- }
- },
- [14] = {name = "Gold Ingot", count = 1, storage = 40012, level = 30, tries = 3, id = 9971,
- needed = {
- [1] = {name = "gold nuggets", id = 2157, count = 5}
- }
- },
- }
- local training = {
- [40011] = "Basic Smelting",
- [40012] = "Advanced Smelting",
- }
- function Player:hasReq(recipe)
- for i = 1, #recipe.needed do
- if self:getItemCount(recipe.needed[i].id) < recipe.needed[i].count then
- return false
- end
- end
- return true
- end
- function Player:sendProductWindow()
- local window = ModalWindow(modalId, "Smelting", "Expand the item you want to produce to view the requirements.\nYou are trained in the following specialties:\n")
- local choices = 0
- local temp = 0
- for i = 40011, 40012 do
- if self:getCSkill(training[i]) >= 10 then
- temp = temp + 1
- window:setMessage(window:getMessage() .. training[i] .. " (" .. self:getCSkill(training[i]) .. ")\n")
- end
- end
- if temp == 0 then
- window:setMessage(window:getMessage() .. "No specialty training.\n")
- end
- for i = 1, #recipes do
- if recipes[i].subname then
- if recipes[i].count > 1 then
- window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
- else
- window:addChoice(i, recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
- end
- else
- if recipes[i].count > 1 then
- window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"])
- else
- window:addChoice(i, recipes[i]["name"])
- end
- end
- choices = choices + 1
- end
- if choices > 0 then
- window:addButton(1, "Expand")
- window:setDefaultEnterButton(1)
- end
- window:addButton(2, "Exit")
- window:setDefaultEscapeButton(2)
- window:sendToPlayer(self)
- return true
- end
- function Player:sendRecipeWindow(product)
- local window = ModalWindow(modalId + 1, product["name"], "To produce this item, you need:\n")
- for i = 1, #product.needed do
- window:setMessage(window:getMessage() .. product.needed[i].count .. " " .. product.needed[i].name .. " (" .. self:getItemCount(product.needed[i].id) .. ")\n")
- end
- if product.storage then
- local lev = self:getCSkill(training[product.storage])
- window:setMessage(window:getMessage() .. training[product.storage] .. " " .. product.level .. " (" .. lev .. ")\n")
- end
- for j = 1, #product.needed do
- if self:getItemCount(product.needed[j].id) < product.needed[j].count or (product.storage and self:getCSkill(training[product.storage]) < product.level) then
- return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
- end
- end
- window:addButton(1, "Make It!")
- window:setDefaultEnterButton(1)
- window:addButton(2, "Back")
- window:setDefaultEscapeButton(2)
- window:sendToPlayer(self)
- return true
- end
- function Player:productWindowChoice(windowId, buttonId, choiceId)
- local p = self:getGuid()
- if windowId == modalId then
- if buttonId == 1 then
- choice[p] = choiceId
- self:sendRecipeWindow(recipes[choiceId])
- return true
- else
- choice[p] = nil
- return false
- end
- end
- return false
- end
- function Player:recipeWindowChoice(windowId, buttonId, choiceId)
- local p = self:getGuid()
- if windowId == modalId + 1 then
- if buttonId == 1 then
- for i = 1, #recipes[choice[p]].needed do
- self:removeItem(recipes[choice[p]].needed[i].id, recipes[choice[p]].needed[i].count)
- end
- self:addItem(recipes[choice[p]].id, recipes[choice[p]].count)
- self:sendTextMessage(MESSAGE_INFO_DESCR, "You have crafted " .. recipes[choice[p]].count .. " " .. recipes[choice[p]].name .. "!")
- self:addCSkillTries(training[recipes[choice[p]].storage], recipes[choice[p]].tries)
- return self:hasReq(recipes[choice[p]]) and self:sendRecipeWindow(recipes[choice[p]]) or self:sendProductWindow()
- elseif buttonId == 2 then
- self:sendProductWindow()
- end
- return false
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment