Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- no = 0
- so = 0
- ea = 0
- we = 0
- x = 0
- z = 0
- total = 0
- t = 0
- tc = 0
- mon = peripherial.wrap("top")
- --calculate progress
- function prog()
- if total = 0 then
- sleep(1)
- else
- tp = math.floor(tc/total)
- mon.setCursorPos(1,4)
- mon.clearLine()
- mon.write("Total Progress: ")
- mon.write(tp)
- tc = tc + 1
- end
- end
- function reset()
- redstone.setBundledOutput("back", 2)
- sleep(1)
- redstone.setBundledOutput("back", 0)
- sleep(5)
- end
- function north()
- redstone.setBundledOutput("back", 16384)
- sleep(5)
- redstone.setBundledOutput("back", 0)
- z = z - 1
- sleep(5)
- end
- function south()
- redstone.setBundledOutput("back", 2048)
- sleep(1)
- redstone.setBundledOutput("back", 0)
- z = z + 1
- sleep(5)
- end
- function west()
- redstone.setBundledOutput("back", 16)
- sleep(1)
- redstone.setBundledOutput("back", 0)
- x = x - 1
- sleep(5)
- end
- function east()
- redstone.setBundledOutput("back", 8192)
- sleep(1)
- redstone.setBundledOutput("back", 0)
- x = x + 1
- sleep(5)
- end
- function fireEW()
- redstone.setBundledOutput("back", 33)
- sleep(20)
- redstone.setBundledOutput("back", 0)
- sleep(5)
- end
- function fireNS()
- redstone.setBundledOutput("back", 32776)
- sleep(20)
- redstone.setBundledOutput("back", 0)
- sleep(5)
- end
- function rpos()
- mon.setCursorPos(1,1)
- mon.clearLine()
- mon.write("Rig current position:")
- mon.setCursorPos(1,2)
- mon.clearLine()
- mon.write("X: ")
- print("Enter X coordinate")
- x = tonumber(io.read())
- mon.write(x)
- mon.write(" Z: ")
- print("Enter Z coordinate")
- z = tonumber(io.read())
- mon.write(z)
- q2()
- end
- function upos()
- mon.setCursorPos(1,2)
- mon.clearLine()
- mon.write("X: ")
- mon.write(x)
- mon.write(" Z: ")
- mon.write(z)
- end
- function mdirn()
- nu = no
- for i = 1, no do
- print("North operations left: ")
- write(nu)
- prog()
- north()
- upos()
- fireEW()
- nu = nu - 1
- end
- no = 0
- end
- function mdirs()
- local su = so
- for i = 1, so do
- print("South operations left: ")
- write(su)
- prog()
- south()
- upos()
- fireEW()
- su = su - 1
- end
- so = 0
- end
- function mdire()
- local eu = ea
- for i = 1, ea do
- print("East operations left: ")
- write(eu)
- prog()
- east()
- upos()
- fireNS()
- eu = eu - 1
- end
- ea = 0
- end
- function mdirw()
- local wu = we
- for i = 1, we do
- print("West operations left: ")
- write(wu)
- prog()
- west()
- upos()
- fireNS()
- wu = wu - 1
- end
- we = 0
- end
- function w()
- print("Mine west how many times?")
- we = tonumber(io.read())
- print("Mining west ")
- write(we)
- if we == 1 then
- write(" time. ")
- else
- write(" times. ")
- end
- q3()
- end
- function e()
- print("Mine east how many times?")
- ea = tonumber(io.read())
- print("Mining east ")
- write(ea)
- if ea == 1 then
- write(" time. ")
- else
- write(" times. ")
- end
- q3()
- end
- function n()
- print("Mine north how many times?")
- no = tonumber(io.read())
- print("Mining north ")
- write(no)
- if no == 1 then
- write(" time. ")
- else
- write(" times. ")
- end
- end
- function s()
- print("Mine south how many times?")
- so = tonumber(io.read())
- print("Mining south ")
- write(so)
- if so == 1 then
- write(" time. ")
- else
- write(" times. ")
- end
- end
- function q1()
- print("Set rig position? y/n")
- local qe1 = io.read()
- if qe1 == "y" then
- rpos()
- elseif qe1 == "n" then
- q2()
- else
- print("Invalid character. Must be y/n")
- qe1 = "v"
- q1()
- end
- end
- function q2()
- print("Mine which direction?")
- local qe2 = io.read()
- if qe2 == "north" then
- n()
- print("Accepted.")
- q3()
- elseif qe2 == "south" then
- s()
- print("Accepted.")
- q3()
- elseif qe2 == "east" then
- e()
- print("Accepted.")
- q3()
- elseif qe2 == "west" then
- w()
- print("Accepted.")
- q3()
- elseif qe2 == "cancel" then
- exit()
- else
- print("Invalid direction. Must be north")
- print("south west or east or cancel")
- qe2 = "v"
- q2()
- end
- end
- function q3()
- print("Mine any aditional directions? y/n")
- local qe3 = io.read()
- if qe3 == "y" then
- q2()
- elseif qe3 == "n" then
- mine()
- else
- print("Invalid character. Must be y/n")
- q3()
- end
- end
- function printloc()
- printer = peripheral.wrap("right")
- printer.newPage()
- printer.setPageTitle("RIG STOPPED AT")
- printer.write("X: ")
- printer.write(x)
- printer.write(" Z: ")
- printer.write(z)
- printer.endPage()
- print("Current location printout successful.")
- end
- function mine()
- print("Mining operation start.")
- total = no + we + ea + so
- if no > 0 then
- reset()
- sleep(3)
- north()
- mdirn()
- reset()
- elseif we > 0 then
- reset()
- sleep(3)
- west()
- mdirw()
- reset()
- elseif so > 0 then
- reset()
- sleep(3)
- south()
- mdirs()
- reset()
- elseif ea > 0 then
- reset()
- sleep(3)
- east()
- mdire()
- reset()
- else
- exit()
- end
- upos()
- printloc()
- end
- q1()
- reset()
- print("Mining operation complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement