Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs < 4 then
- print("Usage : gpsbuild <x> <y> <z> <f>")
- return
- end
- local databaseID = 0 -- Set me
- local Xpos = tonumber(tArgs[1])
- local Ypos = tonumber(tArgs[2])
- local Zpos = tonumber(tArgs[3])
- local facing = tonumber(tArgs[4])
- function buildUp(floppySlot)
- -- Place the disk drive
- turtle.select(3)
- turtle.place()
- -- Load disk into drive and write startup file
- turtle.select(floppySlot)
- turtle.drop()
- file = fs.open("disk/startup","w")
- file.writeLine("fs.copy(\"disk/actualStartup\",\"startup\")" )
- file.writeLine("fs.copy(\"disk/gbang\",\"gbang\")" )
- file.writeLine("fs.copy(\"disk/config\",\"config\")" )
- file.close()
- configFile = fs.open("disk/config","w")
- configFile.writeLine("X = "..Xpos)
- configFile.writeLine("Y = "..Ypos)
- configFile.writeLine("Z = "..Zpos)
- configFile.close()
- -- Place the computer
- turtle.up()
- turtle.select(2)
- turtle.place()
- -- Place the modem
- turtle.up()
- turtle.up()
- turtle.forward()
- turtle.select(4)
- turtle.placeDown()
- turtle.back()
- turtle.down()
- turtle.down()
- -- Turn computer on
- computer = peripheral.wrap("front")
- sleep(0.5)
- if computer then
- computer.turnOn()
- end
- turtle.down()
- turtle.select(3)
- turtle.dig()
- turtle.select(4)
- end
- if type(Xpos) ~= "number" then
- print("x must be number")
- return
- end
- if type(Ypos) ~= "number" then
- print("y must be number")
- return false
- end
- if type(Zpos) ~= "number" then
- print("z must be number")
- return false
- end
- if type(facing) ~= "number" then
- print("facing must be number")
- return false
- end
- print("Please fill up following slots")
- print("1 = Fuel")
- print("2 = Computer (4x)")
- print("3 = Disk drive (1x)")
- print("4 = Modem (4x)")
- print("5 - 8 = Floppy disk (4x)")
- print("Press any key to continue")
- while true do
- event, param1 = os.pullEvent()
- if event == "char" then
- break
- end
- end
- while turtle.getItemCount(1) > 0 do
- turtle.refuel()
- end
- print("Fuel level is "..turtle.getFuelLevel())
- if turtle.getFuelLevel() <= 200 then
- print("Not enough fuel to complete the given task")
- print("Do you want to continue? Y/N")
- while true do
- local ev2,char2 = os.pullEvent("char")
- if char == "y" then
- break
- elseif char == "n" then
- os.reboot()
- end
- end
- print("Going up 100 meters to build a GPS station")
- for height = 1, 100, 1 do
- turtle.up()
- end
- Ypos = Ypos + 101
- -- Go forward 10 to place 1st computer
- for c = 1, 10, 1 do
- turtle.forward()
- end
- if facing == 0 then
- Zpos = Zpos + 11
- end
- if facing == 2 then
- Zpos = Zpos - 11
- end
- if facing == 1 then
- Xpos = Xpos - 11
- end
- if facing == 3 then
- Xpos = Xpos + 11
- end
- buildUp(5)
- -- Go back 20 then place the second computer
- turtle.turnRight()
- turtle.turnRight()
- if facing == 0 then
- facing = 2
- elseif facing == 1 then
- facing = 3
- elseif facing == 2 then
- facing = 0
- elseif facing == 3 then
- facing = 1
- end
- for c = 1, 20, 1 do
- turtle.forward()
- end
- if facing == 0 then
- Zpos = Zpos + 22
- end
- if facing == 2 then
- Zpos = Zpos - 22
- end
- if facing == 1 then
- Xpos = Xpos - 22
- end
- if facing == 3 then
- Xpos = Xpos + 22
- end
- buildUp(6)
- -- go forward to the middle of the station
- turtle.turnRight()
- turtle.turnRight()
- if facing == 0 then
- facing = 2
- elseif facing == 1 then
- facing = 3
- elseif facing == 2 then
- facing = 0
- elseif facing == 3 then
- facing = 1
- end
- for c = 1, 10, 1 do
- turtle.forward()
- end
- if facing == 0 then
- Zpos = Zpos + 11
- end
- if facing == 2 then
- Zpos = Zpos - 11
- end
- if facing == 1 then
- Xpos = Xpos - 11
- end
- if facing == 3 then
- Xpos = Xpos + 11
- end
- -- and 10 more up
- for c = 1, 10, 1 do
- turtle.up()
- end
- Ypos = Ypos + 10
- -- turn right to setup the second row
- turtle.turnRight()
- facing = facing + 1
- if facing == 4 then
- facing = 0
- end
- -- Go forward 10 to place the third computer
- for c = 1, 10, 1 do
- turtle.forward()
- end
- if facing == 0 then
- Zpos = Zpos + 11
- end
- if facing == 2 then
- Zpos = Zpos - 11
- end
- if facing == 1 then
- Xpos = Xpos - 11
- end
- if facing == 3 then
- Xpos = Xpos + 11
- end
- buildUp(7)
- -- Go back 20 and place the last computer
- turtle.turnRight()
- turtle.turnRight()
- if facing == 0 then
- facing = 2
- elseif facing == 1 then
- facing = 3
- elseif facing == 2 then
- facing = 0
- elseif facing == 3 then
- facing = 1
- end
- for c = 1, 20, 1 do
- turtle.forward()
- end
- if facing == 0 then
- Zpos = Zpos + 22
- end
- if facing == 2 then
- Zpos = Zpos - 22
- end
- if facing == 1 then
- Xpos = Xpos - 22
- end
- if facing == 3 then
- Xpos = Xpos + 22
- end
- buildUp(8)
- -- go forward 10 to the middle
- turtle.turnRight()
- turtle.turnRight()
- for c = 1, 10, 1 do
- turtle.forward()
- end
- -- and back to earth
- while not turtle.detectDown() do
- turtle.down()
- end
- print("Finished!")
- return true
Advertisement
Add Comment
Please, Sign In to add comment