Advertisement
Guest User

startup

a guest
Apr 7th, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. -- the list of allowed disks... it uses their ID, since in survival you will never have a disk with the same ID.
  2. -- to add more, add the id on the left, followed by     = true,
  3. local allowedDisksIds = {
  4.   [0] = true,
  5.   [1] = true,
  6. }
  7.  
  8. -- the side to check for disks
  9. local diskSide = 'bottom'
  10. -- the side the door, or the cable to the door is on
  11. local rsSide = 'back'
  12.  
  13. -- this checks if it is an accepted disk
  14. local function isValid()
  15.   -- we get the disk ID
  16.   local diskId = disk.getDiskID and disk.getDiskID(diskSide) or disk.getID(diskSide) -- support for old versions of ComputerCraft
  17.   -- we return the value from the allowed disks table (it will be true or nil/false)
  18.   return allowedDisksIds[diskId]
  19. end
  20.  
  21. -- wait for x amount of time, it is a termination safe sleep function
  22. local function wait( dur )
  23.   dur = type(dur) == 'number' and dur or 1
  24.   local t = os.startTimer(dur)
  25.   repeat
  26.     local _, p = os.pullEventRaw('timer')
  27.   until p == t
  28. end
  29.  
  30. -- the main text while it is waiting for a disk
  31. local function text()
  32.   term.clear()
  33.   term.setCursorPos(1,1)
  34.   print("Please insert disk to enter...")
  35. end
  36.  
  37. -- this is the main function
  38. local function diskCheck()
  39.   -- infinitely loop
  40.   while true do
  41.     rs.setOutput(rsSide, true)
  42.     -- draw the GUI
  43.     text()
  44.     -- wait here until a disk is inserted
  45.     local _, side = os.pullEvent('disk')
  46.     -- if the disk inserted is on the correct side, and it has a valid id
  47.     if side == diskSide and isValid() then
  48.       local handle = assert(fs.open("disk/idinfo", "r"), "Couldn't load vars")
  49.       local input = handle.readAll()
  50.       handle.close()
  51.       local idinfo = textutils.unserialize(input)
  52.       -- give entry
  53.       rs.setOutput(rsSide, false)
  54.       -- tell them they have entry
  55.       term.setCursorPos(1,2)
  56.       write("Welcome to the factory ")
  57.       write(idinfo.name)
  58.       -- eject their disk
  59.       disk.eject(diskSide)
  60.       -- wait 3 seconds
  61.       wait(5)
  62.       -- close the door
  63.       rs.setOutput(rsSide, true)
  64.     else
  65.       -- if their card wasn't valid, or they inserted in a disk drive on another side, eject the disk
  66.       disk.eject(side)
  67.       -- wait for 10 seconds
  68.       wait(10)
  69.     end
  70.   end
  71. end
  72.  
  73. -- run the main function
  74. diskCheck()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement