Advertisement
Grauly

CC_AOF_door

Apr 9th, 2021 (edited)
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. local monitors = {
  2.     peripheral.wrap("top");
  3. }
  4.  
  5. local outputSide = "right";
  6. local reLockTime = 20;
  7. local locked = true;
  8. local onColor = colors.green;
  9. local offColor = colors.red;
  10. local defaultColor = colors.white;
  11.  
  12. --clears all monitors
  13. function clear()
  14.   for i=1, #monitors do
  15.     monitors[i].clear()
  16.     monitors[i].setTextColor(defaultColor)
  17.     monitors[i].setCursorPos(1,1)
  18.   end
  19. end
  20.  
  21. --goes to the next line for all monitors
  22. function nextLine()
  23.   for i=1, #monitors do
  24.     local x,y = monitors[i].getCursorPos()
  25.     local y = y + 1
  26.     monitors[i].setCursorPos(1,y)
  27.   end
  28. end
  29.  
  30. --writes text on all monitors
  31. function writeText(text)
  32.   for i=1, #monitors do
  33.     monitors[i].write(text)
  34.   end
  35. end
  36.  
  37. --sets text color for all monitors
  38. function textColor(color)
  39.   for i=1, #monitors do
  40.     monitors[i].setTextColor(color)
  41.   end
  42. end
  43.  
  44. --sets background color for all monitors
  45. function backgroundColor(color)
  46.   for i=1, #monitors do
  47.     monitors[i].setBackgroundColor(color)
  48.   end
  49. end
  50.  
  51. --sets textScale for all monitors
  52. function textScale(scale)
  53.     for i=1, #monitors do
  54.         monitors[i].setTextScale(scale)
  55.     end
  56. end
  57.  
  58. function routine()
  59.     clear()
  60.     textScale(0.5)
  61.     activeColor = defaultColor
  62.     if(locked) then
  63.         writeText(" Access denied ")
  64.         nextLine()
  65.         nextLine()
  66.         activeColor = offColor
  67.         redstone.setOutput(outputSide,false)
  68.     else
  69.         writeText(" Access granted")
  70.         nextLine()
  71.         nextLine()
  72.         activeColor = onColor
  73.         redstone.setOutput(outputSide,true)
  74.     end
  75.     writeText("+-------------+")
  76.     nextLine()
  77.     for i=1, 6,1 do
  78.         writeText("|")
  79.         backgroundColor(activeColor)
  80.         writeText("             ")
  81.         backgroundColor(colors.black)
  82.         writeText("|")
  83.         nextLine()
  84.     end
  85.     writeText("+-------------+")
  86. end
  87.  
  88. local lockTime = 0;
  89. while true do
  90.     local timer = os.startTimer(1)
  91.     local event,a1,a2,a3 = os.pullEvent()
  92.     if event == "timer" then
  93.         routine()
  94.         if(lockTime == 0 and not locked) then
  95.             locked = true;
  96.         elseif(lockTime > 0 and not locked) then
  97.             lockTime = lockTime -1
  98.         elseif(lockTime > 0 and locked) then
  99.             lockTime = 0
  100.         end
  101.     elseif event == "monitor_touch" then
  102.         routine()
  103.         local x = a2;
  104.         local y = a3;
  105.         if(x > 2 and x < 14) then
  106.             if(y > 4 and y < 9) then
  107.                 locked = not locked
  108.                 lockTime = reLockTime
  109.             end
  110.         end
  111.     end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement