Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------Initialization--------
- local digTime = 7 --seconds
- local iterations = 0
- local cell = peripheral.wrap("back")
- local glass = peripheral.wrap("right")
- local power = cell.getEnergyStored()
- local maxPower = cell.getMaxEnergyStored()
- local percentage = (power / maxPower) * 100
- local commandString = "null"
- local commandNum = 0
- local tempNum = 0 --used in attempt to fix commandNum
- local dontPrintData = false
- local iterationError = false
- local isChatCommand = false
- local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
- -------------Functions-------------
- local function listenForCommand()
- while true do
- event, command = os.pullEvent("chat_command")
- print(event.." "..command)
- isChatCommand = true
- end
- end
- local function checkCommand()
- local tempCount = 0
- for i in string.gmatch(command, "%S+") do
- tempCount = tempCount + 1
- print(i)
- if tempCount == 1 then
- commandString = i
- elseif tempCount == 2 then
- commandNum = i
- end
- if commandString == "mine" then
- tonumber(commandNum)
- tempNum = commandNum + 1
- else
- term.setTextColor(colors.red)
- print("Invalid Command")
- term.setTextColor(colors.white)
- end
- end
- end
- local function getData()
- term.setTextColor(colors.white)
- power = cell.getEnergyStored()
- maxPower = cell.getMaxEnergyStored()
- if dontPrintData == false then
- print(power .. "RF out of " .. maxPower .. "RF")
- end
- percentage = (power / maxPower) * 100
- if dontPrintData == false then
- print("aka " .. percentage .. "%")
- end
- end
- local function updateGlass()
- glass.clear()
- glass.addBox(1,1,150,65,0x000000,0.2)
- glass.addText(6,6,"Current Power",0xCC4C4C)
- glass.addText(6,20,power .. "RF / " .. maxPower .. "RF")
- glass.addText(17,34,percentage .. " %",0xF2B233)
- --if rs.getInput("back") == true then
- --glass.addText(63,51,"GENERATORS ON",0xCC4444)
- --end
- end
- local function moveFrame()
- local blueInput = colors.test(rs.getBundledInput("top",colors.blue))
- if blueInput == true then
- rs.setBundledOutput("top",colors.red) --> wireless transmitter
- sleep(.5)
- rs.setBundledOutput("top",0)
- end
- end
- local function dig()
- local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
- local splitDigTime = digTime / 4
- if not blueInput then
- rs.setBundledOutput("top",colors.black) -->allows tesseract to transmit power
- term.setTextColor(colors.green)
- term.write("Iteration "..iterations)
- dontPrintData = true
- sleep(splitDigTime)
- for i=1,2 do
- term.write(".")
- getData()
- updateGlass()
- term.setTextColor(colors.green)
- sleep(splitDigTime)
- end
- print(".")
- dontPrintData = false
- getData()
- updateGlass()
- sleep(splitDigTime)
- rs.setBundledOutput("top",0)
- else
- term.setTextColor(colors.red)
- term.write("Skipped Iteration "..iterations)
- sleep(splitDigTime)
- dontPrintData = true
- for i=1,2 do
- term.write(".")
- getData()
- updateGlass()
- term.setTextColor(colors.red)
- sleep(splitDigTime)
- end
- print(",")
- dontPrintData = false
- getData()
- updateGlass()
- sleep(splitDigTime)
- end
- end
- local function mine()
- print("Mining Process Started with "..iterations.." iterations...")
- if iterations == 0 then
- term.setTextColor(colors.red)
- print("Error: 0 Iterations?")
- term.setTextColor(colors.white)
- iterationError = true
- else
- iterationError = false
- end
- while iterations > 0 do
- getData()
- updateGlass()
- moveFrame()
- dig()
- end
- end
- ------------Main Program----------
- local function main()
- while true do
- getData()
- updateGlass()
- if isChatCommand == true then
- isChatCommand = false
- checkCommand()
- if commandString == "mine" then
- iterations = tempNum - 1
- mine()
- end
- commandString = "null"
- commandNum = 0
- end
- sleep(1)
- end
- end
- parallel.waitForAny(main,listenForCommand)
Advertisement
Add Comment
Please, Sign In to add comment