Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local drive -- table : peripheral, floppy disk drive
- local folderToCopy = "toCopy/*" -- string : path to the files that should be copied to the floppy disk
- local monitor -- table : peripheral, display screen
- local rawFloppyStorageSide = "left"
- local rawFloppyStorage -- table : peripheral, raw floppy disks storage
- local floppyStorageDirection = "down" -- string : in which direction floppy storage should output the raw floppy disks (floppy storage -> container)
- local floppyBufferStorageName = "tile_thermalexpansion_cache_basic_name_3"
- local floppyBufferStorage -- table : peripheral, written floppy disks buffer
- local driveDirection = "south" -- string : from which direction the container should extract written floppy disks (container <- drive)
- local function init()
- shell.run("label set floppy_distributor")
- if not fs.exists(folderToCopy) then
- error("Folder [" .. folderToCopy .. "] does not exist.")
- end
- drive = peripheral.find("drive")
- if not drive then
- error("No disk drive have been found.")
- end
- monitor = peripheral.find("monitor")
- if not monitor then
- error("No disk monitor have been found.")
- end
- rawFloppyStorage = peripheral.wrap(rawFloppyStorageSide)
- if not rawFloppyStorage then
- error("No floppy disk container found on side [ " .. rawFloppyStorageSide .. "].")
- end
- floppyBufferStorage = peripheral.wrap(floppyBufferStorageName)
- if not floppyBufferStorage then
- error("No buffer [" .. floppyBufferStorageName .. "] have been found.")
- end
- end
- local function getNumber(filepath)
- local f = fs.open(filepath, "r")
- local str = f.readLine()
- f.close()
- return tonumber(str)
- end
- local function setNumber(filepath, n)
- local h = fs.open(filepath, "w")
- h.write(n)
- h.close()
- end
- local function newFloppy()
- local nb = rawFloppyStorage.pushItemIntoSlot(floppyStorageDirection, 2)
- local timeout = 0
- while not drive.isDiskPresent() and timeout < 500 do
- sleep(0)
- timeout = timeout + 1
- end
- if nb ~= 1 then
- print("Il n'y a plus de floppy disk dans le stockage.")
- return
- end
- shell.run("cp " .. folderToCopy .. " /disk/")
- sleep(1)
- drive.setDiskLabel("player_detector")
- floppyBufferStorage.pullItemIntoSlot(driveDirection, 1)
- end
- local function main()
- local n = 0
- init()
- term.redirect(monitor)
- term.clear()
- 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 !")
- print("(Cooldown de ~60 secs)")
- print("\nPlus d'infos sur le forum.")
- while true do
- os.pullEvent("redstone")
- newFloppy()
- if fs.exists("nb") then
- n = getNumber("nb")
- end
- setNumber("nb", n+1)
- sleep(60)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement