Advertisement
DOGGYWOOF

Card Data 2

Jun 16th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. -- main.lua
  2. local cardDriveSide = "bottom" -- side where the card reader is connected
  3. local monitorSide = "right" -- side where the monitor is connected
  4. local doorSide = "left" -- side where the door is connected
  5.  
  6. local cardDrive = peripheral.wrap(cardDriveSide)
  7. local monitor = peripheral.wrap(monitorSide)
  8.  
  9. -- Clear monitor and initialize
  10. monitor.clear()
  11. monitor.setCursorPos(1, 1)
  12.  
  13. function displayOwnerData(diskPath)
  14. local nameFile = fs.open(diskPath.."/Data/Owner/Name.txt", "r")
  15. local rankFile = fs.open(diskPath.."/Data/Owner/Rank.txt", "r")
  16.  
  17. if nameFile and rankFile then
  18. local name = nameFile.readAll()
  19. local rank = rankFile.readAll()
  20.  
  21. nameFile.close()
  22. rankFile.close()
  23.  
  24. monitor.clear()
  25. monitor.setCursorPos(1, 1)
  26. monitor.write("Name: " .. name)
  27. monitor.setCursorPos(1, 2)
  28. monitor.write("Rank: " .. rank)
  29. else
  30. monitor.clear()
  31. monitor.setCursorPos(1, 1)
  32. monitor.write("Owner data missing.")
  33. end
  34. end
  35.  
  36. function checkCard()
  37. if cardDrive.isDiskPresent() then
  38. local diskID = cardDrive.getDiskID()
  39. local diskPath = cardDrive.getMountPath() -- Should be /disk2
  40.  
  41. if fs.exists("/disk/Cards/"..diskID..".ID") then
  42. displayOwnerData(diskPath)
  43. redstone.setOutput(doorSide, true) -- Open door
  44. sleep(5) -- Keep door open for 5 seconds
  45. redstone.setOutput(doorSide, false) -- Close door
  46. else
  47. monitor.clear()
  48. monitor.setCursorPos(1, 1)
  49. monitor.write("Invalid card.")
  50. end
  51. else
  52. monitor.clear()
  53. monitor.setCursorPos(1, 1)
  54. monitor.write("Insert card.")
  55. end
  56. end
  57.  
  58. while true do
  59. checkCard()
  60. sleep(1)
  61. end
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement