Advertisement
Blackhome

Settings Manager

May 2nd, 2025 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | Gaming | 0 0
  1. -- Settings Writer for Storage System
  2. -- Platziert über dem Disk Drive mit der "Settings"-Disk
  3.  
  4. local SETTINGS_LABEL = "Settings"
  5. local COORD_FILE = "initial_coords.txt"
  6. local TASK_FILE = "task.txt"
  7.  
  8. -- Funktion: Hole Disk-Laufwerk mit Label "Settings"
  9. function getSettingsDisk()
  10.     for _, side in ipairs(peripheral.getNames()) do
  11.         if peripheral.getType(side) == "drive" then
  12.             local disk = peripheral.wrap(side)
  13.             if disk.getDiskLabel() == SETTINGS_LABEL then
  14.                 return disk, disk.getMountPath()
  15.             end
  16.         end
  17.     end
  18.     return nil, nil
  19. end
  20.  
  21. -- Funktion: Überprüft, ob initial_coords.txt bereits existiert
  22. function coordsFileExists()
  23.     local _, path = getSettingsDisk()
  24.     if not path then return false end
  25.     return fs.exists(fs.combine(path, COORD_FILE))
  26. end
  27.  
  28. -- Funktion: Fragt den Nutzer nach einer Koordinate (in Form "x y z")
  29. function askForCoords(promptText)
  30.     while true do
  31.         print(promptText)
  32.         local input = read()
  33.         local x, y, z = input:match("(-?%d+)%s+(-?%d+)%s+(-?%d+)")
  34.         if x and y and z then
  35.             return tonumber(x), tonumber(y), tonumber(z)
  36.         else
  37.             print("Ungültiges Format. Bitte erneut eingeben als: x y z")
  38.         end
  39.     end
  40. end
  41.  
  42. -- Funktion: Speichert die beiden Koordinaten in initial_coords.txt
  43. function saveInitialCoords(x1, y1, z1, x2, y2, z2)
  44.     local _, path = getSettingsDisk()
  45.     if not path then error("Settings-Disk nicht gefunden!") end
  46.  
  47.     local fullPath = fs.combine(path, COORD_FILE)
  48.     local file = fs.open(fullPath, "w")
  49.     file.writeLine(string.format("%d,%d,%d", x1, y1, z1))
  50.     file.writeLine(string.format("%d,%d,%d", x2, y2, z2))
  51.     file.close()
  52.     print("Koordinaten erfolgreich gespeichert.")
  53. end
  54.  
  55. -- Funktion: Erstellt task.txt auf Settings-Disk
  56. function createTaskFile()
  57.     local _, path = getSettingsDisk()
  58.     if not path then error("Settings-Disk nicht gefunden!") end
  59.  
  60.     local taskPath = fs.combine(path, TASK_FILE)
  61.     local file = fs.open(taskPath, "w")
  62.     file.writeLine("task=create_chests")
  63.     file.close()
  64.     print("task.txt erfolgreich erstellt (create_chests).")
  65. end
  66.  
  67. -- === Hauptprogramm ===
  68. print("Starte Settings-Setup...")
  69.  
  70. local _, path = getSettingsDisk()
  71. while not path do
  72.     print("Warte auf eingelegte Settings-Disk...")
  73.     sleep(1)
  74.     _, path = getSettingsDisk()
  75. end
  76.  
  77. if coordsFileExists() then
  78.     print("initial_coords.txt existiert bereits. Keine Aktion erforderlich.")
  79. else
  80.     print("Keine initial_coords.txt gefunden. Bitte Koordinaten eingeben.")
  81.     local x1, y1, z1 = askForCoords("Start-Koordinate eingeben (x y z):")
  82.     local x2, y2, z2 = askForCoords("End-Koordinate eingeben (x y z):")
  83.         -- === Nutzerabfrage zur Kistenerstellung ===
  84.         print()
  85.         print("Sollen die Kisten jetzt manuell erstellt werden oder per Task?")
  86.         print("[1] Kisten existieren bereits")
  87.         print("[2] Kisten sollen per Task erstellt werden")
  88.         write("Auswahl (1 oder 2): ")
  89.         local choice = read()
  90.    
  91.         if choice == "2" then
  92.             createTaskFile()
  93.         else
  94.             print("Kein Task erstellt. Es wird davon ausgegangen, dass die Kisten vorhanden sind.")
  95.         end
  96.     saveInitialCoords(x1, y1, z1, x2, y2, z2)
  97. end
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement