Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if peripheral.getType("right") ~= "modem" and peripheral.getType("left") ~= "modem" then
- error("Need a modem for a swarmbot main-pc")
- end
- function installDiskDriver()
- turtle.forward()
- turtle.turnLeft()
- if fs.exists("/disk/startup") then
- fs.delete("/disk/startup")
- sleep(5)
- end
- file = fs.open("/disk/startup", "w")
- file.writeLine([[
- shell.run("rm","data")
- shell.run("rm","startup")
- shell.run("rm","swarmBot")
- shell.run("rm","movementApi")
- shell.run("rm","gpsApi")
- shell.run("rm","digApi")
- ]])
- file.writeLine("shell.run('pastebin', 'get', 'gXF1tY1Y', 'swarmBot')")
- file.writeLine(
- [[
- file = fs.open('startup','w')
- file.writeLine("sleep(1)")
- file.writeLine("shell.run('swarmBot')")
- file.close()
- shell.run('swarmBot')
- ]]
- )
- file.close()
- print("Set config")
- turtle.turnRight()
- turtle.back()
- end
- function bigRegisterFunction()
- local position = vector.new(gps.locate(10))
- local chunk = {math.floor(position.x / 16), math.floor(position.y / 16)}
- local input = nil
- local config = {
- chunk = {},
- directions = {},
- parkHeight = 85,
- flyHeight = 85
- }
- print("Swarmbot main-pc registration")
- print("-----------------------------")
- print("My current chunk is " .. chunk[1] .. "," .. chunk[2])
- print("Is this correct? y/n")
- while true do
- input = read():lower()
- if input == "n" then
- error("I'm not in the correct chunk?")
- else
- config.chunk[1] = chunk[1]
- config.chunk[2] = chunk[2]
- input = nil
- break
- end
- end
- print("At which level should working turtle's home?")
- print("Default is my height + 4, which is currently: " .. position.z + 4)
- while true do
- input = tonumber(read())
- if input == "" or input == nil then
- config.parkHeight = position.z + 4
- break
- elseif type(input) == "number" and input < 256 then
- config.parkHeight = input
- input = nil
- break
- else
- print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
- end
- end
- print("At which level should working turtle's fly?")
- print("Default is my height + 12, which is currently: " .. position.z + 12)
- while true do
- input = tonumber(read())
- if input == "" or input == nil then
- config.flyHeight = position.z + 8
- break
- elseif type(input) == "number" and input < 256 then
- config.flyHeight = input
- input = nil
- break
- else
- print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
- end
- end
- print("At which level should working turtle's start?")
- print("Default is my height, which is currently: " .. position.z)
- while true do
- input = tonumber(read())
- if input == "" or input == nil then
- config.startHeight = position.z
- break
- elseif type(input) == "number" and input < 256 then
- config.startHeight = input
- input = nil
- break
- else
- print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
- end
- end
- print("Where should I work toward")
- print("(note that I mine to the left side)")
- print("String should contain N E S or W (or a combination)")
- while true do
- input = read()
- if input ~= nil and input ~= "" then
- if type(input) ~= "string" then
- print("Wrong input? Input should be string, was: " .. type(input) .. " with a value of " .. input)
- else
- if string.match(input:lower(), "n") then
- config.directions[#config.directions + 1] = "n"
- end
- if string.match(input:lower(), "e") then
- config.directions[#config.directions + 1] = "e"
- end
- if string.match(input:lower(), "s") then
- config.directions[#config.directions + 1] = "s"
- end
- if string.match(input:lower(), "w") then
- config.directions[#config.directions + 1] = "w"
- end
- if
- not string.match(input:lower(), "w") and not string.match(input:lower(), "s") and
- not string.match(input:lower(), "e") and
- not string.match(input:lower(), "n")
- then
- print("Wrong input? Input should include atleast n,e,s or w")
- else
- break
- end
- end
- end
- end
- print("Whats the max length I can go in chunks")
- print("Default is 128")
- while true do
- input = tonumber(read())
- if input == "" or input == nil then
- config.maxLength = 128
- break
- elseif type(input) == "number" then
- config.maxLength = input
- input = nil
- break
- else
- print("Wrong input? Input should be number, was: " .. type(input) .. " with a value of " .. input)
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("My config is as follows:")
- print("Home chunk: " .. config.chunk[1] .. "," .. config.chunk[2])
- print("Turtle's park at this height: " .. config.parkHeight)
- print("Turtle's start at this height: " .. config.startHeight)
- print("Turtle's flies at this height: " .. config.flyHeight)
- local directions = ""
- for i = 1, #config.directions do
- if config.directions[i] ~= nil then
- directions = directions .. tostring(config.directions[i]) .. " "
- end
- end
- print("I'm going to mine towards: " .. directions)
- print("I'm going to mine a lenght of: " .. config.maxLength .. " chunks")
- print("Is this all correct? y/n")
- while true do
- input = read()
- if input ~= nil or input ~= "" then
- if input == "n" then
- term.clear()
- term.setCursorPos(1, 1)
- bigRegisterFunction()
- else
- input = nil
- break
- end
- end
- end
- print("Saving input.")
- local file = fs.open("data/config", "w")
- file.writeLine(textutils.serialize(config))
- file.close()
- term.clear()
- term.setCursorPos(1, 1)
- print("Should I install the disk driver? y/n")
- while true do
- input = read():lower()
- if input == "y" then
- installDiskDriver()
- break
- elseif input == "n" then
- break
- end
- sleep(1)
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- bigRegisterFunction()
Advertisement
Add Comment
Please, Sign In to add comment