Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local waitTime = 0.4
- local mX,mY = term.getSize()
- local function getModem()
- local h = peripheral.getNames()
- local f = false
- for i = 1,#h do
- if h[i] == "top" or h[i] == "front" then
- h = h[i]
- f = true
- break
- end
- end
- if f then
- return peripheral.wrap(h),h
- end
- return false
- end
- term.clear()
- local function writeAt(x,y,wr,fg,bg)
- fg = fg or colors.black
- bg = bg or colors.white
- local clr = string.rep(" ",mX)
- term.setCursorPos(1,y)
- term.write(clr)
- term.setCursorPos(x,y)
- term.write(wr)
- end
- local function checkInv()
- local count = 0
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- count = count + 1
- end
- end
- return count
- end
- local modem,side = getModem()
- if modem then
- writeAt(1,4,"Modem is connected.")
- modem.open(1)
- else
- writeAt(1,4,"Failed to find modem.")
- end
- local function f1()
- while true do
- if checkInv() >= 15 then
- writeAt(1,2,"Inventory full",nil,colors.gray)
- os.sleep(2)
- os.shutdown()
- end
- for i = 1,100 do
- writeAt(1,1,"Mining: " .. tostring(i))
- while not turtle.digDown() do os.sleep(waitTime/2) end
- os.sleep(waitTime)
- end
- end
- end
- local function f2()
- while true do
- local ev = {os.pullEvent("modem_message")}
- assert(ev[1] == "modem_message","This should not happen...")
- local mess = ev[5]
- if mess == "update" then
- writeAt(1,3,"UPDATING!!!")
- os.sleep(2)
- shell.run("pget")
- term.clear()
- writeAt(1,3,"DONE, REBOOTING")
- os.sleep(2)
- os.reboot()
- elseif mess == "shutdown" then
- writeAt(1,3,"Network shutdown.",nil,colors.gray)
- os.sleep(2)
- os.shutdown()
- end
- end
- end
- local ok,err = pcall(parallel.waitForAny,f1,f2)
- writeAt(1,6,"Something happened.",colors.gray)
- writeAt(1,7,err,colors.gray)
- if not err:find( "Terminated" ) then
- os.sleep(3)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement