Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- number of seconds before rebooting the machine, use -1 to disable
- local timeToReboot = 300
- --time in seconds between updates
- local sleepTime = 0.5
- local seconds = 0
- function SecondsToClock(sSeconds)
- local nSeconds = tonumber(sSeconds)
- if nSeconds == 0 then
- return "00:00:00";
- else
- nHours = string.format("%02d", math.floor(nSeconds/3600));
- nMins = string.format("%02d", math.floor(nSeconds/60 - (nHours*60)));
- nSecs = string.format("%02d", math.floor(nSeconds - nHours*3600 - nMins *60));
- return nHours..":"..nMins..":"..nSecs
- end
- end
- local w,h = term.getSize()
- function printStatus()
- term.clear()
- local clockTime = "Time: "..SecondsToClock(seconds)
- term.setCursorPos(w - #clockTime+1, 1)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(clockTime)
- if timeToReboot > 0 then
- local rebootDisplay = "Reboot in: "..string.format("%d",(timeToReboot - seconds))
- term.setCursorPos(w - #rebootDisplay+1, 2)
- term.write(rebootDisplay)
- end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- local isRunning = true
- local reboot = false
- local hitup = 0
- while isRunning do
- printStatus()
- turtle.attack()
- hitup = hitup + 1
- if hitup > 5 then
- hitup = 0
- turtle.attackUp()
- end
- turtle.suck()
- turtle.suckUp()
- if timeToReboot > 0 and seconds >= timeToReboot then
- term.clear()
- term.setCursorPos(1,1)
- term.write("Rebooting...")
- reboot = true
- isRunning = false
- sleep(2)
- else
- seconds = seconds + sleepTime
- sleep(sleepTime)
- end
- end
- if reboot then os.reboot() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement