Advertisement
MavricMC

pinpad

Nov 29th, 2020 (edited)
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --Made by Bloodmuffin on YoutTube go watch his video--
  2. --Just wanted too show off Bloodmuffins cool program--
  3. --I have added some new stuff too--
  4. -----PREFERENCES/VARIABLES-----
  5. local speakerSide = "left"
  6. local doorname = "door1"
  7. local modemSide = "top"
  8. local pin = 1234
  9. local maxtries = 3
  10. local locktime = 60 --seconds
  11. local waittotry = 3 --seconds
  12. local redstoneSide = "right"
  13. local monitorSide = "front"
  14. local serverID = 0
  15. local tries = 0
  16. local input = ""
  17. local keypad = {
  18. --{num,xpos,ypos}
  19.   {1,2,4},
  20.   {2,7,4},
  21.   {3,12,4},
  22.   {4,2,6},
  23.   {5,7,6},
  24.   {6,12,6},
  25.   {7,2,8},
  26.   {8,7,8},
  27.   {9,12,8},
  28.   {0,7,10}
  29. }
  30.  
  31. -----FUNCTIONS-----
  32. function checkClick(t,x,y)
  33.   for i,v in pairs(t) do
  34.     num,cx,cy = unpack(v)
  35.     if (x >= cx) and (x <= cx + 2) and (y == cy) then
  36.       return true,num
  37.     end
  38.   end
  39.   return false
  40. end
  41.  
  42. function numClick(num)
  43.   monitor.setCursorPos((5 + (string.len(input) * 2)),2)
  44.   input = input .. num
  45.   monitor.write("*")
  46.   if (string.len(input) == 4) then
  47.     if (tostring(pin) == input) then
  48.       monAction("Access Granted")
  49.       speaker.playSound("minecraft:entity.player.levelup")
  50.       doorOpen()
  51.       monReset(true)
  52.       input = ""
  53.       tries = 0
  54.     else
  55.       input = ""
  56.       tries = tries + 1
  57.       if (tries >= maxtries) then
  58.         monReset()
  59.         monitor.setBackgroundColor(colors.red)
  60.         monAction("TERMINAL LOCKED")
  61.         rednet.send(serverID, 3, doorname)
  62.         speaker.playSound("minecraft:entity.villager.hurt")
  63.         sleep(locktime)
  64.         rednet.send(serverID, 0, doorname)
  65.         monReset(true)
  66.         os.reboot()
  67.       end
  68.       monAction("Access Denied")
  69.       rednet.send(serverID, 2, doorname)
  70.       speaker.playSound("minecraft:entity.villager.no")
  71.       sleep(waittotry)
  72.       monReset(true)
  73.     end
  74.   end
  75. end
  76.  
  77. function monAction(mess)
  78.   monitor.setCursorPos(1,1)
  79.   monitor.write(mess)
  80. end
  81.  
  82. function monReset(isClear)
  83.   monitor.setBackgroundColor(colors.black)
  84.   monitor.setTextColor(1)
  85.   monitor.setCursorPos(1,1)
  86.   if (isClear) then monitor.clearLine() end
  87.   monitor.setCursorPos(5,2)
  88.   monitor.write("_ _ _ _")
  89. end
  90.  
  91. function doorOpen()
  92.   rednet.send(serverID, 1, doorname)
  93.   redstone.setOutput(redstoneSide, true)
  94.   sleep(3)
  95.   rednet.send(serverID, 4, doorname)
  96.   redstone.setOutput(redstoneSide, false)
  97. end
  98.  
  99. -----BEGIN MAIN-----
  100. rednet.open(modemSide)
  101. speaker = peripheral.wrap(speakerSide)
  102. monitor = peripheral.wrap(monitorSide)
  103. monitor.setTextScale(0.5)
  104. w,h = monitor.getSize()
  105. if (w > 15) or (h > 10) then
  106.   error("Monitor size is to big.")
  107.   exit()
  108. end
  109. monReset()
  110. monReset(true)
  111. monitor.setBackgroundColor(colors.red)
  112. monitor.setTextColor(colors.black)
  113.  
  114. for i,v in pairs(keypad) do
  115.   num,x,y = unpack(v)
  116.   monitor.setCursorPos(x,y)
  117.   monitor.write(" " .. num .. " ")
  118. end
  119.  
  120. monitor.setBackgroundColor(colors.black)
  121. monitor.setTextColor(colors.white)
  122. while true do
  123.   event,button,x,y = os.pullEvent("monitor_touch")
  124.   validClick,num = checkClick(keypad,x,y)
  125.   if (validClick) then
  126.     numClick(num)
  127.   end
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement