Advertisement
Guest User

mainProg

a guest
Jun 18th, 2013
15,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. rednet.open("right")
  2. local miners = {}
  3. local loaders = {}
  4. local fuelBosses = {}
  5. local tArgs = {...}
  6.  
  7.  
  8. function findTurtles()
  9.    local gotMsg = true
  10.    local id, msg, dist
  11.    rednet.broadcast("checkIn")
  12.    while gotMsg do
  13.       id,msg,dist = rednet.receive(1)
  14.       if msg == "Miner" then
  15.          print(id..":"..msg)
  16.          miners[#miners+1] = id
  17.       elseif msg == "chunkloader" then
  18.          print(id..":"..msg)
  19.          loaders[#loaders+1] = id
  20.       elseif msg == "fuelBoss" then
  21.          print(id..":"..msg)
  22.          fuelBosses[#fuelBosses+1] = id
  23.          miners[#miners+1] = id
  24.       elseif msg == "Done" then
  25.       else
  26.          print("Done")
  27.          gotMsg = false
  28.       end
  29.    end      
  30. end
  31.  
  32. function checkFuel()
  33.    if turtle.getFuelLevel() < 900 then
  34.       rednet.send(fuelBosses[1], "fuelBoss")
  35.       rednet.receive()
  36.       turtle.select(3)
  37.       turtle.refuel()
  38.       turtle.select(1)
  39.    end
  40. end
  41.  
  42. function place()
  43.    turtle.select(1)
  44.    turtle.place()
  45.    turtle.down()
  46.    turtle.select(2)
  47.    turtle.place()
  48.    turtle.attack()
  49. end
  50.  
  51. function remove()
  52.    turtle.select(2)
  53.    turtle.dig()
  54.    turtle.up()
  55.    turtle.select(1)
  56.    turtle.dig()
  57. end
  58.  
  59. function minersGo()
  60.    for x,y in pairs(miners) do
  61.       rednet.send(y, "cycle")
  62.    end
  63.    place()
  64.    local total = 0
  65.    while total < #miners do
  66.       local id,msg,dist=rednet.receive()
  67.       total = total+1
  68.    end  
  69.    remove()
  70. end
  71.  
  72. function moveLoaders()
  73.    for x,y in pairs(loaders) do
  74.       rednet.send(y,"chunkLoad")
  75.       rednet.receive()
  76.       sleep(0.5)
  77.    end
  78. end
  79.  
  80. findTurtles()
  81. if tArgs[1] == nil then tArgs[1] = 1 end
  82. for i = 1,tArgs[1] do
  83.    print("Interation: "..tostring(i).." of "..tostring(tArgs[1]))
  84.    minersGo()
  85.    turtle.forward()
  86.    checkFuel()
  87.    moveLoaders()
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement