Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- GPS Deploy by neonerZ v1.0 (modified for labeled computers by KaosKlaus)
- http://youtube.com/neonerz
- This script is originally from BigSHinyToys from ComputerCraft.info
- Original link can be found here:
- http://www.computercraft.info/forums2/index.php?/topic/3088-how-to-guide-gps-global-position-system/page__p__28333#entry28333
- Edited by neonerZ
- In order to use this script you need to setup
- either a mining turtle, or a standard turtle
- Mining Turtle:
- Slot 1 - Fuel
- Slot 2 - 1 Disk
- Slot 3 - At least 4 modems
- Slot 4 - At lease 1 disk drive
- Slot 5-8 - At least 4 computers (makes use of labeled computers possible)
- Standard Turtle:
- Slot 1 - Fuel
- Slot 2 - 1 Disk
- Slot 3 - At least 4 modems
- Slot 4 - At lease 4 disk drives
- Slot 5-8 - At least 4 computers (makes use of labeled computers possible)
- (mining turtles will be able to reuse the same
- disk drive, where-as a standard turtle will leave
- them and deploy a separate disk drive for each
- GPS host)
- Default Usage: Place the turtle where you want it
- deployed facing the SOUTH or 0 direction.
- Fill the turtle with the required materials
- above. Then use the command
- gps-deploy x y z
- Where x, y, z is the *absolute* positions of the deploment
- turtle. By default the turtle will deploy the
- the GPS array at around y = 254. Add a fourth
- value to specify the height offset.
- IMPORTANT: It's crucial you use your absolute coordinates,
- (the ones inside the parentheses next to your realitive coordinates)
- For Example: If F3 shows X = -6.43534 (-7) or Z = -15.542 (-16)
- you'd use -7 and -16 respectively. If you use -6 and -15 all coordinates
- that go past 0 in the opposite direction will be off by 1.)
- Example: gps-deploy 1 1 1 20
- Would assume the turtle's start position is
- x=1, y=1, z=1 and will deploy the satelite
- array at y= 21
- neonerZ added features:
- Smart Refilling: Fuel should go in slot 1.
- If not enough fuel is available script
- will prompt user for more fuel and wait 30.
- Script will estimate how much fuel is needed
- and try to take only that much (in coal)
- Item Detection: Script will check slots 2-5 //modified: 2-8
- for the correct quantity of items. It does
- *not* check if items are valid
- GPS Host Coordinates: The script now requires
- you to enter in the coordinates of the
- turtle before launching. This will set
- the GPS host computers to the correct
- coordinates.
- Satelite Array Location: The script allows
- the user to set an offset for the placement
- of the four satelites
- KaosKlaus added:
- support for labeled (non-stackable) computers
- set label for computers after placing them
- reworked fuel check
- minor fixes
- --]]
- -- ******** FUNCTIONS ********
- local function printUsage()
- print("")
- print( "Usages:" )
- print( "gps-deploy <x> <y> <z> [height]" )
- print( "Example: gps-deploy 1 1 1 20")
- print( "would deploy the satelite to y=21")
- print( "gps-deploy locate [height]")
- print( "if you have working GPS use this")
- print( "to find out the coords over GPS")
- end
- -- move functions - (original code)
- local mov = {}
- mov.forward = function ()
- while not turtle.forward() do
- sleep(1)
- end
- return true
- end
- mov.back = function ()
- while not turtle.back() do
- sleep(1)
- end
- return true
- end
- mov.up = function ()
- while not turtle.up() do
- sleep(1)
- end
- return true
- end
- mov.down = function ()
- while not turtle.down() do
- sleep(1)
- end
- return true
- end
- mov.place = function ()
- while not turtle.place() do
- sleep(1)
- end
- end
- local function selectComp()
- for i = 5,8 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- return
- end
- end
- end
- local function clearTerm()
- term.setCursorPos(1,1)
- term.clear()
- end
- local function p(text)
- term.clearLine()
- print(text)
- end
- local function clearLastLines(num)
- local x,y = term.getCursorPos()
- for i = 1,num do
- term.setCursorPos(1,y-i)
- term.clearLine()
- end
- end
- local function checkFuel()
- --[[
- Check if we have enough fuel
- we estimate the fuel usage ((height*2)+70) needed to
- complete the deoployment and then see if we have enough
- fuel loaded. If we don't, it checks the first slot for
- available fuel and tries to fill up on it. If it doesn't
- have enough fuel in there, it prompts the user for more
- fuel. It allows 30 seconds for the user to add fuel
- (trying to refuel and verify fuel level every second)
- and if it doesn't get it's fill within 30 seconds
- it exits with a message to the user
- neonerZ
- --]]
- if fuelLevel == "unlimited" then
- return true
- end
- fuelNeed = height*2+120
- if turtle.getFuelLevel() < fuelNeed then
- turtle.select(1)
- realcoal=math.ceil((fuelNeed-turtle.getFuelLevel())/80)
- while turtle.getFuelLevel() < fuelNeed do
- if turtle.getItemCount(1) <= 0 then
- for i=30,1,-1 do
- term.setCursorPos(1,4)
- p("You ran out of fuel in slot 1")
- p("Please insert "..fuelNeed-turtle.getFuelLevel().." fuel or "..realcoal.." coal to continue")
- p("Waiting "..i.." seconds for fuel or exiting")
- sleep(1)
- if turtle.refuel(1) then
- clearLastLines(4)
- print("continuing...")
- break
- end
- if i==1 then
- term.setCursorPos(1,4)
- p("Not enough fuel provided")
- p("Please provide "..fuelNeed-turtle.getFuelLevel().." fuel or "..realcoal.." coal and try again")
- p("")
- return false
- end
- end
- end
- turtle.refuel(1)
- end
- end
- return true
- end
- -- ******** MAIN PROGRAM ********
- clearTerm()
- -- check if the script is running on a turtle - (original code)
- if not turtle then
- print("")
- print("Error: not a turtle")
- return
- end
- --[[
- How high up should the satellite be deployed?
- This is the default value if you don't pass a
- value to the script. There is a check down below
- to make sure the user entered values isn't > 254
- --]]
- HEIGHT_DEFAULT = 254
- height = 0
- --[[
- confirm default height isn't set above 254
- Check to see if a minimum of 3 values were
- passed to the script
- --]]
- local tArgs = { ... }
- if tArgs[1] == "locate" then
- -- check for modem turtle and activate rednet
- if peripheral.getType("right") == "modem" then
- rednet.open( "right" )
- else
- print ("No Modem on Turtle detected, please rerun manually")
- print("")
- return
- end
- print ("Locating GPS signal...")
- xcord, ycord, zcord = gps.locate(5, false)
- if xcord==nil then
- print("")
- print ("No GPS signal detected, please rerun manually")
- return
- end
- if tArgs[2] == nil then
- height = HEIGHT_DEFAULT-ycord
- else
- height = math.min(tonumber(tArgs[2]),254-tonumber(ycord))
- end
- print ("Position: ",xcord,"/",ycord,"/",zcord," Build height: ",height+ycord)
- else
- if #tArgs < 3 or #tArgs > 4 then
- printUsage()
- return
- else
- xcord = tonumber(tArgs[1])
- ycord = tonumber(tArgs[2])
- zcord = tonumber(tArgs[3])
- if tArgs[4] == nil then
- height = HEIGHT_DEFAULT-ycord
- else
- height = math.min(tonumber(tArgs[4]),254-ycord)
- end
- end
- print ("Parameters set to:")
- print ("Position: ",xcord,"/",ycord,"/",zcord," Build height: ",height+ycord)
- end
- if not checkFuel() then
- return
- end
- --[[
- Ressource Check:
- check if the required quantity of items
- are in the appropriate spots. I'm sure
- there's a more elegant way of doing this.
- I don't believe there's a way to check if
- the items are correct without using compare
- --]]
- monitor=0
- modem=0
- diskdrive=0
- disk=0
- print("")
- if turtle.getItemCount(2) < 1 then
- print("Please place 1 disk into slot two")
- disk=1
- end
- if turtle.getItemCount(3) < 4 then
- print("Please place at least 4 modems into slot three")
- modem=1
- end
- if turtle.getItemCount(4) < 1 then
- print("Please place 1 disk drive into slot four if a -mining turtle-")
- print("Please place 4 disk drives into slot four if a -standard turtle-")
- diskdrive=1
- end
- if turtle.getItemCount(5)+turtle.getItemCount(6)+turtle.getItemCount(7)+turtle.getItemCount(8) < 4 then
- print("Please place at least 4 computers distributed over slots five, six, seven or eight")
- monitor=1
- end
- if monitor == 1 or modem == 1 or diskdrive == 1 or disk == 1 then
- print("Please fix above issues to continue")
- return
- end
- -- calculate the coordinates of the 4 satelite arrays
- newycord=tonumber(ycord)+tonumber(height)
- if newycord > 254 then newycord = 254 end
- toycordns=newycord
- toycordwe=newycord-3
- if toycordns >= 255 or toycordwe >= 255 then
- toycordns=254
- toycordwe=251
- end
- local set = {}
- set[1] = {x = tonumber(xcord),z = tonumber(zcord)+9,y = tonumber(toycordns)}
- set[2] = {x = tonumber(xcord)-9,z = tonumber(zcord),y = tonumber(toycordwe)}
- set[3] = {x = tonumber(xcord),z = tonumber(zcord)-9,y = tonumber(toycordns)}
- set[4] = {x = tonumber(xcord)+9,z = tonumber(zcord),y = tonumber(toycordwe)}
- -- start the climb up
- for i = 1,height do
- mov.up()
- end
- --[[
- once at the correct height, deploy GPS array
- this is a mixture of my own code and the
- original code
- --]]
- for a = 1,4 do
- --forward two
- for i = 1,8 do
- mov.forward()
- end
- selectComp()
- mov.place()
- mov.back()
- turtle.select(3)
- mov.place()
- mov.down()
- mov.forward()
- turtle.select(4)
- mov.place()
- turtle.select(2)
- turtle.drop()
- --[[
- make a custom disk that starts up the gps host application
- with the correct coordinates and copy it over. also makes
- makes it a startup script so the computers will
- start back up properly after chunk unloading
- --]]
- fs.delete("disk/startup")
- file = fs.open("disk/startup","w")
- -- KaosK: added shell.run command for labeling Computers
- file.write([[
- shell.run("label", "set", "GPS_Host_]]..a..[[")
- fs.copy("disk/install","startup")
- fs.delete("disk/startup")
- if fs.exists("disk/custom") then
- fs.copy("disk/custom","custom")
- fs.delete("disk/custom")
- end
- print("sleep in 10")
- sleep(10)
- os.reboot()
- ]])
- file.close()
- if fs.exists("custom") then
- fs.copy("custom","disk/custom")
- end
- file = fs.open("disk/install","w")
- file.write([[
- if fs.exists("custom") then
- shell.run("custom","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..","..(base or "nil")..[[)
- else
- shell.run("id")
- print("")
- shell.run("gps","host",]]..set[a]["x"]..","..set[a]["y"]..","..set[a]["z"]..[[)
- end
- ]])
- file.close()
- turtle.turnLeft()
- mov.forward()
- mov.up()
- turtle.turnRight()
- mov.forward()
- turtle.turnRight()
- peripheral.call("front","turnOn")
- mov.down()
- turtle.suck()
- turtle.select(3)
- turtle.dig()
- mov.up()
- -- reboot would be here
- turtle.turnRight()
- --back 3
- for i = 1,9 do
- mov.forward()
- end
- turtle.turnLeft()
- mov.forward()
- if a == 1 or a == 3 then
- for i = 1,3 do
- mov.down()
- end
- elseif a == 2 or a == 4 then
- for i = 1,3 do
- mov.up()
- end
- end
- end
- -- goes back down
- for i = 1,height do
- mov.down()
- end
- print("")
- print("Finished")
Add Comment
Please, Sign In to add comment