gknova61

Robot Fleet (Client)

Oct 4th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. osPullEvent = osPullEventRaw
  2. shell.run("cd","..")
  3. shell.run("cd","disk")
  4. shell.run("cp","startup","startup")
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. local function start()
  8. local correctid = 212 --Set this to whatever the server id
  9.     rednet.open("left")
  10.     rednet.send(correctid, "getturtleID")
  11.         g,TurtleNetID = rednet.receive(5)
  12.         TurtleNetID = TurtleNetID .. " "
  13. --print("Robot Fleet ID:"..TurtleNetID.. )
  14.         rednet.send(correctid, "New turtle at " .. gps.locate(20, false))
  15. if TurtleNetID == nil then
  16.     print("Could not get TurtleNet ID, please ctrl+t and try again")
  17. end
  18. running = 1
  19. while running == 1 do
  20. I,m,d = rednet.receive()
  21. if I ~== correctid then
  22.     start()
  23. end
  24. if m == TurtleNetID .. "location" then
  25.     rednet.send(I, gps.locate(20, false))
  26. end
  27. if m == TurtleNetID .. "forward" then
  28.         if turtle.forward() == false then
  29.         rednet.send(I, "Error moving forwards")
  30.     end
  31. end
  32. if m == TurtleNetID .. "back" then
  33.     turtle.backward()
  34.     if turtle.backward() == false then
  35.     rednet.send(I, "Error moving backwards")
  36.     end
  37. end
  38. if m == TurtleNetID .. "up" then
  39.     if turtle.up() == false then
  40.     rednet.send(I, "Error moving up")
  41.     end
  42. end
  43. if m == TurtleNetID .. "down" then
  44.     turtle.down
  45.     if turtle.down() == false then
  46.     rednet.send(I, "Error moving down")
  47.     end
  48. end
  49. if m == TurtleNetID .. "turn left" then
  50.     turtle.turnLeft()
  51.     rednet.send(I, "Turned left")
  52. end
  53. if m == TurtleNetID .. "turn right" then
  54.     turtle.turnRight()
  55.     rednet.send(I, "Turned right")
  56. end
  57. if m == TurtleNetID .. "dig front" then
  58.     turtle.dig()
  59.     rednet.send(I, "Dug front")
  60. end
  61. if m == TurtleNetID .. "dig up" then
  62.     turtle.digUp()
  63.     rednet.send(I, "Dug up")
  64. end
  65. if m == TurtleNetID .. "dig down" then
  66.     turtle.digDown()
  67.     rednet.send(I, "Dug down")
  68. end
  69. if m == TurtleNetID .. "place front" then
  70.     if turtle.place() == false then
  71.     rednet.send(I, "Error placing in front")
  72.     end
  73. end
  74. if m == TurtleNetID .. "place up" then
  75.     if turtle.placeUp() == false then
  76.     rednet.send(I, "Error placing up")
  77. end
  78. if m == TurtleNetID .. "place down" then
  79.     if turtle.placeDown() == false then
  80.         rednet.send(I, "Error placing up")
  81.     end
  82. end
  83. if m == TurtleNetID .. "detect front" then
  84.     if turtle.detect == "true" then
  85.         rednet.send(I, "Block in front")
  86.     end
  87. end
  88. if m == TurtleNetID .. "detect up" then
  89.     if turtle.detectUP() == false then
  90.         ednet.send(I, "Block up")
  91.     end
  92. end
  93. if m == TurtleNetID .. "detect down" then
  94.     if turtle.detectDown() == false then
  95.         rednet.send(I, "Block down")
  96.     end
  97. end
  98. if m == TurtleNetID .. "spew" then
  99.     turtle.drop()
  100. end
  101. if m == "reset ID" then
  102.     rednet.send(I, TurtleNetID)
  103. end
  104. if m == "report in" then
  105.     rednet.send(I, "Turtle ID ".. TurtleNetID .. " reporting in from " gps.locate(20, false))
  106. end
  107. if m == TurtleNetID .. "terminate" then
  108.     running = 0
  109. end
  110. I,m,d = 0
  111. end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment