Advertisement
LBPHacker

MFFS Controller for devillwithin

Jul 10th, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. -- * configuration
  2. local usernamesToAccept = {
  3.     "yourUserame",
  4.     "otherUserame",
  5.     "LBPHacker"
  6. }
  7. local innerMonitorName = "monitor_0"
  8. local outerDetectorName = "playerDetector_0"
  9. local redstoneOutput = "bottom"
  10.  
  11. -- * not my style, but wrap up the monitor (I prefer peripheral.call)
  12. local monitor = peripheral.wrap(innerMonitorName)
  13.  
  14. -- * updates the redstone output and the monitor
  15. local toggleOutput = function()
  16.     local current = not rs.getOutput(redstoneOutput)
  17.     rs.setOutput(redstoneOutput, current) -- * toggles the output
  18.     monitor.setBackgroundColor(current and colors.lime or colors.red)
  19.     monitor.clear()
  20.     monitor.setCursorPos(2, 3)
  21.     monitor.write(current and "MFFS: [ON]| OFF " or "MFFS:  ON |[OFF]")
  22. end
  23.  
  24. -- * checks for access
  25. local hasAccess = function(username)
  26.     local access = false
  27.     for uix = 1, #usernamesToAccept do access = usernamesToAccept[uix] == username or access end -- * gives access sooner or later if the username is in the table 'usernamesToAccept'
  28.     return access
  29. end
  30.  
  31. monitor.setTextColor(colors.white)
  32. rs.setOutput(redstoneOutput, false) -- * change false to true if you want the MFFS to be off by default
  33. toggleOutput()
  34.  
  35. -- * endless loop
  36. while true do
  37.     local eventData = {os.pullEvent()} -- * puts the event data into a table
  38.     if eventData[1] == "monitor_touch" or eventData[1] == "player" and hasAccess(eventData[2]) then
  39.         -- * nothing is on the monitor apart from the button
  40.         --   which toggles the MFFS, so no need of fancy button APIs
  41.         toggleOutput()
  42.     end
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement