Guest User

server

a guest
Jul 16th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. --[[
  4.     You have to edit some variables to make the program work
  5.     Start here
  6. --]]
  7.  
  8. --You have to add the ids of your turtles to the list like below. REPLACE/DELETE THE OLD IDS
  9. turtles = {}
  10. turtles[1] = 43
  11. turtles[2] = 45
  12. turtles[3] = 46
  13. turtles[4] = 47
  14. turtles[5] = 48
  15. turtles[6] = 49
  16. turtles[7] = 50
  17. turtles[8] = 51
  18. turtles[9] = 52
  19. turtles[10] = 53
  20. turtles[11] = 56
  21. turtles[12] = 57
  22. turtles[13] = 58
  23. turtles[14] = 59
  24. turtles[15] = 60
  25. turtles[16] = 61
  26. turtles[17] = 62
  27. turtles[18] = 63
  28.  
  29. --Same as above. The ids of the two chunkloader turtles are saved in that table
  30. chunkloadert = {}
  31. chunkloadert[1] = 54
  32. chunkloadert[2] = 65
  33. local chunknum = table.getn(chunkloadert)
  34. local num = table.getn(turtles)
  35.  
  36. --Replace 43 with the id of the turtle directly left to the server/master turtle
  37. local idOfRefuelTurtle = 43
  38.  
  39. --[[
  40.     Dont edit the code below. Only edit the code before this comment
  41. --]]
  42.  
  43. function checkFuelClient()
  44.  for i=1,num,1 do
  45.   rednet.send(turtles[i],"refuel")
  46.   id,msg = rednet.receive()
  47.   while not(id == turtles[i]) or not(msg == "done") do
  48.    print("Error while refueling clients!")
  49.    os.sleep(5)
  50.   end
  51.  end
  52. end
  53.  
  54. function checkFuelServer()
  55.  if turtle.getFuelLevel() < 100 then
  56.   rednet.send(idOfRefuelTurtle ,"refuelM")
  57.   turtle.up()
  58.   turtle.turnLeft()
  59.   turtle.select(1)
  60.   turtle.suck()
  61.   shell.run("refuel all")
  62.   turtle.turnRight()
  63.   turtle.down()
  64.   rednet.send(idOfRefuelTurtle,"done")
  65.  end
  66. end
  67.  
  68. function cycle()
  69.  turtle.up()
  70.  turtle.select(15)
  71.  turtle.place()
  72.  turtle.up()
  73.  turtle.select(16)
  74.  turtle.place()
  75.  turtle.down()
  76.  turtle.attack()
  77.  turtle.down()
  78.  turtle.select(14)
  79.  turtle.place()
  80.  for i=1,num,1 do
  81.   rednet.send(turtles[i],"cycle")
  82.  end
  83.  os.sleep(30)
  84.  turtle.dig()
  85.  turtle.up()
  86.  turtle.up()
  87.  turtle.select(16)
  88.  turtle.dig()
  89.  turtle.down()
  90.  turtle.select(15)
  91.  turtle.dig()
  92.  turtle.down()
  93. end
  94.  
  95. function moveChunkLoaders()
  96.  for i=1,chunknum,1 do
  97.   rednet.send(chunkloadert[i], "move")
  98.   id,msg = rednet.receive()
  99.   os.sleep(1)
  100.  end
  101. end
  102.  
  103. while true do
  104.  while turtle.detect() do print("Block detected. Remove it if you want me to continue!") os.sleep(10) end
  105.  moveChunkLoaders()
  106.  checkFuelClient()
  107.  checkFuelServer()
  108.  cycle()
  109.  turtle.forward()
  110.  for i=1,num,1 do rednet.send(turtles[i],"go") end
  111.  os.sleep(1)
  112. end
Advertisement
Add Comment
Please, Sign In to add comment