Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to clear the screen
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Function to open a file using the editor
- local function openFileInEditor(filePath)
- shell.run("edit " .. filePath)
- end
- -- Function to handle sending redstone control signals
- local function controlRedstone(computerID, sides)
- -- Attach the modem
- local modem = peripheral.find("modem")
- if not modem then
- print("No modem found. Please attach a modem.")
- return
- end
- modem.open(1) -- Open channel 1 for communication
- -- Iterate over each side
- for _, side in ipairs(sides) do
- -- Send signal to turn off redstone
- modem.transmit(1, 1, {action="off", duration=5, side=side, id=computerID})
- -- Wait for the specified duration
- sleep(5)
- -- Send signal to turn on redstone
- modem.transmit(1, 1, {action="on", side=side, id=computerID})
- end
- -- Close the modem channel
- modem.close(1)
- end
- -- Function to read the computer ID from the file
- local function readComputerID()
- local file = fs.open("ID.txt", "r")
- local id = file.readLine()
- file.close()
- return tonumber(id)
- end
- -- Function to handle guest parking
- local function handleGuest()
- clear()
- print("Guest Parking")
- write("Enter Number Plate: ")
- local numberPlate = read()
- write("Enter Car Make: ")
- local carMake = read()
- write("Enter Car Model: ")
- local carModel = read()
- write("Enter Your Name: ")
- local guestName = read()
- write("Enter Reason for Visit: ")
- local reason = read()
- -- Generate parking ticket content
- local ticket = "Parking Ticket\n"
- ticket = ticket .. "--------------------\n"
- ticket = ticket .. "Number Plate: " .. numberPlate .. "\n"
- ticket = ticket .. "Car Make: " .. carMake .. "\n"
- ticket = ticket .. "Car Model: " .. carModel .. "\n"
- ticket = ticket .. "Name: " .. guestName .. "\n"
- ticket = ticket .. "Reason for Visit: " .. reason .. "\n"
- ticket = ticket .. "--------------------\n"
- ticket = ticket .. "Thank you for visiting!"
- -- Write the ticket content to a file
- local filePath = "TICKET"
- local file = fs.open(filePath, "w")
- file.write(ticket)
- file.close()
- -- Notify user to print the file
- clear()
- print("The ticket has been created.")
- print("Press Ctrl+P to print the ticket.")
- print("Then press Ctrl+E to confirm and exit the editor.")
- print("You will be returned to the main menu once you confirm.")
- -- Open the file in the editor for printing
- openFileInEditor(filePath)
- -- Confirmation message after the editor is closed
- clear()
- print("The printing has been completed. You may proceed to the guest parking.")
- print("Press Ctrl+P and then Ctrl+E to confirm your ticket.")
- sleep(3) -- Wait for 3 seconds before returning to the main menu
- -- Control the redstone signal to the back
- local computerID = readComputerID()
- controlRedstone(computerID, {"back"})
- clear()
- end
- -- Function to handle resident parking
- local function handleResident()
- clear()
- print("Resident Parking")
- write("Enter Your Name: ")
- local residentName = read()
- -- Check if the file exists
- local filePath = "/disk/" .. residentName
- if fs.exists(filePath) then
- write("Enter Password: ")
- local enteredPassword = read("*") -- Read password with hidden input
- -- Read the stored password from the file
- local file = fs.open(filePath, "r")
- local storedPassword = file.readLine()
- file.close()
- -- Check if the entered password matches the stored password
- if enteredPassword == storedPassword then
- clear()
- print("Welcome, " .. residentName .. "!")
- sleep(2)
- clear()
- else
- clear()
- print("Incorrect Password!")
- print("Press any key to return to main menu...")
- os.pullEvent("key")
- end
- else
- clear()
- print("Resident Not Found!")
- print("Press any key to return to main menu...")
- os.pullEvent("key")
- end
- -- Control the redstone signals for both back and left
- local computerID = readComputerID()
- controlRedstone(computerID, {"back", "left"})
- clear()
- end
- -- Main program loop
- while true do
- clear()
- print("Parking System")
- print("1. Guest")
- print("2. Resident")
- write("Choose an option: ")
- local choice = read()
- if choice == "1" then
- handleGuest()
- fs.delete("TICKET") -- Ensure the ticket file is deleted after printing
- elseif choice == "2" then
- handleResident()
- else
- clear()
- print("Invalid option. Please try again.")
- sleep(2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement