Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --EN:
- --This program does the same thing like ScanArea, but it
- --also destroys the area.
- --
- --Download ScanArea from http://pastebin.com/1hFiZ7Ub
- --CZ:
- --Tenhle program dela to same jako ScanArea,
- --ale danou oblast znici.
- --
- --Stahnete si ScanArea z http://pastebin.com/1hFiZ7Ub
- --
- --Input ------------------------------------------
- --
- local tArgs = { ... }
- if #tArgs ~= 3 and #tArgs ~= 4 then
- print("Usage: ScanArea <x> <y> <map name>")
- return
- end
- if fs.exists(tArgs[3]) then
- print("Current file already exists")
- return
- end
- --Runned by another program?
- local runByProgram = tArgs[4] == "T"
- --Clear screen
- if runByProgram == false then
- term.clear()
- term.setCursorPos(1, 1)
- print("Info: Fuel place only in the last slot")
- print(" Run only on mining turtle")
- print("")
- end
- --
- --Main variables ---------------------------------
- --
- local VirtualMap = {}
- local X = tonumber(tArgs[1])
- local Y = tonumber(tArgs[2])
- --
- --Methods ----------------------------------------
- --
- local function CheckForAll()
- --fuel
- if turtle.getFuelLevel() == 0 then
- turtle.select(16)
- local bFirst = true
- while turtle.refuel(1) == false do
- if bFirst then
- print("Out of fuel, waiting...")
- end
- os.sleep(1)
- bFirst = false
- end
- print("Thanks!")
- turtle.select(1)
- end
- end
- local function ScanLine(index, inverted)
- local LineMap = {}
- local i = 1
- while i <= X do
- if inverted then
- LineMap[X - (i - 1)] = turtle.detectDown()
- else
- LineMap[i] = turtle.detectDown()
- end
- turtle.digDown()
- if i ~= X then
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- i = i + 1
- end
- VirtualMap[index] = LineMap
- end
- --
- --Code -------------------------------------------
- --
- local invertedLine = false
- local i = 1
- while i <= Y do
- ScanLine(i, invertedLine)
- if i ~= Y then
- CheckForAll()
- if invertedLine then
- shell.run("/rom/programs/turtle/go left forward left")
- invertedLine = false
- else
- shell.run("/rom/programs/turtle/go right forward right")
- invertedLine = true
- end
- end
- i = i + 1
- end
- --Return
- if invertedLine then
- shell.run("/rom/programs/turtle/go right")
- for n=1, (Y - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go right")
- else
- shell.run("/rom/programs/turtle/go left")
- for n=1, (Y - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go left")
- for n=1, (X - 1) do
- CheckForAll()
- shell.run("/rom/programs/turtle/go forward")
- end
- shell.run("/rom/programs/turtle/go left 2")
- end
- --
- --Save result ------------------------------------
- --
- local file = fs.open(tArgs[3], "w")
- for y=1, Y do
- local line = ""
- for x=1, X do
- if VirtualMap[y][x] then
- line = line.."1"
- else
- line = line.."0"
- end
- end
- file.writeLine(line)
- end
- file.close()
- if runByProgram == false then
- print("Scanning done, result saved")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement