caucow

smine

Dec 28th, 2016 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local m = peripheral.find("modem")
  2. local senderID = os.getComputerLabel() == nil and "ID:" .. os.getComputerID() or os.getComputerLabel()
  3. local channels = {
  4.       ["stdout"] = 1000,
  5.       ["stdin"] = 1001,
  6.       ["witherout"] = 1010,
  7.       ["witherin"] = 1011
  8.     }
  9. m.open(channels.stdin)
  10. local ticks = 0
  11.  
  12. local function checkStop()
  13.   if ticks % 4 == 0 then
  14.     os.startTimer(0.15)
  15.     local a, b, c, d, e
  16.     repeat
  17.       evt, face, sendCh, replyCh, msg, dist = os.pullEvent()
  18.       if evt == "modem_message" and msg.type == "cmd" and msg.cmd == "sigterm" and (msg.receiver == nil or (type(msg.receiver) == "string" and string.match(senderID, msg.receiver))) then
  19.         return true
  20.       end
  21.     until evt == "timer"
  22.   end
  23.   return false
  24. end
  25.  
  26. local function tryRefuel()
  27.   while turtle.getFuelLevel() < 1 do
  28.     for i = 1, 16 do
  29.       turtle.select(i)
  30.       turtle.refuel(1)
  31.       if turtle.getFuelLevel() > 0 then
  32.         break
  33.       end
  34.     end
  35.     turtle.select(1)
  36.   end
  37. end
  38.  
  39. local function forward()
  40.   if checkStop() then
  41.     error()
  42.   end
  43.   tryRefuel()
  44.   while not turtle.forward() do
  45.     sleep(.25)
  46.     turtle.dig()
  47.   end
  48. end
  49.  
  50. while true do
  51.   turtle.digDown()
  52.   turtle.dig()
  53.   turtle.digUp()
  54.   forward()
  55. end
Add Comment
Please, Sign In to add comment