Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings Writer for Storage System
- -- Platziert über dem Disk Drive mit der "Settings"-Disk
- local SETTINGS_LABEL = "Settings"
- local COORD_FILE = "initial_coords.txt"
- local TASK_FILE = "task.txt"
- -- Funktion: Hole Disk-Laufwerk mit Label "Settings"
- function getSettingsDisk()
- for _, side in ipairs(peripheral.getNames()) do
- if peripheral.getType(side) == "drive" then
- local disk = peripheral.wrap(side)
- if disk.getDiskLabel() == SETTINGS_LABEL then
- return disk, disk.getMountPath()
- end
- end
- end
- return nil, nil
- end
- -- Funktion: Überprüft, ob initial_coords.txt bereits existiert
- function coordsFileExists()
- local _, path = getSettingsDisk()
- if not path then return false end
- return fs.exists(fs.combine(path, COORD_FILE))
- end
- -- Funktion: Fragt den Nutzer nach einer Koordinate (in Form "x y z")
- function askForCoords(promptText)
- while true do
- print(promptText)
- local input = read()
- local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
- if x and y and z then
- return tonumber(x), tonumber(y), tonumber(z)
- else
- print("Ungültiges Format. Bitte erneut eingeben als: x y z")
- end
- end
- end
- -- Funktion: Speichert die beiden Koordinaten in initial_coords.txt
- function saveInitialCoords(x1, y1, z1, x2, y2, z2)
- local _, path = getSettingsDisk()
- if not path then error("Settings-Disk nicht gefunden!") end
- local fullPath = fs.combine(path, COORD_FILE)
- local file = fs.open(fullPath, "w")
- file.writeLine(string.format("%d,%d,%d", x1, y1, z1))
- file.writeLine(string.format("%d,%d,%d", x2, y2, z2))
- file.close()
- print("Koordinaten erfolgreich gespeichert.")
- end
- -- Funktion: Erstellt task.txt auf Settings-Disk
- function createTaskFile()
- local _, path = getSettingsDisk()
- if not path then error("Settings-Disk nicht gefunden!") end
- local taskPath = fs.combine(path, TASK_FILE)
- local file = fs.open(taskPath, "w")
- file.writeLine("task=create_chests")
- file.close()
- print("task.txt erfolgreich erstellt (create_chests).")
- end
- -- === Hauptprogramm ===
- print("Starte Settings-Setup...")
- local _, path = getSettingsDisk()
- while not path do
- print("Warte auf eingelegte Settings-Disk...")
- sleep(1)
- _, path = getSettingsDisk()
- end
- if coordsFileExists() then
- print("initial_coords.txt existiert bereits. Keine Aktion erforderlich.")
- else
- print("Keine initial_coords.txt gefunden. Bitte Koordinaten eingeben.")
- local x1, y1, z1 = askForCoords("Start-Koordinate eingeben (x y z):")
- local x2, y2, z2 = askForCoords("End-Koordinate eingeben (x y z):")
- -- === Nutzerabfrage zur Kistenerstellung ===
- print()
- print("Sollen die Kisten jetzt manuell erstellt werden oder per Task?")
- print("[1] Kisten existieren bereits")
- print("[2] Kisten sollen per Task erstellt werden")
- write("Auswahl (1 oder 2): ")
- local choice = read()
- if choice == "2" then
- createTaskFile()
- else
- print("Kein Task erstellt. Es wird davon ausgegangen, dass die Kisten vorhanden sind.")
- end
- saveInitialCoords(x1, y1, z1, x2, y2, z2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement