caucow

infinidig

Dec 28th, 2016 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 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.  
  11. local args = {...}
  12. local digFunc = turtle.dig
  13. if args[1] == "up" then
  14.   digFunc = turtle.digUp
  15. elseif args[1] == "down" then
  16.   digFunc = turtle.digDown
  17. end
  18. local xTime = os.clock()
  19.  
  20. local function checkStop()
  21.   if os.clock() >= xTime then
  22.     os.startTimer(0.15)
  23.     local a, b, c, d, e
  24.     repeat
  25.       evt, face, sendCh, replyCh, msg, dist = os.pullEvent()
  26.       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
  27.         return true
  28.       end
  29.     until evt == "timer"
  30.     xTime = os.clock() + 2.5
  31.   end
  32.   return false
  33. end
  34.  
  35. while true do
  36.   if checkStop() then
  37.     break
  38.   end
  39.   digFunc()
  40. end
Add Comment
Please, Sign In to add comment