Advertisement
VADemon

Quarry Turtle v1.8 [RP2 Turtle Quarry]

Apr 5th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. print("Starting...")
  2.  
  3. if not modemSide then modemSide = "right" end
  4.  
  5. local serverID = 358
  6. local sleepTime = 10 --default sleep time if not defined by the server
  7.  
  8. -- mining well slot = 1
  9. local startMsg = "start"
  10. local endMsg = "shutdown"
  11.  
  12.  
  13. if not rednet.isOpen(modemSide) then rednet.open(modemSide) end
  14.  
  15. turtle.select(1)
  16.  
  17. function mine()
  18.     turtle.place() --place mining well
  19.     turtle.up()
  20.     --sleep(0.15) -- a safe solution from picking up mining well's items
  21.     --redstone.setOutput("back", true)
  22.     sleep(sleepTime) -- subtract 0.15 from here
  23.     print("sleepTime: "..sleepTime)
  24.     --redstone.setOutput("back", false)
  25.     turtle.down()
  26.     turtle.dig()
  27.     --rednet.send(serverID, "done")
  28. end
  29.  
  30. while true do
  31.     local fromID, msg = rednet.receive()
  32.    
  33.     if string.sub(msg, 1, 2)=="go" then --continue mining
  34.         mine()
  35.        
  36.     elseif msg == endMsg then --onStop
  37.    
  38.         print("Stopping the mining!")
  39.        
  40.     elseif string.find(msg, startMsg) then --onStart
  41.         print("Beginning to work...")
  42.        
  43.         local s, e = string.find(msg, "%d+")
  44.             print(s,e)
  45.         if s then --custom sleepTimer
  46.             print("true!!!")
  47.             local sTime = tonumber(string.sub(msg, s, e))
  48.             if sTime~=sleepTime then
  49.                 sleepTime = sTime
  50.                 print("sleepTime set to \""..sleepTime.."\"")
  51.             else
  52.                 print("not equal!")
  53.             end
  54.         end
  55.        
  56.         mine()
  57.        
  58.     else
  59.         print("Wrong message: "..msg)
  60.     end
  61. end
  62.  
  63.  
  64.  
  65. print("Shutting down...")
  66.  
  67. print("Power off.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement