Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Residental List Monitor by csmit195
- local monitor = peripheral.wrap('right')
- local residentList = 'residents.txt'
- local authorisedTablet = 476
- local cur
- -- Design Options
- monitor.setTextScale(2)
- monitor.setBackgroundColor(colors.white)
- monitor.clear()
- -- Important Codes
- local termX, termY = term.getSize()
- rednet.open('bottom')
- function showList()
- -- Does List Exist
- if ( fs.exists(residentList) ) then
- local listHandle = fs.open(residentList, 'r')
- local nativeTerm = term.redirect(monitor)
- paintutils.drawFilledBox(1, 1, termX, 3, colors.lightBlue)
- term.setCursorPos(1,2)
- centerText('Current Residents')
- term.setCursorPos(3,5)
- monitor.setBackgroundColor(colors.white)
- monitor.setTextColor(colors.black)
- write(listHandle.readAll():gsub('\n','\n '))
- term.redirect(nativeTerm)
- listHandle.close()
- else
- local newList = fs.open(residentList, 'w')
- newList.writeLine('ExampleUser1\nExampleUser2\nExampleUser3')
- newList.close()
- error('Resident List: residents.txt could not be found, one has been created, type "edit residents.txt" to modify it, and press Left+CTRL then Enter to bring up the save menu.')
- end
- end
- function waitForTablet()
- local senderId, message, protocol = rednet.receive('resident_controller')
- print(senderId..', '..message..', '..protocol)
- if ( senderId == authorisedTablet ) then
- if ( message == "rc_load" ) then
- local residentFile = fs.open(residentList, 'r')
- local residents = residentFile.readAll()
- residentFile.close()
- rednet.send(authorisedTablet, residents, 'resident_controller')
- else
- local residentFile = fs.open(residentList, 'w')
- residentFile.write(message)
- residentFile.close()
- monitor.clear()
- showList()
- end
- end
- waitForTablet()
- end
- -- Utility Functions
- function centerText(text)
- local x, y = term.getSize()
- local cX, cY = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), cY)
- write(text)
- end
- showList()
- waitForTablet()
Add Comment
Please, Sign In to add comment