Advertisement
DOGGYWOOF

Untitled

Jul 31st, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. -- Function to clear the screen
  2. local function clear()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. end
  6.  
  7. -- Function to open a file using the editor
  8. local function openFileInEditor(filePath)
  9. shell.run("edit " .. filePath)
  10. end
  11.  
  12. -- Function to handle sending redstone control signals
  13. local function controlRedstone(computerID, sides)
  14. -- Attach the modem
  15. local modem = peripheral.find("modem")
  16.  
  17. if not modem then
  18. print("No modem found. Please attach a modem.")
  19. return
  20. end
  21.  
  22. modem.open(1) -- Open channel 1 for communication
  23.  
  24. -- Iterate over each side
  25. for _, side in ipairs(sides) do
  26. -- Send signal to turn off redstone
  27. modem.transmit(1, 1, {action="off", duration=5, side=side, id=computerID})
  28. -- Wait for the specified duration
  29. sleep(5)
  30. -- Send signal to turn on redstone
  31. modem.transmit(1, 1, {action="on", side=side, id=computerID})
  32. end
  33.  
  34. -- Close the modem channel
  35. modem.close(1)
  36. end
  37.  
  38. -- Function to read the computer ID from the file
  39. local function readComputerID()
  40. local file = fs.open("ID.txt", "r")
  41. local id = file.readLine()
  42. file.close()
  43. return tonumber(id)
  44. end
  45.  
  46. -- Function to handle guest parking
  47. local function handleGuest()
  48. clear()
  49. print("Guest Parking")
  50. write("Enter Number Plate: ")
  51. local numberPlate = read()
  52. write("Enter Car Make: ")
  53. local carMake = read()
  54. write("Enter Car Model: ")
  55. local carModel = read()
  56. write("Enter Your Name: ")
  57. local guestName = read()
  58. write("Enter Reason for Visit: ")
  59. local reason = read()
  60.  
  61. -- Generate parking ticket content
  62. local ticket = "Parking Ticket\n"
  63. ticket = ticket .. "--------------------\n"
  64. ticket = ticket .. "Number Plate: " .. numberPlate .. "\n"
  65. ticket = ticket .. "Car Make: " .. carMake .. "\n"
  66. ticket = ticket .. "Car Model: " .. carModel .. "\n"
  67. ticket = ticket .. "Name: " .. guestName .. "\n"
  68. ticket = ticket .. "Reason for Visit: " .. reason .. "\n"
  69. ticket = ticket .. "--------------------\n"
  70. ticket = ticket .. "Thank you for visiting!"
  71.  
  72. -- Write the ticket content to a file
  73. local filePath = "TICKET"
  74. local file = fs.open(filePath, "w")
  75. file.write(ticket)
  76. file.close()
  77.  
  78. -- Notify user to print the file
  79. clear()
  80. print("The ticket has been created.")
  81. print("Press Ctrl+P to print the ticket.")
  82. print("Then press Ctrl+E to confirm and exit the editor.")
  83. print("You will be returned to the main menu once you confirm.")
  84.  
  85. -- Open the file in the editor for printing
  86. openFileInEditor(filePath)
  87.  
  88. -- Confirmation message after the editor is closed
  89. clear()
  90. print("The printing has been completed. You may proceed to the guest parking.")
  91. print("Press Ctrl+P and then Ctrl+E to confirm your ticket.")
  92. sleep(3) -- Wait for 3 seconds before returning to the main menu
  93.  
  94. -- Control the redstone signal to the back
  95. local computerID = readComputerID()
  96. controlRedstone(computerID, {"back"})
  97. clear()
  98. end
  99.  
  100. -- Function to handle resident parking
  101. local function handleResident()
  102. clear()
  103. print("Resident Parking")
  104. write("Enter Your Name: ")
  105. local residentName = read()
  106.  
  107. -- Check if the file exists
  108. local filePath = "/disk/" .. residentName
  109. if fs.exists(filePath) then
  110. write("Enter Password: ")
  111. local enteredPassword = read("*") -- Read password with hidden input
  112.  
  113. -- Read the stored password from the file
  114. local file = fs.open(filePath, "r")
  115. local storedPassword = file.readLine()
  116. file.close()
  117.  
  118. -- Check if the entered password matches the stored password
  119. if enteredPassword == storedPassword then
  120. clear()
  121. print("Welcome, " .. residentName .. "!")
  122. sleep(2)
  123. clear()
  124. else
  125. clear()
  126. print("Incorrect Password!")
  127. print("Press any key to return to main menu...")
  128. os.pullEvent("key")
  129. end
  130. else
  131. clear()
  132. print("Resident Not Found!")
  133. print("Press any key to return to main menu...")
  134. os.pullEvent("key")
  135. end
  136.  
  137. -- Control the redstone signals for both back and left
  138. local computerID = readComputerID()
  139. controlRedstone(computerID, {"back", "left"})
  140. clear()
  141. end
  142.  
  143. -- Main program loop
  144. while true do
  145. clear()
  146. print("Parking System")
  147. print("1. Guest")
  148. print("2. Resident")
  149. write("Choose an option: ")
  150. local choice = read()
  151.  
  152. if choice == "1" then
  153. handleGuest()
  154. fs.delete("TICKET") -- Ensure the ticket file is deleted after printing
  155. elseif choice == "2" then
  156. handleResident()
  157. else
  158. clear()
  159. print("Invalid option. Please try again.")
  160. sleep(2)
  161. end
  162. end
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement