Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- main.lua
- local cardDriveSide = "bottom" -- side where the card reader is connected
- local monitorSide = "right" -- side where the monitor is connected
- local doorSide = "left" -- side where the door is connected
- local cardDrive = peripheral.wrap(cardDriveSide)
- local monitor = peripheral.wrap(monitorSide)
- -- Clear monitor and initialize
- monitor.clear()
- monitor.setCursorPos(1, 1)
- function displayOwnerData(diskPath)
- local nameFile = fs.open(diskPath.."/Data/Owner/Name.txt", "r")
- local rankFile = fs.open(diskPath.."/Data/Owner/Rank.txt", "r")
- if nameFile and rankFile then
- local name = nameFile.readAll()
- local rank = rankFile.readAll()
- nameFile.close()
- rankFile.close()
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Name: " .. name)
- monitor.setCursorPos(1, 2)
- monitor.write("Rank: " .. rank)
- else
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Owner data missing.")
- end
- end
- function checkCard()
- if cardDrive.isDiskPresent() then
- local diskID = cardDrive.getDiskID()
- local diskPath = cardDrive.getMountPath() -- Should be /disk2
- if fs.exists("/disk/Cards/"..diskID..".ID") then
- displayOwnerData(diskPath)
- redstone.setOutput(doorSide, true) -- Open door
- sleep(5) -- Keep door open for 5 seconds
- redstone.setOutput(doorSide, false) -- Close door
- else
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Invalid card.")
- end
- else
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Insert card.")
- end
- end
- while true do
- checkCard()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement