Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SERVER_PORT = 0
- local CLIENT_PORT = 10
- term.clear()
- term.setCursorPos(1, 1)
- local segmentation = 5
- if (#arg == 1) then
- segmentation = tonumber(arg[1])
- print("Segmentation size set to", segmentation)
- elseif (#arg == 0) then
- print("No segmentation size selected, defaulting to", segmentation)
- else
- error('Too many args given...')
- end
- local endX, endY, endZ = gps.locate()
- endX = math.floor(endX)
- endY = math.floor(endY + 2)
- endZ = math.floor(endZ)
- local modem = peripheral.wrap("right")
- modem.open(SERVER_PORT)
- function getItemIndex(itemName)
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item ~= nil then
- if item.name == itemName then
- return slot
- end
- end
- end
- end
- function deploy(cords)
- numm = getItemIndex("computercraft:turtle_advanced")
- if numm == nil then
- turtle.suckDown(1)
- turtle.select(getItemIndex("computercraft:turtle_advanced"))
- else
- turtle.select(numm)
- end
- while (turtle.detect()) do
- sleep(0.3)
- end
- turtle.place()
- peripheral.call("front", "turnOn")
- event, side, senderChannel, replyChannel, msg, distance = os.pullEvent("modem_message")
- if msg ~= "CLIENT_DEPLOYED" then
- error("No client deploy message, exitting...")
- end
- --drop thing for the turtle to have on them--
- modem.transmit(CLIENT_PORT, SERVER_PORT, cords)
- print("Deploying bot to", cords[1], cords[2], cords[3])
- end
- function round(number, segment)
- --check if remander = 0--
- if number % segment ~= 0 then
- --if not then get the remander--
- remander = number % segment
- --work out deveden--
- --example 11 % 5 = 5, remander 1, because 5 times 2 plus 1 = 11
- --remove remander from number to round down to the closest mulitpul of the segment
- down = number - remander
- --devide rounded down number buy segmnet number to get diveden
- div = down / segment
- times = div
- --rounded = times * segment
- return times, remander
- else
- times = number / segment
- times = times - 1
- return times, 5
- end
- end
- function sendBots(xStart, zStart, xSize, zSize, cords, seg)
- xCount, xRound = round(xSize, seg)
- zCount, zRound = round(zSize, seg)
- xNum = xCount + 1
- zNum = zCount + 1
- num = xNum * zNum
- if num > 1 then
- printError("Deploying", num, "bots...")
- else
- printError("Deploying", num, "bot...")
- end
- number = cords[1]
- zOffset = cords[3]
- for z = 1, xCount do
- xOffset = number
- for x = 1, zCount do
- cords[1] = xOffset
- cords[3] = zOffset
- cords[4] = seg
- cords[6] = seg
- deploy(cords)
- xOffset = xOffset - seg
- end
- cords[1] = xOffset
- cords[3] = zOffset
- cords[4] = xRound
- cords[6] = seg
- deploy(cords)
- zOffset = zOffset - seg
- end
- xOffset = number
- for x = 1, xCount do
- cords[1] = xOffset
- cords[3] = zOffset
- cords[4] = seg
- cords[6] = zRound
- deploy(cords)
- xOffset = xOffset - seg
- end
- cords[1] = xOffset
- cords[3] = zOffset
- cords[4] = xRound
- cords[6] = zRound
- deploy(cords)
- end
- while true do
- printError("Waiting for target signal...")
- event, side, senderChannel, replyChannel, cord, distance = os.pullEvent("modem_message")
- print("RECEIVED QUARY REQUEST AT:", cord[1], cord[2], cord[3])
- cord[7] = endX
- cord[8] = endY
- cord[9] = endZ
- sendBots(cord[1], cord[3], cord[4], cord[6], cord, segmentation)
- event, side, senderChannel, replyChannel, msg, distance = os.pullEvent("modem_message")
- turtle.digUp()
- term.clear()
- term.setCursorPos(1, 1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement