Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- * configuration
- local usernamesToAccept = {
- "yourUserame",
- "otherUserame",
- "LBPHacker"
- }
- local innerMonitorName = "monitor_0"
- local outerMonitorName = "monitor_1"
- local outerDetectorName = "playerDetector_0"
- local redstoneOutput = "bottom"
- -- * calls the same methods of the two monitors
- local callMonitorMethod = function(...)
- -- * I used peripheral.call in the end - no need of wrapping the monitors up
- peripheral.call(innerMonitorName, ...)
- peripheral.call(outerMonitorName, ...)
- end
- -- * updates the redstone output and the monitor
- local toggleOutput = function()
- local current = not rs.getOutput(redstoneOutput)
- rs.setOutput(redstoneOutput, current) -- * toggles the output
- callMonitorMethod("setBackgroundColor", current and colors.lime or colors.red)
- callMonitorMethod("clear")
- callMonitorMethod("setCursorPos", 2, 3)
- callMonitorMethod("write", current and "MFFS: [ON]| OFF " or "MFFS: ON |[OFF]")
- end
- -- * checks for access
- local hasAccess = function(username)
- local access = false
- for ixUser = 1, #usernamesToAccept do access = usernamesToAccept[ixUser] == username or access end -- * gives access sooner or later if the username is in the table 'usernamesToAccept'
- return access
- end
- callMonitorMethod("setTextColor", colors.white)
- rs.setOutput(redstoneOutput, false) -- * change false to true if you want the MFFS to be off by default
- toggleOutput()
- -- * endless loop
- while true do
- local eventData = {os.pullEvent()} -- * puts the event data into a table
- -- * every monitor sends a monitor_touch
- -- * (eventData[1] == "player" and hasAccess(eventData[2])):
- -- will return true if the event was player and the username can be found
- -- in the list of users permitted to toggle the MFFS power - again, call for
- -- hasAccess won't execute if the event wasn't player
- if eventData[1] == "monitor_touch" or eventData[1] == "player" and hasAccess(eventData[2]) then
- -- * nothing is on the monitor apart from the button
- -- which toggles the MFFS, so no need of fancy button APIs
- toggleOutput()
- end
- end
Add Comment
Please, Sign In to add comment