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)
- -- export from system
- function exporter (sItem, eCount)
- result, err = bridge.exportItem({name=sItem, count=eCount}, "up")
- if err then
- print("export failure")
- else
- print("exporting ", result)
- print("export success")
- end
- end
- -- craft resource
- function crafter (sItem, eCount)
- if craftSuccess == bridge.craftItem({name=sItem, count=eCount}) then
- print("ME crafting success")
- return true
- else
- return false
- end
- end
- -- check for item in storage
- hasItem, err = bridge.getItem({name = eTable.name})
- if err or (hasItem.name == nil) then
- --doesnt have it
- print("None found..")
- if hasItem.isCraftable then
- -- Can be crafted
- print("Attempting ME crafting..")
- if crafter(sItem, eCount) then
- exporter(sItem, eCount)
- else
- print("ME Craft failure")
- print("Unable to provide")
- end
- else
- -- Cannot be crafted
- print("ME Crafting unable")
- print("Unable to provide")
- end
- else
- --has it
- if hasItem.amount >= eCount then
- -- attempt export
- exporter(sItem, eCount)
- else
- print("ME system cannot provide full amount")
- print("Attempting to craft remainder...")
- restCount = eCount - hasItem.amount
- if crafter(sItem, restCount) then
- exporter(sItem, eCount)
- else
- print("Crafting failure")
- print("exporting: ", hasItem.amount, " of ", eCount)
- exporter(sItem, hasItem.amount)
- end
- end
- end
- end
- -- retreive active work orders
- woOrder = ci.getWorkOrders()
- -- Check for availability of resources in work orders
- -- loop through 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 resource is not available, then call for extract
- 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(i, " complete")
- end
Advertisement
Add Comment
Please, Sign In to add comment