eytixis

turtle 2

Oct 25th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. -- turtle --
  2.  
  3. -- configuration --
  4. controller =
  5. modemSide = "left"
  6.  
  7. function mainFunction()
  8.     rednet.open(modemSide)
  9.     listenForCommands()
  10.  
  11.  
  12. end
  13.  
  14. function listenForCommands()
  15.     while true do
  16.         cmd = getCMD()
  17.         useCMD(cmd)
  18.        
  19.     end
  20.  
  21. end
  22.  
  23. function getCMD()
  24.     while true do
  25.         id, msg = rednet.receive()
  26.         if id == controller then
  27.             break;
  28.         else
  29.            
  30.         end
  31.     end
  32.     return msg
  33. end
  34.  
  35. function useCMD(command)
  36.     if command == "shutdown" then
  37.         os.shutdown()
  38.     elseif command == "go forward" then
  39.         turtle.forward()
  40.     elseif command == "go back" then
  41.         turtle.back()
  42.     elseif command == "turn left" then
  43.         turtle.turnLeft()
  44.     elseif command == "turn right" then
  45.         turtle.turnRight()
  46.     elseif command == "go up" then
  47.         turtle.up()
  48.     elseif command == "go down" then
  49.         turtle.down()
  50.     elseif command == "place up" then
  51.         turtle.placeUp()
  52.     elseif command == "dig up" then
  53.         turtle.digUp()
  54.     elseif command == "inspect up" then
  55.         sleep(0.2)
  56.         b,dat = turtle.inspectUp()
  57.         if b then
  58.             rednet.send(controller, dat.name)
  59.         else
  60.             rednet.send(controller, "nothing above")
  61.         end
  62.     elseif command == "place down" then
  63.         turtle.placeDown()
  64.     elseif command == "dig down" then
  65.         turtle.digDown()
  66.     elseif command == "inspect down" then
  67.         sleep(0.2)
  68.         b,dat = turtle.inspectDown()
  69.         if b then
  70.             rednet.send(controller, dat.name)
  71.         else
  72.             rednet.send(controller, "nothing above")
  73.         end
  74.     elseif command == "place" then
  75.         turtle.place()
  76.     elseif command == "dig" then
  77.         turtle.dig()
  78.     elseif command == "inspect" then
  79.         sleep(0.2)
  80.         b,dat = turtle.inspect()
  81.         if b then
  82.             rednet.send(controller, dat.name)
  83.         else
  84.             rednet.send(controller, "nothing above")
  85.         end
  86.     elseif command == "send fuel" then
  87.         sleep(0.1)
  88.         rednet.send(controller, "fuel: "..tostring(turtle.getFuelLevel()).." or "..tostring(math.floor(turtle.getFuelLevel() / 1000)).."%")
  89.     elseif command == "get slot" then
  90.         ssl = tonumber(getCMD())
  91.         it = turtle.getItemDetail(ssl)
  92.         if it == nil then
  93.             rednet.send(controller, ssl..":nothing")
  94.         else
  95.             rednet.send(controller, tostring(ssl)..":"..it.count.."x"..it.name)
  96.     end
  97. end
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. mainFunction()
Add Comment
Please, Sign In to add comment