Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function saveToFile(filename, content)
- local file = fs.open(filename, "w")
- if file then
- file.write(content)
- file.close()
- else
- print("Nelze otevřít soubor pro zápis: " .. filename)
- end
- end
- local lp = peripheral.wrap("front") -- Request Pipe na straně "front"
- local output = ""
- if lp then
- local items = lp.getAvailableItems()
- if #items == 0 then
- output = output .. "V síti nejsou žádné dostupné položky.\n"
- else
- output = output .. "Dostupné položky v síti:\n"
- for _, pair in ipairs(items) do
- -- Získání názvu položky z objektu getType1
- local successType1, type1 = pcall(function() return pair.getType1() end)
- local itemName = "Neznámý název"
- if successType1 and type(type1) == "table" and type1.getFriendlyName then
- local successName, friendlyName = pcall(type1.getFriendlyName, type1)
- if successName then
- itemName = friendlyName
- end
- end
- -- Získání množství položky
- local successValue2, value2 = pcall(function() return pair.getValue2() end)
- local itemQuantity = successValue2 and tonumber(value2) or 0
- -- Sestavení výstupu
- output = output .. string.format("Položka: %s, Množství: %d\n", tostring(itemName), itemQuantity)
- end
- end
- else
- output = output .. "Nenalezena žádná Logistics Pipe.\n"
- end
- local filename = "items_summary.txt"
- saveToFile(filename, output)
- print("Výstup byl uložen do souboru " .. filename)
- -- Spuštění příkazu pastebin put
- local success = shell.run("pastebin", "put", filename)
- -- Výpis výsledku
- if success then
- print("Soubor byl úspěšně nahrán na Pastebin. Zkontrolujte konzoli pro odkaz.")
- else
- print("Chyba při nahrávání na Pastebin.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement