Advertisement
Guest User

craft.lua v1.2

a guest
Aug 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.46 KB | None | 0 0
  1. -- APIs
  2.  
  3. local component = require("component")
  4. local tunnel = component.tunnel
  5. local event = require("event")
  6. local computer = require("computer")
  7.  
  8. -- Wall Confirmation Prompt
  9.  
  10. function promptWall()
  11.   io.write("Insufficient amount of walls. Would you like to construct more now? (Y/N) ")
  12.   answer = string.upper(io.read())
  13.   if answer == "Y" then
  14.     tunnel.send("Y")
  15.     _, _, _, _, _, message = event.pull("modem_message")
  16.     if message == "failed" then
  17.       print("Operation failed. Not enough items.")
  18.       os.sleep(2)
  19.       computer.shutdown(true)
  20.     elseif message == "success" then
  21.       print("Confirmed operation. Constructing walls now.")
  22.     end
  23.   elseif answer == "N" then
  24.     print("Operation denied. Cancelling machine wall construction.")
  25.     tunnel.send("N")
  26.     os.sleep(2)
  27.     computer.shutdown(true)
  28.   end
  29. end
  30.  
  31. -- Crafting Arguments
  32.  
  33. args = {...}
  34.  
  35. if (args[1] == nil) or (string.upper(args[1]) == "HELP") then
  36.   print("Usage: craft <item> (maxMachine, minMachine, walls, tunnel, redTunnel)")
  37.   return
  38. end
  39.  
  40. if (string.upper(args[1]) == "MAXMACHINE") then
  41.   tunnel.send("maxMachine")
  42.   _, _, _, _, _, message = event.pull("modem_message")
  43.   if message == "wallConfirm" then
  44.     promptWall()
  45.   elseif message == "maxMachineConfirm" then
  46.     io.write("Would you like to construct a maximum compact machine? (5x5x5) (Y/N) ")
  47.     answer = string.upper(io.read())
  48.     if answer == "Y" then
  49.       tunnel.send("Y")
  50.       _, _, _, _, _, message = event.pull("modem_message")
  51.       if message == "failed" then
  52.         print("Operation failed. Not enough items.")
  53.         os.sleep(2)
  54.         computer.shutdown(true)
  55.       elseif message == "success" then
  56.         print("Confirmed operation. Constructing compact machine now.")
  57.       end
  58.     elseif answer == "N" then
  59.       print("Operation denied. Cancelling compact machine construction.")
  60.       tunnel.send("N")
  61.       os.sleep(2)
  62.       computer.shutdown(true)
  63.     end
  64.   end
  65. elseif (string.upper(args[1]) == "WALLS") then
  66.   tunnel.send("walls")
  67.   _, _, _, _, _, message = event.pull("modem_message")
  68.   if message == "wallConfirm" then
  69.     io.write("Would you like to construct sixteen machine walls? (Y/N) ")
  70.     answer = string.upper(io.read())
  71.     if answer == "Y" then
  72.       tunnel.send("Y")
  73.       _, _, _, _, _, message = event.pull("modem_message")
  74.       if message == "failed" then
  75.         print("Operation failed. Not enough items.")
  76.         os.sleep(2)
  77.         computer.shutdown(true)
  78.       elseif message == "success" then
  79.         print("Confirmed operation. Constructing machine walls now.")
  80.       end
  81.     elseif answer == "N" then
  82.       print("Operation denied. Cancelling machine wall construction.")
  83.       tunnel.send("N")
  84.       os.sleep(2)
  85.       computer.shutdown(true)
  86.     end
  87.   end
  88. elseif (string.upper(args[1]) == "MINMACHINE") then
  89.   tunnel.send("minMachine")
  90.   _, _, _, _, _, message = event.pull("modem_message")
  91.   if message == "wallConfirm" then
  92.     promptWall()
  93.   elseif message == "minMachineConfirm" then
  94.     io.write("Would you like to construct a normal compact machine? (3x3x3) (Y/N) ")
  95.     answer = string.upper(io.read())
  96.     if answer == "Y" then
  97.       tunnel.send("Y")
  98.       _, _, _, _, _, message = event.pull("modem_message")
  99.       if message == "failed" then
  100.         print("Operation failed. Not enough items.")
  101.         os.sleep(2)
  102.         computer.shutdown(true)
  103.       elseif message == "success" then
  104.         print("Confirmed operation. Constructing compact machine now.")
  105.       end
  106.     elseif answer == "N" then
  107.       print("Operation denied. Cancelling compact machine construction.")
  108.       tunnel.send("N")
  109.       os.sleep(2)
  110.       computer.shutdown(true)
  111.     end
  112.   end
  113. elseif (string.upper(args[1]) == "TUNNEL") then
  114.   tunnel.send("tunnel")
  115.   _, _, _, _, _, message = event.pull("modem_message")
  116.   if message == "wallConfirm" then
  117.     promptWall()
  118.   elseif message == "tunnelConfirm" then
  119.     io.write("Would you like to construct two tunnels? (Y/N) ")
  120.     answer = string.upper(io.read())
  121.     if answer == "Y" then
  122.       tunnel.send("Y")
  123.       _, _, _, _, _, message = event.pull("modem_message")
  124.       if message == "failed" then
  125.         print("Operation failed. Not enough items.")
  126.         os.sleep(2)
  127.         computer.shutdown(true)
  128.       elseif message == "success" then
  129.         print("Confirmed operation. Constructing tunnels now.")
  130.       end
  131.     elseif answer == "N" then
  132.       print("Operation denied. Cancelling tunnel construction.")
  133.       tunnel.send("N")
  134.       os.sleep(2)
  135.       computer.shutdown(true)
  136.     end
  137.   end
  138. elseif (string.upper(args[1]) == "REDTUNNEL") then
  139.   tunnel.send("redTunnel")
  140.   _, _, _, _, _, message = event.pull("modem_message")
  141.   if message == "wallConfirm" then
  142.     promptWall()
  143.   elseif message == "redTunnelConfirm" then
  144.     io.write("Would you like to construct two redstone tunnels? (Y/N) ")
  145.     answer = string.upper(io.read())
  146.     if answer == "Y" then
  147.       tunnel.send("Y")
  148.       _, _, _, _, _, message = event.pull("modem_message")
  149.       if message == "failed" then
  150.         print("Operation failed. Not enough items.")
  151.         os.sleep(2)
  152.         computer.shutdown(true)
  153.       elseif message == "success" then
  154.         print("Confirmed operation. Constructing redstone tunnels now.")
  155.       end
  156.     elseif answer == "N" then
  157.       print("Operation denied. Cancelling redstone tunnel construction.")
  158.       tunnel.send("N")
  159.       os.sleep(2)
  160.       computer.shutdown(true)
  161.     end
  162.   end
  163. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement