ColdIV

playerDetectorLock

Aug 5th, 2022 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. local args = {...}
  2.  
  3. function main ()
  4.     local detector = peripheral.find("playerDetector")
  5.    
  6.     parallel.waitForAny(
  7.         -- physical
  8.         function ()
  9.             while true do              
  10.                 -- player input
  11.                 term.clear()
  12.                 term.setCursorPos(1, 1)
  13.                 print ("Password: ")
  14.                 input = read("*")
  15.                 if input == "open" then
  16.                     redstone.setOutput("bottom", true)
  17.                     sleep(3)
  18.                     redstone.setOutput("bottom", false)
  19.                 end
  20.             end
  21.         end,
  22.         -- player detector
  23.         function ()
  24.             while true do
  25.                 local playerInRange = function (range)
  26.                     local players = detector.getPlayersInRange(range)
  27.                     return #players > 0
  28.                 end
  29.                
  30.                 if detector ~= nil then
  31.                     if playerInRange(6) then
  32.                         redstone.setOutput("bottom", true)
  33.                     else
  34.                         redstone.setOutput("bottom", false)
  35.                     end
  36.                 end
  37.             end
  38.         end
  39.     )
  40. end
  41.  
  42. if args[1] == "update" then
  43.     shell.run("pastebin", "run", "FuQ3WvPs f6Y3M1MP playerDetectorLock")
  44. else
  45.     peripheral.wrap("top")
  46.     main()
  47. end
Add Comment
Please, Sign In to add comment