Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local = arg{...}
- if arg[1] == nil then
- print("no table to save")
- return false
- end
- local of = io,open(drone,w)
- if of then
- for n,sLineB in ipairs(arg[1]) do
- of:write(sLineB)
- print(sLineB)
- of:write("\n")
- end
- of:close()
- else
- print("error could not open file")
- end
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- if turtle.up() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- local tfile = {}
- function printtbl(tbl,comment)
- print("printtbl("..tostring(tbl).."["..#tbl.."],"..tostring(comment)..")")
- for i,j in ipairs(tbl) do
- print("tbl"..tostring(comment).."- "..i..","..j)
- end
- end
- function load()
- b = io.open("drone","r")
- if b then
- local sLine = b:read()
- while sLine do
- table.insert(tfile, sLine)
- sLine = b:read()
- end
- b:close()
- end
- if #tfile == 0 then
- table.insert(tfile, "")
- end
- end
- function save()
- d = io.open("drone","w")
- if d then
- for n,sLineB in ipairs(tfile) do
- d:write(sLineB)
- print(sLineB)
- d:write("\n")
- end
- end
- d:close()
- end
- function updatePos()
- local x,y,z
- local oldx = tonumber(tfile[7])
- local oldy = tonumber(tfile[8])
- local oldz = tonumber(tfile[9])
- local gpx,gpy,gpz = gps.locate(2,true)
- if gpx then x = gpx else x = oldx end
- if gpy then y = gpy else y = oldy end
- if gpz then z = gpz else z = oldz end
- tfile[7] = tonumber(x)
- tfile[8] = tonumber(y)
- tfile[9] = tonumber(z)
- end
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- turtle.digUp()
- turtle.digDown()
- turtle.dig()
- if turtle.forward() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- turtle.digUp()
- turtle.digDown()
- return true
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- if turtle.forward() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- if turtle.back() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- local tfile = {}
- function load()
- b = io.open("drone","r")
- if b then
- local sLine = b:read()
- while sLine do
- table.insert(tfile, sLine)
- sLine = b:read()
- end
- b:close()
- end
- if #tfile == 0 then
- table.insert(tfile, "")
- end
- end
- function save()
- d = io.open("drone","w")
- if d then
- for n,sLineB in ipairs(tfile) do
- d:write(sLineB)
- print(sLineB)
- d:write("\n")
- end
- end
- d:close()
- end
- function updateFuel()
- local cur = turtle.getFuelLevel()
- local max = turtle.getFuelLimit()
- tfile[5] = "moves - "..tostring(cur)
- tfile[6] = "fuel - "..(cur/max*100).."%"
- end
- load()
- updateFuel()
- save()
- local tfile = {}
- function load()
- a,b,c = os.run({tfile},"z/load")
- print(a)
- print(b)
- print(c)
- print(tfile)
- for i,j in pairs(tfile) do
- print(i..":"..j)
- end
- end
- function send()
- local msg = "{"..os.getComputerLabel().."}"
- for n,sLineB in ipairs(tfile) do
- msg = msg.."{"..sLineB.."}"
- end
- rednet.broadcast(msg)
- end
- load()
- send()
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- turtle.turnRight()
- turtle.turnRight()
- while i < dist do
- turtle.dig()
- if turtle.forward() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- turtle.turnRight()
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- turtle.dig()
- if turtle.forward() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- local of = io.open("drone","r")
- if of then
- local sLine = of:read()
- while sLine do
- table.insert(tfile, sLine)
- sLine = of.read()
- end
- of:close()
- end
- --for i,j in pairs(tfile) do
- -- print(i..":"..j)
- -- end
- return tfile
- --print("updateDrone initiated")
- local args = {...}
- local tfile = {}
- function printtbl(tbl,comment)
- print("printtbl("..tostring(tbl).."["..#tbl.."],"..tostring(comment)..")")
- for i,j in ipairs(tbl) do
- print("tbl"..tostring(comment).."- "..i..","..j)
- end
- end
- function load()
- b = io.open("drone","r")
- if b then
- local sLine = b:read()
- while sLine do
- table.insert(tfile, sLine)
- sLine = b:read()
- end
- b:close()
- end
- if #tfile == 0 then
- table.insert(tfile, "")
- end
- end
- function save()
- d = io.open("drone","w")
- if d then
- for n,sLineB in ipairs(tfile) do
- d:write(sLineB)
- print(sLineB)
- d:write("\n")
- end
- end
- d:close()
- end
- function updatefuel()
- local cur = turtle.getFuelLevel()
- local max = turtle.getFuelLimit()
- tfile[5] = "moves - "..tostring(cur)
- tfile[6] = "fuel - "..(cur/max*100).."%"
- end
- function updatetool()
- local preSlot = turtle.getSelectedSlot()
- local space = turtle.getItemCount(15)
- local tool = "none"
- if space < 1 then
- turtle.select(16)
- turtle.equipLeft()
- sleep(1/10)
- tool = turtle.getItemDetail()
- sleep(1/10)
- --printtbl(tool)
- turtle.equipLeft()
- turtle.select(preSlot)
- tfile[4] ="tool - "..tostring(tool[name])
- end
- end
- function updatePos()
- local x,y,z
- local oldx = tonumber(tfile[7])
- local oldy = tonumber(tfile[8])
- local oldz = tonumber(tfile[9])
- local gpx,gpy,gpz = gps.locate(2,true)
- if gpx then x = gpx else x = oldx end
- if gpy then y = gpy else y = oldy end
- if gpz then z = gpz else z = oldz end
- tfile[7] = tonumber(x)
- tfile[8] = tonumber(y)
- tfile[9] = tonumber(z)
- end
- function update()
- load()
- updatetool()
- updatefuel()
- updatePos()
- term.clear()
- term.setCursorPos(1,1)
- save()
- end
- --print("Load Complete")
- update()
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- if turtle.down() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- turtle.turnLeft()
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- turtle.digDown()
- if turtle.down() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
- local args = {...}
- local dist = 1
- if args[1] then dist = tonumber(args[1]) end
- local i = 0
- local hit = false
- local hitc = 0
- if not (dist > 0) then dist = 1 end
- while i < dist do
- turtle.digUp()
- if turtle.up() then
- i = i + 1
- else
- print("I hit Something")
- sleep(1/4)
- hitc = hitc + 1
- end
- if hitc > dist/2 then
- print("hit = "..hitc)
- return false end
- end
- return true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement