mah17

MFFS Quarry Control.lua

Aug 26th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. --> Config Settings <--
  2.  
  3. --Time it takes for the mining wells to reach bedrock
  4. MINING_TIME = 110
  5.  
  6. --Side to watch for a redstone signal, so the system will stop
  7. RS_DISABLE_SIDE = "top"
  8.  
  9. function pulseSide(side)
  10.     rs.setOutput(side, true)
  11.     sleep(1)
  12.     rs.setOutput(side, false)
  13. end
  14.  
  15. function writeState(s)
  16.         f = fs.open("state.txt", "w")
  17.         f.write(s)
  18.         f.close()
  19. end
  20.  
  21. function readState()
  22.     f = fs.open("state.txt", "r")
  23.     local state = f.readLine()
  24.     f.close()
  25.     return state
  26. end
  27.  
  28. function pauseExecution()
  29.     if rs.getInput(RS_DISABLE_SIDE) then
  30.         print "Shutting down..."
  31.         while rs.getInput(RS_DISABLE_SIDE) do
  32.             sleep(10)
  33.         end
  34.     end
  35. end
  36.  
  37. while true do
  38.     local current_state = readState()
  39.    
  40.     if current_state == "1" then
  41.         pauseExecution()
  42.        
  43.         print("Moving forward...")
  44.         sleep(1)
  45.         pulseSide("left")
  46.         sleep(4)
  47.         pulseSide("left")
  48.        
  49.         writeState("2")
  50.        
  51.     elseif current_state == "2" then
  52.         print("Moving force manipulator into place...")
  53.         sleep(1)
  54.         pulseSide("back")
  55.         sleep(4)
  56.         pulseSide("back")
  57.        
  58.         writeState("3")
  59.        
  60.     elseif current_state == "3" then
  61.         print("Beginning mining...")
  62.         sleep(1)
  63.         pulseSide("right")
  64.         sleep(MINING_TIME)
  65.         print("Retracting mining apparatus...")
  66.         pulseSide("right")
  67.         sleep(1)
  68.        
  69.         writeState("1")
  70.        
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment