Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- local queue = {}
- while true do
- local sender, message = rednet.receive("printer")
- if message == "ping" then
- print("Received ping from "..sender)
- rednet.send(sender,"Hydro's Office","printer")
- elseif message == "print" then
- print("Received print from "..sender)
- while true do
- local sender2, message2 = rednet.receive("printer",2)
- if sender2 == sender then
- print("Executing print")
- local points = {message2:find(" ")}
- local words = {}
- if #points == 0 then
- words = {message2}
- elseif #points == 1 then
- words = {message2:sub(1,points[1]-1),message2:sub(points[1]+1)}
- else
- words = {message2:sub(1,points[1]-1)}
- for i = 2,#points-1 do
- table.insert(words,message2:sub(points[i]+1,points[i+1]-1))
- end
- table.insert(words,message2:sub(points[#points]))
- end
- print("Established words ("..#words.." found)")
- local line = ""
- local lines = {}
- local pages = {}
- line = words[1]
- table.remove(words,1)
- for each,word in pairs(words) do
- if #line + #word + 1 > 25 then
- if #lines > 21 then
- print("New page")
- table.insert(pages,lines)
- lines = {line}
- line = word
- else
- print("New line")
- table.insert(lines,line)
- line = word
- end
- else
- line = line.." "..word
- end
- end
- table.insert(lines,line)
- table.insert(pages,lines)
- print("Constructed Pages")
- local printer = peripheral.wrap("left")
- if printer.getInkLevel() < #pages then
- rednet.send(sender,"ink","printer")
- print("Not enough ink")
- elseif printer.getPaperLevel() < #pages then
- rednet.send(sender,"paper","printer")
- print("Not enough paper")
- else
- print("Has sufficient resources")
- print("Todo: "..#pages.." pages")
- for each,page in pairs(pages) do
- print("Starting page "..each.."/"..#pages)
- printer.newPage()
- for any,line in pairs(page) do
- printer.write(line.."\n")
- end
- printer.endPage()
- print("Print finished")
- end
- end
- break
- else
- local tab = {sender2,message2}
- table.insert(queue,tab)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment