Advertisement
DaikiKaminari

Untitled

Nov 9th, 2020 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. local drive -- table : peripheral, floppy disk drive
  2. local folderToCopy = "toCopy/*" -- string : path to the files that should be copied to the floppy disk
  3.  
  4. local monitor -- table : peripheral, display screen
  5.  
  6. local rawFloppyStorageSide = "left"
  7. local rawFloppyStorage -- table : peripheral, raw floppy disks storage
  8. local floppyStorageDirection = "down" -- string : in which direction floppy storage should output the raw floppy disks (floppy storage -> container)
  9.  
  10.  
  11. local floppyBufferStorageName = "tile_thermalexpansion_cache_basic_name_3"
  12. local floppyBufferStorage -- table : peripheral, written floppy disks buffer
  13. local driveDirection = "south" -- string : from which direction the container should extract written floppy disks (container <- drive)
  14.  
  15. local function init()
  16. shell.run("label set floppy_distributor")
  17.  
  18. if not fs.exists(folderToCopy) then
  19. error("Folder [" .. folderToCopy .. "] does not exist.")
  20. end
  21.  
  22. drive = peripheral.find("drive")
  23. if not drive then
  24. error("No disk drive have been found.")
  25. end
  26.  
  27. monitor = peripheral.find("monitor")
  28. if not monitor then
  29. error("No disk monitor have been found.")
  30. end
  31.  
  32. rawFloppyStorage = peripheral.wrap(rawFloppyStorageSide)
  33. if not rawFloppyStorage then
  34. error("No floppy disk container found on side [ " .. rawFloppyStorageSide .. "].")
  35. end
  36.  
  37. floppyBufferStorage = peripheral.wrap(floppyBufferStorageName)
  38. if not floppyBufferStorage then
  39. error("No buffer [" .. floppyBufferStorageName .. "] have been found.")
  40. end
  41. end
  42.  
  43. local function getNumber(filepath)
  44. local f = fs.open(filepath, "r")
  45. local str = f.readLine()
  46. f.close()
  47. return tonumber(str)
  48. end
  49.  
  50. local function setNumber(filepath, n)
  51. local h = fs.open(filepath, "w")
  52. h.write(n)
  53. h.close()
  54. end
  55.  
  56. local function newFloppy()
  57. local nb = rawFloppyStorage.pushItemIntoSlot(floppyStorageDirection, 2)
  58. local timeout = 0
  59. while not drive.isDiskPresent() and timeout < 500 do
  60. sleep(0)
  61. timeout = timeout + 1
  62. end
  63. if nb ~= 1 then
  64. print("Il n'y a plus de floppy disk dans le stockage.")
  65. return
  66. end
  67. shell.run("cp " .. folderToCopy .. " /disk/")
  68. sleep(1)
  69. drive.setDiskLabel("player_detector")
  70. floppyBufferStorage.pullItemIntoSlot(driveDirection, 1)
  71. end
  72.  
  73. local function main()
  74. local n = 0
  75.  
  76. init()
  77. term.redirect(monitor)
  78. term.clear()
  79. print("Marchez sur la plaque de pression pour recevoir une disquette contenant le programme PLAYER_DETECTOR permettant de couper automatiquement vos spawners quand vous etes deconnecte !")
  80. print("(Cooldown de ~60 secs)")
  81. print("\nPlus d'infos sur le forum.")
  82. while true do
  83. os.pullEvent("redstone")
  84. newFloppy()
  85. if fs.exists("nb") then
  86. n = getNumber("nb")
  87. end
  88. setNumber("nb", n+1)
  89. sleep(60)
  90. end
  91. end
  92.  
  93. main()
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement