Advertisement
ignjat2

Laser Drill Config

Apr 20th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. function Startup()
  2.   if fs.exists("DrillData") then
  3.     DataInit(true)
  4.     if (DrillID == nil or DrillID == "") then
  5.       Setup(true)
  6.     else
  7.       Drilling(true)
  8.     end
  9.   else
  10.     Setup(true)
  11.   end
  12. end
  13.  
  14. function DataInit()
  15.   file = fs.open("DrillData/".."Data", "r")
  16.   DrillData = {}
  17.   Data = file.readLine()
  18.   repeat
  19.     table.insert(DrillData, Data)
  20.     Data = file.readLine()
  21.   until Data == nil
  22.   file.close()
  23.   DrillID = DrillData[1]
  24.   DrillName = DrillData[2]
  25. end
  26.  
  27. function Setup()
  28.   print("\nEnter this drill's ID\n")
  29.   DrillID = read()
  30.   fs.makeDir("DrillData")
  31.   file = fs.open("DrillData/".."Data", "w")
  32.     file.writeLine(DrillID)
  33.   file.close()
  34.   DataInit(true)
  35.   loop(true)
  36. end
  37.  
  38. function Drilling()
  39.   id, message = rednet.receive("Drill"..DrillID)
  40.   if message == "Drill"..DrillID.."Activation" then
  41.     print("\nActivated Laser Drill")
  42.     redstone.setOutput("bottom", true)
  43.     os.sleep(1)
  44.     loop(true)
  45.   elseif message == "Drill"..DrillID.."Deactivation" then
  46.     print("\nDeactivated Laser Drill")
  47.     redstone.setOutput("bottom", false)
  48.     os.sleep(1)
  49.     loop(true)
  50.   elseif message == "Status" then
  51.     status = redstone.getOutput("bottom")
  52.     if status == true then
  53.       rednet.broadcast("On", "Drill"..DrillID)
  54.       Drilling(true)
  55.     elseif status == false then
  56.       rednet.broadcast("Off", "Drill"..DrillID)
  57.       loop(true)
  58.     end
  59.   else
  60.     os.sleep(0.5)
  61.     loop(true)
  62.   end
  63. end
  64.  
  65. function loop()
  66.     os.sleep(0.5)
  67.     Drilling(true)
  68. end
  69.  
  70. rednet.open("top")
  71.  
  72. Startup(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement