Savage_Me55iah

remote turtle

Jun 11th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1.  
  2. function find_peripheral(t, e)
  3. e = e or nil
  4. sides = {[1] = "front", [2] = "back", [3] = "left", [4] = "right", [5] = "top", [6] = "bottom"}
  5. peripheral_found = false
  6. for num=1, 6 do
  7. type = peripheral.getType(sides[num])
  8. if type == t then
  9. if e == "wireless" then
  10. if peripheral.call(sides[num], "isWireless") then
  11. return sides[num]
  12. end
  13. elseif e == "remote" then
  14. if not peripheral.call(sides[num], "isWireless") then
  15. return sides[num]
  16. end
  17. elseif e == nil then
  18. return sides[num]
  19. end
  20. end
  21. end
  22. print("No " .. t .. " attached to the computer")
  23. end
  24.  
  25. function unload()
  26. turtle.select(15)
  27. turtle.placeUp()
  28. for num=1,14 do
  29. turtle.select(num)
  30. turtle.dropUp()
  31. end
  32. turtle.select(15)
  33. turtle.digUp()
  34. turtle.select(1)
  35. end
  36.  
  37. function suckall()
  38. turtle.suckUp()
  39. turtle.suckDown()
  40. repeat
  41. turtle.suck()
  42. until turtle.suck() == false
  43. unload()
  44. end
  45.  
  46. rednet.open(find_peripheral("modem", "wireless"))
  47. --names = {[1] = turtle.up(), [2] = turtle.down(), [3] = turtle.forward(), [4] = turtle.back(), [5] = turtle.turnLeft(), [6] = turtle.turnRight(), [7] = turtle.Place(), [8] = turtle.dig(), [9] = suckall()
  48. --, [10] = turtle.drop(), [11] = unload(), [12] = turtle.select(1), [13] = turtle.select(16), [14] = turtle.digDown()}
  49.  
  50. while true do
  51. e, i, x, y = os.pullEvent()
  52. if e == "rednet_message" and names[x] ~= nil then
  53. if x == 1 then turtle.up()
  54. elseif x == 2 then turtle.down()
  55. elseif x == 3 then turtle.forward()
  56. elseif x == 4 then turtle.back()
  57. elseif x == 5 then turtle.turnLeft()
  58. elseif x == 6 then turtle.turnRight()
  59. elseif x == 7 then turtle.place()
  60. elseif x == 8 then turtle.dig()
  61. elseif x == 9 then suckall()
  62. elseif x == 10 then turtle.drop()
  63. elseif x == 11 then unload()
  64. elseif x == 12 then turtle.select(1)
  65. elseif x == 13 then turtle.select(16)
  66. elseif x == 14 then turtle.digDown()
  67. end
  68. end
  69. print(e .. " " .. x)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment