Advertisement
DOGGYWOOF

Untitled

Jun 17th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. -- Function to get the disk ID from the bottom drive
  2. local function getDiskID()
  3. -- Wrap the disk drive at the bottom of the computer
  4. local drive = peripheral.wrap("bottom")
  5.  
  6. if drive and peripheral.getType("bottom") == "drive" then
  7. -- Check if there is a disk in the drive
  8. if drive.isDiskPresent() then
  9. -- Get the disk ID
  10. local diskID = drive.getDiskID()
  11. return diskID
  12. else
  13. print("No disk present in the drive.")
  14. end
  15. else
  16. print("No drive found at the bottom.")
  17. end
  18. return nil
  19. end
  20.  
  21. -- Function to list all cards in /disk/Cards
  22. local function listCards()
  23. local cardDir = "/disk/Cards/"
  24. local files = fs.list(cardDir)
  25. if #files > 0 then
  26. print("Cards in /disk/Cards:")
  27. for _, file in ipairs(files) do
  28. print("- " .. file)
  29. end
  30. else
  31. print("No cards found in /disk/Cards.")
  32. end
  33. end
  34.  
  35. -- Function to link a card
  36. local function linkCard()
  37. while true do
  38. print("\nLink Card:")
  39. print("1. Insert Card to Link")
  40. print("2. Enter Card ID")
  41. print("0. Back to Main Menu")
  42. local choice = tonumber(read())
  43.  
  44. if choice == 1 then
  45. print("Insert a disk to link...")
  46. local diskID = getDiskID()
  47. if diskID then
  48. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  49. local file = fs.open(cardFileName, "w")
  50. file.close()
  51. print("Card linked successfully.")
  52. end
  53. elseif choice == 2 then
  54. print("Enter the card ID:")
  55. local cardID = read()
  56.  
  57. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  58. local file = fs.open(cardFileName, "w")
  59. file.close()
  60.  
  61. print("Card linked successfully.")
  62. elseif choice == 0 then
  63. break -- Back to main menu
  64. else
  65. print("Invalid choice. Please enter 1, 2, or 0.")
  66. end
  67. end
  68. end
  69.  
  70. -- Function to unlink a card
  71. local function unlinkCard()
  72. while true do
  73. print("\nUnlink Card:")
  74. print("1. Insert Card to Unlink")
  75. print("2. Enter Card ID")
  76. print("0. Back to Main Menu")
  77. local choice = tonumber(read())
  78.  
  79. if choice == 1 then
  80. print("Insert a disk to unlink...")
  81. local diskID = getDiskID()
  82. if diskID then
  83. local cardFileName = "/disk/Cards/" .. diskID .. ".ID"
  84. if fs.exists(cardFileName) then
  85. fs.delete(cardFileName)
  86. print("Card unlinked successfully.")
  87. else
  88. print("No matching card found to unlink.")
  89. end
  90. end
  91. elseif choice == 2 then
  92. print("Enter the card ID:")
  93. local cardID = read()
  94.  
  95. local cardFileName = "/disk/Cards/" .. cardID .. ".ID"
  96. if fs.exists(cardFileName) then
  97. fs.delete(cardFileName)
  98. print("Card unlinked successfully.")
  99. else
  100. print("No matching card found to unlink.")
  101. end
  102. elseif choice == 0 then
  103. break -- Back to main menu
  104. else
  105. print("Invalid choice. Please enter 1, 2, or 0.")
  106. end
  107. end
  108. end
  109.  
  110. -- Main program loop
  111. while true do
  112. print("\nCard System")
  113. print("1. List Cards")
  114. print("2. Link Card")
  115. print("3. Unlink Card")
  116. print("0. Exit")
  117.  
  118. local choice = tonumber(read())
  119.  
  120. if choice == 1 then
  121. listCards()
  122. elseif choice == 2 then
  123. linkCard()
  124. elseif choice == 3 then
  125. unlinkCard()
  126. elseif choice == 0 then
  127. print("Exiting...")
  128. break
  129. else
  130. print("Invalid choice. Please enter a number from the menu.")
  131. end
  132. end
  133.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement