SHARE
TWEET

Untitled

a guest Jan 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. item_list = {"Copper Ingot", "Slime Tough Rod", "Blue Slime Crystal", "Diamond Axe", "Diamond Shovel", "Obsidian", "Glowstone Dust", "Glowstone", "Lantern", "Sigil of Haste", "Sigil of Air", "Inactive Crystal", "Iron Pickaxe", "Iron Ingot", "Coal", "Charcoal", "Diamond", "Blood Rune", "Blank Slate", "Infused Slate", "Furnace", "Lapis Lazuli", "Redstone Dust", "Gold Ore"}
  2. items = {}
  3. function randomize()
  4.     for _, i in ipairs(item_list) do
  5.         table.insert(items, {display_name = i, qty = math.random(0, 64)})
  6.     end
  7. end
  8. randomize()
  9. function fetch(item, qty)
  10.     if qty > item.qty then
  11.         print("Too many")
  12.     else
  13.         item.qty = item.qty - qty
  14.     end
  15. end
  16.  
  17. function search(s1, s2)
  18.     local s1=string.lower(string.gsub(string.gsub(s1, " ", ""), "_", ""))
  19.     local s2=string.lower(string.gsub(string.gsub(s2, " ", ""), "_", ""))
  20.     return string.find(s1, s2)
  21. end
  22.  
  23. function slice(tbl, first, last)
  24.     local sliced = {}
  25.     for i=first, last do
  26.         table.insert(sliced, tbl[i])
  27.     end
  28.     return sliced
  29. end
  30.  
  31. function side_number(n)
  32.     term.setCursorPos(1, n+1)
  33.     local spaces = {}
  34.     n_string = tostring(n)
  35.     for i=1, 3-#n_string do
  36.         table.insert(spaces, " ")
  37.     end
  38.     term.setTextColor(colors.gray)
  39.     term.write(table.concat(spaces)..n_string)
  40.     term.setTextColor(colors.white)
  41. end
  42.  
  43. x, y = term.getSize()
  44.  
  45. function show_results(s)
  46.     term.clear()
  47.     paintutils.drawLine(1,1,x,1,colors.cyan)
  48.     term.setCursorPos(1,1)
  49.     term.write("Search:\""..s.."\"")
  50.     paintutils.drawFilledBox(1,2,x,y-1,colors.black)
  51.     term.setCursorPos(1,2)
  52.     for i,result in ipairs(slice(results, 1, y-2)) do
  53.         side_number(i)
  54.         print(" "..result.display_name..": "..result.qty)
  55.     end
  56.     paintutils.drawLine(1,y,x,y,colors.gray)
  57.     term.setCursorPos(1,y)
  58. end
  59.  
  60. function start_search(s)
  61.     results = {}
  62.     for _, item in ipairs(items) do
  63.         r = search(item.display_name, s)
  64.         if r and item.qty > 0 then
  65.             table.insert(results, item)
  66.         end
  67.     end
  68.     show_results(s)
  69. end
  70.  
  71. while true do
  72.     cmd = io.read()
  73.     if tonumber(cmd) and #results > 0 and tonumber(cmd) <= #results then
  74.         n = tonumber(cmd)
  75.         print(results[n].display_name..": "..results[n].qty)
  76.         print("How many?")
  77.         amount = io.read()
  78.         while not tonumber(amount) or amount == "x" do
  79.             amount = io.read()
  80.         end
  81.         if amount == "x" then
  82.             show_results()
  83.         else
  84.             fetch(results[n], tonumber(amount))
  85.         end
  86.     else
  87.         start_search(cmd)
  88.     end
  89. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top