Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- print("Slave")
- if not peripheral.isPresent("right") then
- print("Modem not detected possible bug because the server has restarted, try debuging please wait")
- turtle.back()
- turtle.forward()
- while not peripheral.isPresent("right") do
- print("Impossible de trouver le modem, replacez la turtle")
- sleep(30)
- end
- end
- rednet.open("right")
- function newSlave()
- msg = nil
- print("En attente d'instructions")
- while msg == nil do
- rednet.broadcast("New Slave", "New Slave")
- sID, msg, prot = rednet.receive("New Slave Wait", 5)
- end
- print(msg[1])
- if msg[1] == "Miner" then
- x = msg[2]
- y = msg[3]
- pocketID = msg[4]
- xmax = msg[5]
- ymax = msg[6]
- placement()
- end
- if msg[1] == "Master" then
- pocketID = sID
- xmax = msg[2]
- ymax = msg[3]
- master()
- end
- end
- function master()
- print("je suis master")
- master = true
- looter = true
- slaveDic = {}
- slaveDic[0] = os.getComputerID()
- x = 0
- y = 0
- sx = 0
- sy = 0
- nbSlaves = 1
- ECLoot = 0
- turtle.select(1)
- while turtle.getItemDetail() == nil or turtle.getItemDetail().name ~= "EnderStorage:enderChest" do
- print("Placer l'enderchest contenant les turttles")
- sleep(1)
- end
- turtle.select(2)
- while turtle.getItemDetail() == nil or turtle.getItemDetail().name ~= "EnderStorage:enderChest" do
- print("Placer les enderchest contenant les loots")
- sleep(1)
- end
- local ECLootIntervale = 1
- nbec = turtle.getItemCount()
- while not (xmax/ECLootIntervale <= nbec) do
- ECLootIntervale = ECLootIntervale + 1
- end
- print("Intervalle ", ECLootIntervale)
- turtle.select(1)
- turtle.digUp()
- turtle.placeUp()
- turtle.dig()
- while turtle.suckUp() do
- local data = turtle.getItemDetail()
- if data and (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded") then
- turtle.place()
- msg = nil
- peripheral.wrap("front").turnOn()
- sID, msg, prot = rednet.receive("New Slave", 60)
- if msg == nil then
- print("Error: Slave not responding")
- elseif msg == "New Slave" then
- print("Send miner Instruction")
- sx = sx + 1
- if sx >= xmax then
- sx = 0
- sy = sy + 1
- end
- ECLoot = ECLoot + 1
- if ECLoot == ECLootIntervale and sy == 0 then
- turtle.select(2)
- turtle.drop(1)
- turtle.select(1)
- ECLoot = 0
- end
- rednet.send(sID, {"Miner", sx, sy, pocketID, xmax, ymax}, "New Slave Wait")
- nbSlaves = nbSlaves + 1
- slaveDic[nbSlaves] = sID
- while turtle.detect() do
- sleep(0.2)
- end
- if sy == ymax-1 and sx == xmax-1 then
- break
- end
- end
- end
- end
- print(slaveDic)
- turtle.digUp()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- end
- function placement()
- print("je suis miner")
- master = false
- if turtle.getItemDetail() ~= nil and turtle.getItemDetail().name == "EnderStorage:enderChest" then
- looter = true
- else
- looter = false
- end
- print(x, " ", y)
- z = 0
- for i=1, y*3 do
- while not turtle.up() do
- local success, data = turtle.inspectUp()
- if data.name ~= "ComputerCraft:CC-Turtle" and data.name ~= "ComputerCraft:CC-TurtleExpanded" then
- turtle.digUp()
- elseif not success then
- turtle.attackUp()
- end
- sleep(0.2)
- end
- end
- if x ~= 0 then
- turtle.turnRight()
- end
- for i = 1, x do
- while not turtle.forward() do
- local success, data = turtle.inspect()
- if data.name ~= "ComputerCraft:CC-Turtle" and data.name ~= "ComputerCraft:CC-TurtleExpanded" then
- turtle.dig()
- elseif not success then
- turtle.attack()
- end
- sleep(0.2)
- end
- end
- if x ~= 0 then
- turtle.turnLeft()
- end
- while not turtle.forward() do
- local success, data = turtle.inspect()
- if data.name ~= "ComputerCraft:CC-Turtle" and data.name ~= "ComputerCraft:CC-TurtleExpanded" then
- turtle.dig()
- elseif not success then
- turtle.attack()
- end
- sleep(0.2)
- end
- if turtle.getItemDetail() ~= nil and turtle.getItemDetail().name == "EnderStorage:enderChest" then
- looter = true
- else
- looter = false
- end
- end
- function refuel()
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.refuel(8) then
- turtle.select(1)
- return true
- end
- end
- turtle.select(1)
- return false
- end
- function mining(distance)
- print(distance)
- DistParc = 0
- turtle.digDown()
- turtle.digUp()
- while DistParc ~= distance do
- print(distance)
- while turtle.detect() do
- turtle.dig()
- end
- if turtle.forward() then
- DistParc = DistParc + 1
- turtle.digDown()
- turtle.digUp()
- else
- turtle.attack()
- end
- if DistParc/20 == math.floor(DistParc/20) then
- if turtle.getFuelLevel() < 256 then
- print("need fuel")
- refuel()
- end
- end
- end
- end
- function looting()
- empty = 1
- if y ~= 0 then
- for i=1, y*2 do
- while not turtle.down() do
- local success, data = turtle.inspectDown()
- if data.name ~= "ComputerCraft:CC-Turtle" and data.name ~= "ComputerCraft:CC-TurtleExpanded" then
- turtle.digDown()
- else
- sleep(0.2)
- end
- end
- end
- local success, data = turtle.inspectUp()
- while not (not (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded") or redstone.getInput("top")) or not vide(empty) do
- local success, data = turtle.inspectUp()
- for i=1, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- redstone.setOutput("bottom", true)
- if recup == true then
- recuperation()
- end
- while not redstone.getInput("bottom") do
- print("J'attend que les autres se vident")
- sleep(1)
- end
- redstone.setOutput("bottom", false)
- redstone.setOutput("top", true)
- while redstone.getInput("top") do
- sleep(1)
- end
- redstone.setOutput("top", false)
- for i=1, y*2 do
- while not turtle.up() do
- print("J'attend que la turtle d'en haut parte 2")
- local success, data = turtle.inspectUp()
- if success and (data.name ~= "ComputerCraft:CC-Turtle" and data.name ~= "ComputerCraft:CC-TurtleExpanded") then
- turtle.digUp()
- else
- sleep(0.2)
- end
- end
- end
- else
- turtle.turnLeft()
- side = "back"
- if looter == true then
- turtle.turnLeft()
- if master == true then
- turtle.select(2)
- if turtle.getItemCount() > 1 then
- empty = 3
- else
- empty = 2
- end
- else
- turtle.select(1)
- end
- side = "left"
- turtle.place()
- end
- if x+1 == xmax then
- local success, data = turtle.inspectUp()
- while not (not (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded") or redstone.getInput("top")) or not vide(empty) do
- local success, data = turtle.inspectUp()
- for i=empty, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- else
- while (((not ilyauneturtle("top")) and (not redstone.getInput("top"))) or (not redstone.getInput(side))) or not vide(empty) do
- for i=empty, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- if master == false then
- print("debug 1")
- if looter == true then
- turtle.select(1)
- turtle.dig()
- turtle.turnRight()
- end
- redstone.setOutput("front", true)
- end
- if not master then
- if recup == true then
- recuperation()
- end
- while not redstone.getInput("front") do
- print("J'attend que les autres se vident")
- sleep(1)
- end
- redstone.setOutput("front", false)
- redstone.setOutput("back", true)
- redstone.setOutput("top", true)
- while redstone.getInput("back") or redstone.getInput("top") do
- sleep(1)
- success, data = turtle.inspectUp()
- if not (success and (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded")) then
- break
- end
- end
- redstone.setOutput("back", false)
- redstone.setOutput("top", false)
- else
- turtle.select(2)
- turtle.dig()
- if recup == true then
- recuperation()
- end
- redstone.setOutput("top", true)
- redstone.setOutput("left", true)
- while redstone.getInput("top") or redstone.getInput("left") do
- sleep(1)
- end
- redstone.setOutput("top", false)
- redstone.setOutput("left", false)
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- end
- function vide(empty)
- for i=empty, 16 do
- turtle.select(i)
- if turtle.getItemCount() ~= 0 then
- return false
- end
- end
- turtle.select(1)
- return true
- end
- function recuperation()
- print("recuperation")
- for a, b in pairs(redstone.getSides()) do
- print(b, redstone.getOutput(b))
- end
- if master then
- rednet.broadcast(true, "Recuperation")
- turtle.turnLeft()
- turtle.select(2)
- while not (turtle.getItemCount() == nbec) do
- print("je suck")
- turtle.suck()
- sleep(0.5)
- end
- redstone.setOutput("front", true)
- turtle.digDown()
- turtle.select(1)
- turtle.placeDown()
- while (not redstone.getInput("top")) and ilyauneturtle("top") do
- if turtle.suckUp() then
- turtle.dropDown()
- else
- sleep(0.2)
- end
- end
- turtle.digUp()
- turtle.dropDown()
- while (not redstone.getInput("front")) and ilyauneturtle("front") do
- if turtle.suck() then
- turtle.dropDown()
- else
- sleep(0.2)
- end
- end
- if ilyauneturtle("front") then
- turtle.dig()
- turtle.dropDown()
- end
- turtle.digDown()
- turtle.turnLeft()
- turtle.back()
- print("Vous pouvez ramasser la turtle")
- while true do
- sleep(60)
- end
- else -- not master
- rednet.receive("Recuperation")
- redstone.setOutput("front", false)
- redstone.setOutput("bottom", false)
- sleep(0.2)
- if y == 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- while not redstone.getInput("back") do
- print("je suck")
- turtle.suck()
- sleep(0.5)
- end
- redstone.setOutput("front", true)
- while (not redstone.getInput("top")) and ilyauneturtle("top")do
- if turtle.suckUp() then
- else
- sleep(0.2)
- end
- end
- turtle.digUp()
- while (not redstone.getInput("front")) and ilyauneturtle("front") do
- if turtle.suck() then
- else
- sleep(0.2)
- end
- end
- if ilyauneturtle("front") then
- turtle.dig()
- end
- while not vide(1) do
- print("J'attend qu'on me vide")
- sleep(0.5)
- end
- redstone.setOutput("back", true)
- print("J'attend qu'on me casse")
- while true do
- sleep(60)
- end
- else -- y ~= 0
- while (not redstone.getInput("top")) and ilyauneturtle("top") do
- turtle.suckUp()
- end
- turtle.digUp()
- while not vide(1) do
- print("j'attend qu'on me vide")
- sleep(0.5)
- end
- redstone.setOutput("bottom", true)
- print("j'attend qu'on me casse")
- while true do
- sleep(60)
- end
- end
- end
- end
- function ilyauneturtle(sidetocheck)
- if sidetocheck == "top" then
- local success, data = turtle.inspectUp()
- if success and (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded") then
- return true
- else
- return false
- end
- elseif sidetocheck == "front" then
- local success, data = turtle.inspect()
- if success and (data.name == "ComputerCraft:CC-Turtle" or data.name == "ComputerCraft:CC-TurtleExpanded") then
- return true
- else
- return false
- end
- end
- end
- function main()
- newSlave()
- while true do
- print("En attente d'instructions")
- local sID, msg, prot = rednet.receive("Instruction")
- if sID == pocketID then
- if msg[1] == "Mining" then
- mining(msg[2])
- end
- if msg[1] == "Looting" then
- recup = false
- looting()
- end
- if msg[1] == "Recup" then
- recup = true
- looting()
- end
- if msg[1] == "Shutdown" then
- os.reboot()
- end
- end
- end
- end
- main()
- print("Debug")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement