Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script: diagnose_orders_to_file.lua
- -- Purpose: Dumps detailed information about all active work orders and their resources to a file.
- local COLONY_INTEGRATOR_NAME = "colonyIntegrator"
- local OUTPUT_FILE = "colony_orders_report.txt"
- local colony = peripheral.find(COLONY_INTEGRATOR_NAME)
- if not colony then
- print("ERROR: Colony Integrator ('" .. COLONY_INTEGRATOR_NAME .. "') not found!")
- return
- end
- local file = fs.open(OUTPUT_FILE, "w") -- Open in write mode to overwrite/create
- if not file then
- print("ERROR: Could not open output file: " .. OUTPUT_FILE)
- return
- end
- print("Colony Integrator found. Writing data to " .. OUTPUT_FILE .. "...\n")
- file.write("Colony Work Order and Resource Report - " .. textutils.formatTime(os.time(), false) .. "\n")
- local workOrders = colony.getWorkOrders()
- if not workOrders or #workOrders == 0 then
- file.write("No active workOrders found.\n")
- print("No active workOrders found.")
- file.close()
- return
- end
- file.write("Found " .. #workOrders .. " work order(s):\n")
- file.write("----------------------------------------\n")
- print("Found " .. #workOrders .. " work order(s). See " .. OUTPUT_FILE .. " for details.")
- for i, wo in ipairs(workOrders) do
- file.write("\n--- Work Order #" .. i .. " ---\n")
- file.write(" ID: " .. tostring(wo.id) .. "\n")
- file.write(" Building Name: " .. tostring(wo.buildingName) .. "\n")
- file.write(" Work Order Type: " .. tostring(wo.workOrderType) .. "\n")
- file.write(" Target Level: " .. tostring(wo.targetLevel) .. "\n")
- file.write(" Is Claimed: " .. tostring(wo.isClaimed) .. "\n")
- file.write(" Changed: " .. tostring(wo.changed) .. "\n")
- if wo.builder then
- file.write(" Builder Location: X:" .. wo.builder.x .. " Y:" .. wo.builder.y .. " Z:" .. wo.builder.z .. "\n")
- else
- file.write(" Builder Location: N/A\n")
- end
- file.write(" Resources for this Work Order (ID: " .. tostring(wo.id) .. "):\n")
- local resources = colony.getWorkOrderResources(wo.id)
- if resources then
- if #resources > 0 then
- for resIdx, res in ipairs(resources) do
- file.write(" --- Resource #" .. resIdx .. " ---\n")
- local sResItem = "UnknownItemRegistry"
- if type(res.item) == "table" then sResItem = res.item.name or "UnknownInTable" elseif type(res.item) == "string" then sResItem = res.item end
- local sResDisplayName = sResItem
- if type(res.displayName) == "table" then sResDisplayName = res.displayName.name or sResDisplayName elseif type(res.displayName) == "string" then sResDisplayName = res.displayName end
- file.write(" Item Registry: " .. sResItem .. "\n")
- file.write(" Display Name: " .. sResDisplayName .. "\n")
- file.write(" Needed: " .. tostring(res.needed) .. " (Type: " .. type(res.needed) .. ")\n")
- file.write(" Available: " .. tostring(res.available) .. " (Type: " .. type(res.available) .. ")\n")
- file.write(" Delivering: " .. tostring(res.delivering) .. " (Type: " .. type(res.delivering) .. ")\n")
- file.write(" Status: " .. tostring(res.status) .. " (Type: " .. type(res.status) .. ")\n")
- -- Full dump of the 'res' table to the file
- file.write(" Raw 'res' table content for this resource:\n")
- for k, v in pairs(res) do
- file.write(" " .. tostring(k) .. ": " .. tostring(v) .. " (Type: " .. type(v) .. ")\n")
- end
- end
- else
- file.write(" No specific resource entries listed for this work order.\n")
- end
- else
- file.write(" Failed to retrieve resources for this work order (getWorkOrderResources returned nil).\n")
- end
- file.write("----------------------------------------\n")
- end
- file.write("\nDiagnostic scan complete.\n")
- file.close()
- print("Diagnostic data written to " .. OUTPUT_FILE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement