Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ci = peripheral.find("colonyIntegrator") or error("No CoIn attached", 0)
- bridge = peripheral.find("meBridge") or error("No meBridge attached", 0)
- -- ME system extraction
- function meExtract (eItem, eCount, eTable)
- sItem = tostring(eItem)
- --print(sItem)
- function exporter (sItem, eCount)
- result, err = bridge.exportItem({name=sItem, count=eCount}, "up")
- if err then
- print("export failure")
- else
- print(result)
- print("export success")
- end
- end
- -- check for item in storage
- hasItem, err = bridge.getItem({name = eTable.name})
- if err or (hasItem.name == nil) then
- --doesnt have it
- if hasItem.isCraftable then
- craftSuccess, err = bridge.craftItem({name=sItem, count=eCount})
- if err then
- print("ME Craft failure")
- print("Unable to provide")
- else
- print("ME system Crafting requested...")
- end
- else
- print("ME Crafting unable")
- print("Unable to provide")
- end
- --print("debug:", "count: ", hasItem.count)
- --print("debug:", "debug table failure")
- --print("debug:", "error: ", err)
- else
- --has it
- if hasItem.amount >= eCount then
- -- attempt export
- exporter(sItem, eCount)
- else
- print("ME system cannot provide full amount")
- print("exporting: ", hasItem.amount, " of ", eCount)
- exporter(sItem, hasItem.amount)
- end
- end
- end
- -- retreive active work orders
- woOrder = ci.getWorkOrders()
- -- Check for availability of resources in work orders
- for i=1, #woOrder,1 do
- print("Checking work order number ", i, " of ", #woOrder)
- -- retrieve table for resources for work order
- woID = tonumber(woOrder[i].id)
- woOrResources = ci.getWorkOrderResources(woID)
- -- check through resources
- if woOrResources ~= nil then
- for r=1, #woOrResources,1 do
- availability = woOrResources[r].available
- print("----")
- print(woOrResources[r].displayName, ", available: ", availability)
- if availability == 0 then
- print("none found, attempting extract..")
- meExtract(woOrResources[r].item.name, woOrResources[r].needed, woOrResources[r].item)
- else
- print("skipping")
- end
- end
- end
- print(#woOrder, " complete")
- end
Advertisement
Add Comment
Please, Sign In to add comment