Sneaky4296

ComputerCraft Floppy Disc Door

Feb 12th, 2015
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. --Allowed floppy ID. This code only allows 1 floppy to be inserted, but you can easily modify it to have multiple allowed.
  2. allowedID = 1
  3.  
  4. --Variable for which side the redstone will be at
  5. redstoneSide = 'bottom'
  6.  
  7. --Variable for which side your disk drive will be on. You can also change it to networked positions
  8. diskSide = 'left'
  9.  
  10. --Checks to see if it's the correct disk
  11. local function isCorrect()
  12.     diskID = disk.getID(diskSide)
  13.     if diskID == allowedID then
  14.         return true
  15.     else
  16.         return false
  17.     end
  18. end
  19.  
  20. --Function that just waits a given number of seconds
  21. local function wait( dur )
  22.     dur = type(dur) == 'number' and dur or 1
  23.     local t = os.startTimer(dur)
  24.     repeat
  25.         local _, p = os.pullEventRaw('timer')
  26.     until p == t
  27. end
  28.  
  29. --Standby text
  30. local function text()
  31.     term.clear()
  32.     term.setCursorPos(1,2)
  33.     print("Insert Disk")
  34. end
  35.  
  36. --waits until a disk is inserted and then runs isCorrect() in order to figure out what to do next
  37. local function checkDisk()
  38.     while true do
  39.         text()
  40.         local _, side = os.pullEvent('disk')
  41.         if isCorrect() == true then
  42.             rs.setOutput(redstoneSide, true)
  43.             term.setCursorPos(1,2)
  44.             term.clear()
  45.             print("GRANTED")
  46.             disk.eject(diskSide)
  47.             wait(3)
  48.                 rs.setOutput(redstoneSide, false)
  49.         else
  50.             disk.eject(diskSide)
  51.             term.clear()
  52.             print("Denied.")
  53.             wait(10)
  54.         end
  55.     end
  56. end
  57.  
  58. checkDisk()
Advertisement
Add Comment
Please, Sign In to add comment