Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local defaults = {
- rows = 16,
- changeRowDelay = 1,
- delayStart = 0
- }
- local pretty = require "cc.pretty"
- local usage = {
- "if multiple of the same arg are given then the last one will be used - this is redundant don't do it",
- "we will tell you the arg number which caused any errors",
- " -h | prints this usage information",
- " -r <integer/number> | number of rows to mine, defaults to 16",
- " -d <float/number> | number of seconds to wait between row change, defaults to 1 second",
- " -w <float/number> | number of seconds to wait until it starts, if not specified, starts immediately"
- }
- local function printUsage()
- blockInput = true
- print(table.concat(usage, "\n"))
- looping = false
- end
- local function myError(msg, lvl)
- printUsage()
- error(msg, lvl+1)
- end
- local writtenStates= {
- ["ropeDown"]="Mining",
- ["ropeUp"]="Pulling the miner up",
- ["nextRow"]="Moving to the next row",
- ["retractStart"]="Retracting",
- ["retractEnd"]="Ending the Program"
- }
- local args = {...}
- local maxRows = defaults.rows
- local changeRowDelay = defaults.changeRowDelay
- local delayStart = defaults.delayStart
- local row = 1
- local state = "ropeDown"
- local looping = true
- local firstLoop = true
- local blockInput = false
- local function updateStatus()
- clear()
- local screen = pretty.concat(
- pretty.text("CQP - Create Quarry Program v0.1", colours.red),
- pretty.text("______________________________________", colours.red),
- pretty.line,
- pretty.group(pretty.concat(pretty.text("Status: ", colours.orange), pretty.text(writtenStates[state], colours.white))),
- pretty.line,
- pretty.group(pretty.concat(pretty.text("Row: ", colours.orange), pretty.text(tostring(row) .. "/" .. tostring(maxRows), colours.white))),
- pretty.line,
- pretty.group(pretty.concat(pretty.text("Completed: ", colours.orange), pretty.text(tostring((row/maxRows)*100) .. "%", colours.white)))
- )
- pretty.print(screen)
- end
- if #arg > 0 then
- --lower case everything
- for i = 1, #arg do
- if not tonumber(arg[i]) then
- arg[i] = string.lower(arg[i])
- end
- end--]]
- --process arg
- local i = 1
- while i <= #arg do
- local doubleInc = false
- if arg[i] == "-h" then
- looping = false
- printUsage()
- doubleInc = false
- elseif arg[i] == "-r" then --maxRows
- local r = tonumber(arg[i+1])
- if r == nil then
- myError("arg "..i.." -r arg must be followed by a number", 2)
- elseif not ((r % 1) == 0) then
- myError("arg "..i.." -r arg must be followed by an integer number, you put a float", 2)
- end
- maxRows = r
- doubleInc = true
- elseif arg[i] == "-d" then --changeRowDelay
- local d = tonumber(arg[i+1])
- if d == nil then
- myError("arg "..i.." -d arg must be followed by a number", 2)
- end
- changeRowDelay = d
- doubleInc = true
- elseif arg[i] == "-w" then --delayStart
- local w = tonumber(arg[i+1])
- if w == nil then
- myError("arg "..i.." -w arg must be followed by a number", 2)
- end
- delayStart = w
- doubleInc = true
- else
- myError("arg "..i.." unprocessed arg",2)
- end
- if doubleInc then
- i = i +2
- else
- i = i +1
- end
- end
- end
- local function back(redstate)
- rs.setOutput("back", redstate)
- end
- local function backSwitch()
- back(not rs.getOutput("back"))
- end
- local function front(redstate)
- rs.setOutput("front", redstate)
- end
- local function frontSwitch()
- front(not rs.getOutput("front"))
- end
- local function left(redstate)
- rs.setOutput("left", redstate)
- end
- local function leftSwitch()
- left(not rs.getOutput("left"))
- end
- local function right(redstate)
- rs.setOutput("right", redstate)
- end
- local function rightSwitch()
- right(not rs.getOutput("right"))
- end
- local function top(redstate)
- rs.setOutput("top", redstate)
- end
- local function topSwitch()
- top(not rs.getOutput("top"))
- end
- local function bottom(redstate)
- rs.setOutput("bottom", redstate)
- end
- local function bottomSwitch()
- bottom(not rs.getOutput("bottom"))
- end
- local function retractEnd()
- blockInput = true
- --print("Reset Ending")
- updateStatus()
- back(false)
- right(false)
- front(false)
- bottom(false)
- top(false)
- left(false)
- looping = false
- sleep(1)
- blockInput = false
- end
- local function retractStart()
- blockInput = true
- --print("Reset Starting")
- updateStatus()
- --front(true)
- --sleep(4.5)
- back(true)
- right(true)
- sleep(1)
- state = "retractEnd"
- blockInput = false
- end
- local function ropeDown()
- blockInput = true
- --print("Sending the Drill down on row number " .. tostring(row) .. "/" .. tostring(maxRows))
- updateStatus()
- left(true)
- sleep(1)
- state = "ropeUp"
- blockInput = false
- end
- local function ropeUp()
- blockInput = true
- --print("Retracting the Drill down on row number " .. tostring(row) .. "/" .. tostring(maxRows))
- updateStatus()
- left(false)
- sleep(1)
- if row == maxRows then
- front(true)
- state = "retractStart"
- else
- state = "nextRow"
- end
- blockInput = false
- end
- local function nextRow()
- --print("Moving the Drill from row " .. tostring(row) .. "/" .. tostring(maxRows) .. " to " .. tostring(row+1) .. "/" .. tostring(maxRows) )
- updateStatus()
- front(true)
- sleep(0.5)
- right(true)
- sleep(changeRowDelay)
- row = row + 1
- updateStatus()
- right(false)
- sleep(1.5)
- front(false)
- state = "ropeDown"
- end
- local states= {
- ["ropeDown"]=ropeDown,
- ["ropeUp"]=ropeUp,
- ["nextRow"]=nextRow,
- ["retractStart"]=retractStart,
- ["retractEnd"]=retractEnd
- }
- if looping then
- if delayStart > 0 then
- sleep(delayStart)
- end
- while looping do
- if (firstLoop) then
- firstLoop = false
- ropeDown()
- end
- os.pullEvent("redstone")
- if rs.getInput("bottom") and not blockInput then
- states[state]()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment