aesom_e

Computercraft Delivery Turtle

Oct 7th, 2022
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. modem.open(500)
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. term.write("My X: ")
  6. x = tonumber(io.read())
  7. term.setCursorPos(1,2)
  8. term.write("My Y: ")
  9. y = tonumber(io.read())
  10. term.setCursorPos(1,3)
  11. term.write("My Z: ")
  12. z = tonumber(io.read())
  13. term.setCursorPos(1,4)
  14. term.write("Facing (xp/xn/zp/zn): ")
  15. facing = io.read()
  16. term.setCursorPos(1,5)
  17. term.write("Waiting for instructions...")
  18. term.setCursorPos(1,6)
  19. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  20. px = tonumber(message)
  21. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  22. py = tonumber(message)
  23. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  24. pz = tonumber(message)
  25. notthere = true
  26. direction = "x"
  27. while notthere do
  28.     if px > x and direction == "x" then
  29.         if facing == "xn" then
  30.             turtle.turnLeft()
  31.             turtle.turnLeft()
  32.         end
  33.         if facing == "zp" then
  34.             turtle.turnLeft()
  35.         end
  36.         if facing == "zn" then
  37.             turtle.turnRight()
  38.         end
  39.         facing = "xp"
  40.         turtle.dig()
  41.         if turtle.forward() then
  42.             x = x + 1
  43.         end
  44.     end
  45.     if px < x and direction == "x" then
  46.         if facing == "xp" then
  47.             turtle.turnLeft()
  48.             turtle.turnLeft()
  49.         end
  50.         if facing == "zp" then
  51.             turtle.turnRight()
  52.         end
  53.         if facing == "zn" then
  54.             turtle.turnLeft()
  55.         end
  56.         facing = "xn"
  57.         turtle.dig()
  58.         if turtle.forward() then
  59.             x = x - 1
  60.         end
  61.     end
  62.     if px == x and direction == "x" then
  63.        direction = "z"
  64.     end
  65.     if pz > z and direction == "z" then
  66.         if facing == "xn" then
  67.             turtle.turnLeft()
  68.         end
  69.         if facing == "zn" then
  70.             turtle.turnLeft()
  71.             turtle.turnLeft()
  72.         end
  73.         if facing == "xp" then
  74.             turtle.turnRight()
  75.         end
  76.         facing = "zp"
  77.         turtle.dig()
  78.         if turtle.forward() then
  79.             z = z + 1
  80.         end
  81.     end
  82.     if pz < z and direction == "z" then
  83.         if facing == "xp" then
  84.             turtle.turnLeft()
  85.         end
  86.         if facing == "zp" then
  87.             turtle.turnLeft()
  88.             turtle.turnLeft()
  89.         end
  90.         if facing == "xn" then
  91.             turtle.turnRight()
  92.         end
  93.         turtle.dig()
  94.         if turtle.forward() then
  95.             z = z - 1
  96.         end
  97.     end
  98.     if pz == z and direction == "z" then
  99.         direction = "y"
  100.     end
  101.     if py > y and direction == "y" then
  102.         turtle.digUp()
  103.         if turtle.up() then
  104.             y = y + 1
  105.         end
  106.     end
  107.     if py < y and direction == "y" then
  108.         turtle.digDown()
  109.         if turtle.down() then
  110.             y = y - 1
  111.         end
  112.     end
  113.     if py == y and direction == "y" then
  114.         notthere = false
  115.     end
  116. end
  117. modem.transmit(500, 500, "Arrived")
Add Comment
Please, Sign In to add comment