MatthewGB

Lua Mag-Card Door

Mar 23rd, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. p = peripheral.wrap("bottom")
  2. pw = "io"
  3. if fs.exists("mgpw") then
  4.  print("Password file found")
  5.  h = fs.open("mgpw", "r")
  6.  pw = h.readLine()
  7.  h.close()
  8. else
  9.  print("Password file not found!")
  10.  print("You will need to setup a card.")
  11.  write("The password to be stored on the magcard: ")
  12.  ag1 = read()
  13.  write("The label of the magcard: ")
  14.  ag2 = read()
  15.  print("The password will be "..ag1.." and the label will be "..ag2..". Insert the magcard.")
  16.  p.beginWrite(ag1, ag2)
  17.  print("Waiting for card to write to...")
  18.  event,arg1,arg2,arg3 = os.pullEvent("mag_write_done")
  19.  h = fs.open("mgpw", "w")
  20.  h.write(ag1)
  21.  h.close()
  22.  print("Operation complete. Rebooting...")
  23.  sleep(1)
  24.  os.reboot()
  25. end
  26. print("Waiting for card")
  27. event,arg1,arg2,arg3 = os.pullEvent("mag_swipe")
  28. if arg1 == pw then
  29.  print("Correct card")
  30.  rs.setOutput("left", true)
  31.  sleep(2)
  32.  rs.setOutput("left", false)
  33. else
  34.  print("Incorrect card")
  35. end
  36. sleep(1)
  37. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment