dragon81655

Drone

Jul 3rd, 2022 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. function inspect()
  2. local s,n = turtle.inspect()
  3. if(s == true) then
  4. return n.name
  5. else
  6. return "No Block"
  7. end
  8. end
  9. function inspectDown()
  10. local s,n = turtle.inspectDown()
  11. if(s == true) then
  12. return n.name
  13. else
  14. return "No Block"
  15. end
  16. end
  17. function inspectUp()
  18. local s,n = turtle.inspectUp()
  19. if(s == true) then
  20. return n.name
  21. else
  22. return "No Block"
  23. end
  24. end
  25.  
  26. function detectAround()
  27. local detection = {front = inspect(), down = inspectDown(), up = inspectUp()}
  28. turtle.turnLeft()
  29. detection = {front = detection.front, down = inspectDown(), up = inspectUp(), left = inspect()}
  30. turtle.turnLeft()
  31. detection = {front = detection.front, down = inspectDown(), up = inspectUp(), left = detection.left, back = inspect()}
  32. turtle.turnLeft()
  33. detection = {front = detection.front, down = inspectDown(), up = inspectUp(), left = detection.left, back = detection.back, right = inspect()}
  34. turtle.turnLeft()
  35. return detection
  36. end
  37.  
  38. while true do
  39. local info = nil
  40. local id, currentOrder = rednet.receive("Drone")
  41. print(currentOrder)
  42. if(currentOrder == "w") then
  43. turtle.forward()
  44. end
  45. if(currentOrder == "a") then
  46. turtle.turnLeft()
  47. end
  48. if(currentOrder == "d") then
  49. turtle.turnRight()
  50. end
  51. if(currentOrder == "s") then
  52. turtle.turnLeft()
  53. turtle.turnLeft()
  54. end
  55. if(currentOrder == "1") then
  56. turtle.dig()
  57. end
  58. if(currentOrder == "2") then
  59. turtle.digUp()
  60. end
  61. if(currentOrder == "3") then
  62. turtle.digDown()
  63. end
  64. if(currentOrder == "Down") then
  65. turtle.down()
  66. end
  67. if(currentOrder == "Up") then
  68. turtle.up()
  69. end
  70.  
  71. if(currentOrder == "Look") then
  72. local detection = detectAround()
  73. info = detection
  74. print("Left: " .. detection.left)
  75. print("Back: " .. detection.back)
  76. print("Right: " .. detection.right)
  77. end
  78.  
  79. if(info == nil) then
  80. info = { front = inspect(), up = inspectUp(), down = inspectDown()}
  81. end
  82. rednet.broadcast(info, "Remote")
  83. if(turtle.getFuelLevel() < 80) then
  84. turtle.refuel(1)
  85. end
  86. end
  87.  
Add Comment
Please, Sign In to add comment