Advertisement
Alscara

tan.lua

Jun 19th, 2015
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.85 KB | None | 0 0
  1. -- config
  2. local modalId = 1007
  3. local choice = {}
  4. local recipes = {
  5.     [1] = {name = "Raw Leather", subname = "lizard leather", count = 1, storage = 40010, level = 20, tries = 2, id = 22539,
  6.         needed = {
  7.             [1] = {name = "lizard leathers", id = 5876, count = 2}
  8.         }
  9.     },
  10.     [2] = {name = "Raw Leather", subname = "minotaur leather", count = 1, storage = 40010, level = 10, tries = 1, id = 22539,
  11.         needed = {
  12.             [1] = {name = "minotaur leathers", id = 5878, count = 2}
  13.         }
  14.     },
  15.     [3] = {name = "Raw Leather", subname = "red dragon leather", count = 1, storage = 40010, level = 20, tries = 3, id = 22539,
  16.         needed = {
  17.             [1] = {name = "red dragon leathers", id = 5948, count = 2}
  18.         }
  19.     },
  20.     [4] = {name = "Raw Leather", subname = "green dragon leather", count = 1, storage = 40010, level = 20, tries = 2, id = 22539,
  21.         needed = {
  22.             [1] = {name = "green dragon leathers", id = 5877, count = 2}
  23.         }
  24.     },
  25.     [5] = {name = "Raw Leather", subname = "crocodile leather", count = 1, storage = 40010, level = 10, tries = 1, id = 22539,
  26.         needed = {
  27.             [1] = {name = "pieces of crocodile leather", id = 11196, count = 4}
  28.         }
  29.     },
  30.     [6] = {name = "Raw Leather", subname = "orc leather", count = 1, storage = 40010, level = 10, tries = 1, id = 22539,
  31.         needed = {
  32.             [1] = {name = "orc leathers", id = 12435, count = 4}
  33.         }
  34.     },
  35.     [7] = {name = "Raw Leather", subname = "silky fur", count = 1, storage = 40010, level = 30, tries = 1, id = 22539,
  36.         needed = {
  37.             [1] = {name = "silky fur", id = 11209, count = 1}
  38.         }
  39.     },
  40.     [8] = {name = "Raw Leather", subname = "black wool", count = 1, storage = 40010, level = 30, tries = 1, id = 22539,
  41.         needed = {
  42.             [1] = {name = "black wool", id = 12404, count = 1}
  43.         }
  44.     },
  45.     [9] = {name = "Raw Leather", subname = "striped fur", count = 1, storage = 40010, level = 30, tries = 1, id = 22539,
  46.         needed = {
  47.             [1] = {name = "striped fur", id = 11210, count = 1}
  48.         }
  49.     },
  50.     [10] = {name = "Raw Leather", subname = "war wolf fur", count = 2, storage = 40010, level = 40, tries = 2, id = 22539,
  51.         needed = {
  52.             [1] = {name = "war wolf fur", id = 11235, count = 1}
  53.         }
  54.     },
  55.     [11] = {name = "Raw Leather", subname = "winter wolf fur", count = 2, storage = 40010, level = 40, tries = 1, id = 22539,
  56.         needed = {
  57.             [1] = {name = "winter wolf fur", id = 11212, count = 1}
  58.         }
  59.     },
  60.     [12] = {name = "Raw Leather", subname = "wool", count = 2, storage = 40010, level = 40, tries = 1, id = 22539,
  61.         needed = {
  62.             [1] = {name = "wool", id = 11236, count = 1}
  63.         }
  64.     },
  65.     [13] = {name = "Raw Leather", subname = "badger fur", count = 2, storage = 40010, level = 40, tries = 2, id = 22539,
  66.         needed = {
  67.             [1] = {name = "badger fur", id = 11216, count = 1}
  68.         }
  69.     },
  70.     [14] = {name = "Raw Leather", subname = "werewolf fur", count = 2, storage = 40010, level = 40, tries = 4, id = 22539,
  71.         needed = {
  72.             [1] = {name = "werewolf fur", id = 11234, count = 1}
  73.         }
  74.     },
  75.     [15] = {name = "Raw Leather", subname = "thick fur", count = 4, storage = 40010, level = 60, tries = 2, id = 22539,
  76.         needed = {
  77.             [1] = {name = "thick fur", id = 11224, count = 1}
  78.         }
  79.     },
  80.     [16] = {name = "Raw Leather", subname = "frost giant pelt", count = 4, storage = 40010, level = 60, tries = 2, id = 22539,
  81.         needed = {
  82.             [1] = {name = "frost giant pelt", id = 10575, count = 1}
  83.         }
  84.     },
  85.     [17] = {name = "Raw Leather", subname = "white deer skin", count = 4, storage = 40010, level = 80, tries = 3, id = 22539,
  86.         needed = {
  87.             [1] = {name = "white deer skin", id = 13534, count = 1}
  88.         }
  89.     },
  90.     [18] = {name = "Raw Leather", subname = "frazzle skin", count = 4, storage = 40010, level = 80, tries = 4, id = 22539,
  91.         needed = {
  92.             [1] = {name = "frazzle skin", id = 22533, count = 1}
  93.         }
  94.     },
  95.  
  96. }
  97.  
  98. local training = {
  99.     [40010] = "Basic Tanning",
  100. }
  101.  
  102. function Player:hasReq(recipe)
  103.     for i = 1, #recipe.needed do
  104.         if self:getItemCount(recipe.needed[i].id) < recipe.needed[i].count then
  105.             return false
  106.         end
  107.     end
  108.     return true
  109. end
  110.  
  111. function Player:sendPeltWindow()
  112.     local window = ModalWindow(modalId, "Tanning", "Expand the item you want to produce to view the requirements.\nYou are trained in the following skills:\n")
  113.     local choices = 0
  114.     local temp = 0
  115.     for key,value in pairs(training) do
  116.         if self:getStorageValue(key) >= 10 then
  117.             temp = temp + 1
  118.             window:setMessage(window:getMessage() .. training[key] .. " (" .. self:getCSkill(training[key]) .. ")\n")
  119.         end
  120.     end
  121.     if temp == 0 then
  122.         window:setMessage(window:getMessage() .. "No skill training.\n")
  123.     end
  124.     for i = 1, #recipes do
  125.         if recipes[i].subname then
  126.             if recipes[i].count > 1 then
  127.                 window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
  128.             else
  129.                 window:addChoice(i, recipes[i]["name"] .. " (" .. recipes[i].subname .. ")")
  130.             end
  131.         else
  132.             if recipes[i].count > 1 then
  133.                 window:addChoice(i, recipes[i].count .. " " .. recipes[i]["name"])
  134.             else
  135.                 window:addChoice(i, recipes[i]["name"])
  136.             end
  137.         end
  138.         choices = choices + 1
  139.     end
  140.     if choices > 0 then
  141.         window:addButton(1, "Expand")
  142.         window:setDefaultEnterButton(1)
  143.     end
  144.     window:addButton(2, "Exit")
  145.     window:setDefaultEscapeButton(2)
  146.     window:sendToPlayer(self)
  147.     return true
  148. end
  149.  
  150. function Player:sendPRecipeWindow(product)
  151.     local window = ModalWindow(modalId + 1, product["name"], "To produce this item, you need:\n")
  152.    
  153.     for i = 1, #product.needed do
  154.         window:setMessage(window:getMessage() .. product.needed[i].count .. " " .. product.needed[i].name .. " (" .. self:getItemCount(product.needed[i].id) .. ")\n")
  155.     end
  156.     if product.storage then
  157.         local lev = self:getCSkill(training[product.storage])
  158.         window:setMessage(window:getMessage() .. training[product.storage] .. " " .. product.level .. " (" .. lev .. ")\n")
  159.     end
  160.     for j = 1, #product.needed do
  161.         if self:getItemCount(product.needed[j].id) < product.needed[j].count or (product.storage and self:getCSkill(training[product.storage]) < product.level) then
  162.             return window:addButton(2, "Back"), window:setDefaultEscapeButton(2), window:setDefaultEnterButton(2), window:sendToPlayer(self)
  163.         end
  164.     end
  165.     window:addButton(1, "Make It!")
  166.     window:setDefaultEnterButton(1)
  167.     window:addButton(2, "Back")
  168.     window:setDefaultEscapeButton(2)
  169.     window:sendToPlayer(self)
  170.     return true
  171. end
  172.  
  173. function Player:peltWindowChoice(windowId, buttonId, choiceId)
  174.     local p = self:getGuid()
  175.     if windowId == modalId then
  176.         if buttonId == 1 then
  177.             choice[p] = choiceId
  178.             self:sendPRecipeWindow(recipes[choiceId])
  179.             return true
  180.         else
  181.             choice[p] = nil
  182.             return false
  183.         end
  184.     end
  185.     return false
  186. end
  187.  
  188. function Player:pRecipeWindowChoice(windowId, buttonId, choiceId)
  189.     local p = self:getGuid()
  190.     if windowId == modalId + 1 then
  191.         if buttonId == 1 then
  192.             for i = 1, #recipes[choice[p]].needed do
  193.                 self:removeItem(recipes[choice[p]].needed[i].id, recipes[choice[p]].needed[i].count)
  194.             end
  195.            
  196.             local rand = math.random(1,100000)
  197.             local extra = false
  198.             local chance = (cSkills[training[recipes[choice[p]].storage]].bonus * self:getCSkill(training[recipes[choice[p]].storage])) * 100
  199.             if rand < chance * 1000 then
  200.                 extra = true
  201.             end
  202.            
  203.             if extra then
  204.                 self:addItem(recipes[choice[p]].id, recipes[choice[p]].count + 2)
  205.                 self:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have produced " .. recipes[choice[p]].count + 2 .. " " .. recipes[choice[p]].name .. " instead of the usual " .. recipes[choice[p]].count .. "!")
  206.             else
  207.                 self:addItem(recipes[choice[p]].id, recipes[choice[p]].count)
  208.                 self:sendTextMessage(MESSAGE_INFO_DESCR, "You have produced " .. recipes[choice[p]].count .. " " .. recipes[choice[p]].name .. "!")
  209.             end
  210.             self:addCSkillTries(training[recipes[choice[p]].storage], recipes[choice[p]].tries)
  211.  
  212.            
  213.             return self:hasReq(recipes[choice[p]]) and self:sendPRecipeWindow(recipes[choice[p]]) or self:sendPeltWindow()
  214.         elseif buttonId == 2 then
  215.             self:sendPeltWindow()
  216.         end
  217.         return false
  218.     end
  219.    
  220.     return false
  221. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement