Advertisement
Josqus

Doorlock

Dec 22nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw -- Disable CTRL+T
  2.  
  3. function sleep(n)  -- seconds
  4.   local clock = os.clock
  5.   local t0 = clock()
  6.   while clock() - t0 <= n do end
  7. end
  8.  
  9. conf = {}
  10.  
  11. function main()
  12.     conf.red_side = 'back'
  13.     conf.pause = 1.5
  14.     conf.pw = 'apple'
  15.     conf.keep_open = false
  16.     conf.menu()
  17. end
  18.  
  19. function start()
  20. while true do
  21.     if conf.keep_open == true then
  22.         redstone.setOutput(conf.red_side, true)
  23.     else redstone.setOutput(conf.red_side, false)
  24.     end
  25.     print("Passwort eingeben or settings")
  26.     local input = io.read()
  27.     if input == conf.pw then
  28.         term.clear()
  29.         print("Passwort korrekt.")
  30.         redstone.setOutput(conf.red_side, true)
  31.         sleep(3)
  32.         redstone.setOutput(conf.red_side, false)
  33.     elseif input == 'settings' then
  34.         print ("Password:")
  35.         local i = io.read()
  36.         if i == conf.pw then
  37.             term.clear()
  38.             conf.menu()
  39.         else
  40.         print("WRONG PW")
  41.         end
  42.     else
  43.         print("Passwort Falsch!")
  44.     end
  45. end
  46. end
  47.  
  48. function conf.menu()
  49.     print("Doorlocker by John")
  50.     print("Start: 0")
  51.     print("Set Redstone Side: 1")
  52.     print("Set Password: 2")
  53.     print("Set pause_time: 3")
  54.     print("Set keep-open: 4")
  55.     local input = io.read() input = tonumber(input)
  56.     if input == 0 then
  57.         start()
  58.     elseif input == 1 then
  59.         conf.set_red_side()
  60.     elseif input == 2 then
  61.         conf.set_pw()
  62.     elseif input == 3 then
  63.         conf.set_pause_time()
  64.     elseif input == 4 then
  65.         conf.set_keep_open()
  66.     else
  67.         print("ERROR: WRONG INPUT, DU NOOB!")
  68.     end
  69. end
  70. function conf.set_red_side()
  71.     print("Set Redstone Side(back, right, left, up)")
  72.     local input = io.read()
  73.     conf.red_side = input
  74.     conf.menu()
  75. end
  76.  
  77. function conf.set_pw()
  78.     print("Set Password:")
  79.     local input = io.read()
  80.     conf.pw = input
  81.     conf.menu()
  82. end
  83.  
  84. function conf.set_pause_time()
  85.     print("Set Pause Time (must be number):")
  86.     local input = io.read() input = tonumber(input)
  87.     conf.pause_time = input
  88.     conf.menu()
  89. end
  90.  
  91. function conf.set_keep_open()
  92.     print("Keep open?")
  93.     print("1: true; 2: false")
  94.     local input = io.read() input = tonumber(input)
  95.     if input == 1 then
  96.         conf.keep_open = true
  97.     elseif input == 2 then
  98.         conf.keep_open = false
  99.     else
  100.         print("ERROR: Only 1 and 2")
  101.     end
  102.     conf.menu()
  103. end
  104.  
  105. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement