Advertisement
IcyProtocol

pVault

Aug 29th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.08 KB | None | 0 0
  1. function clear()
  2.   term.clear()
  3.   term.setCursorPos(1,1)
  4. end
  5. cpass = {}
  6. mon = peripheral.wrap("left")
  7. function boot()
  8.   clear()
  9.   if fs.exists("pass") then
  10.     term.redirect(mon)
  11.     print("Loading...")
  12.     --find perphs
  13.     piston = "right"
  14.     note = "back"
  15.     light = "top"
  16.     mon = peripheral.wrap("left")
  17.     reader = peripheral.wrap("front")
  18.     clear()
  19.     textutils.slowPrint("PVault Loaded!")
  20.     sleep(math.random(1,5))
  21.     clear()
  22.     passwordFile = fs.open("pass","r")
  23.     password = passwordFile.readLine()
  24.     passwordFile.close()
  25.     main()
  26.   else
  27.     print("Welcome and thank you for purchasing PVault!")
  28.     sleep(3)
  29.     clear()
  30.     print("Before we begin, check to make sure your peripherals are in place correctly:")
  31.     print("Piston(redstone w/negate)=right, light=top, card reader=front, monitor=left, and alarm(noteblock)=back")
  32.     print("When this is done, please press Y.")
  33.     while true do
  34.       local event, param1=os.pullEvent("char")
  35.       if param1 == "y" then
  36.         clear()
  37.         print("Please take a blank mag card and swipe it now. Do not lose this! This will be your only access to the vault.")
  38.         reader = peripheral.wrap("front")
  39.         reader.setInsertCardLight(true)
  40.         while true do
  41.           password = math.random(11111,99999)
  42.           reader.beginWrite(password,"Vault Key")
  43.           event,x,y,z = os.pullEvent("mag_swipe")
  44.           reader.setInsertCardLight(false)
  45.           piston = "right"
  46.           note = "back"
  47.           light = "top"
  48.           file = fs.open("pass","w")
  49.           file.write(password)
  50.           file.close()
  51.           clear()
  52.           term.setTextColor(colors.lime)
  53.           print("Vault key created!")
  54.           sleep(3)
  55.           clear()
  56.           print("Setup complete! Restarting program...")
  57.           sleep(3)
  58.           clear()
  59.           term.setTextColor(colors.white)
  60.           reader.cancelWrite()
  61.           boot()
  62.         end
  63.       end
  64.     end
  65.   end
  66. end
  67.  
  68. function main()
  69.   term.setTextColor(colors.white)
  70.   term.setBackgroundColor(colors.black)
  71.   print("Please swipe card...")
  72.   reader.setInsertCardLight(true)
  73.   while true do
  74.     event,x,y,z = os.pullEvent("mag_swipe")
  75.     passwordFile = fs.open("pass","r")
  76.     password = tonumber(passwordFile.readLine())
  77.     passwordFile.close()
  78.     reader.setInsertCardLight(false)
  79.     if param1 == password then
  80.       term.setTextColor(colors.lime)
  81.       textutils.slowPrint("Card accepted!")
  82.       sleep(2)
  83.       clear()
  84.       timer=10 --change this for the amount of time you want the vault open in seconds
  85.       redstone.setOutput(piston, true)
  86.       for i=1, timer do
  87.         print("Door open for "..tostring(timer).." seconds...")
  88.         timer = timer - 1
  89.         sleep(1)
  90.         clear()
  91.       end
  92.       clear()
  93.       term.setTextColor(colors.red)
  94.       redstone.setOutput(piston,false)
  95.       print("Door sealed!")
  96.       sleep(2)
  97.       clear()
  98.       timer = 120 --change this for the amount of time you want the vault time locked after a recent opening in seconds. Default=2 minutes
  99.       for i=1, timer do
  100.         print("Time lock activated! Door will be active again in "..tostring(timer).." seconds.")
  101.         timer = timer - 1
  102.         sleep(1)
  103.         clear()
  104.       end
  105.       clear()
  106.       term.setTextColor(colors.white)
  107.       main()
  108.     else
  109.       term.setTextColor(colors.red)
  110.       timer = 120 --change this for the amount of time you want the vault to be locked and the alarm to be set off after failing with card. Default 2 minutes
  111.       print("Invalid card! Initiating lock-down procedures!")
  112.       for i=1, (timer * 2) do
  113.       term.setBackgroundColor(colors.red)
  114.       term.setTextColor(colors.black)
  115.       redstone.setOutput(note, true)
  116.       redstone.setOutput(light, true)
  117.       sleep(.25)
  118.       term.setBackgroundColor(colors.black)
  119.       term.setTextColor(colors.red)
  120.       redstone.setOutput(note,false)
  121.       redstone.setOutput(light,false)
  122.       timer = timer - 1
  123.       sleep(.25)
  124.       end
  125.       clear()
  126.       term.setTextColor(colors.white)
  127.       main()
  128.     end
  129.   end
  130. end
  131. boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement