ivanzrer

colony2

Nov 3rd, 2024 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. ci = peripheral.find("colonyIntegrator")  or error("No ColonyIntegrator attached", 0)
  2. bridge = peripheral.find("meBridge")  or error("No meBridge attached", 0)
  3.  
  4. -- ME system extraction
  5. function meExtract (eItem, eCount, eTable)
  6.     sItem = tostring(eItem)
  7.  
  8.     -- export from system
  9.     function exporter (sItem, eCount)
  10.         result, err = bridge.exportItem({name=sItem, count=eCount}, "up")
  11.         if err then
  12.             print("export failure")
  13.         else    
  14.             print("exporting ", result)
  15.             print("export success")
  16.         end
  17.     end
  18.  
  19.     -- craft resource
  20.     function crafter (sItem, eCount)
  21.         craftSuccess = bridge.craftItem({name=sItem, count=eCount})
  22.         --bridge.craftItem({name=sItem, count=eCount})
  23.         if craftSuccess then
  24.             print("ME crafting success")
  25.             return true
  26.         else
  27.             print("ME crafting failure")
  28.             return false
  29.         end
  30.     end
  31.  
  32.     -- check for item in storage
  33.     hasItem, err = bridge.getItem({name = eTable.name})
  34.     if err or (hasItem.name == nil) then
  35.         --doesnt have it
  36.         print("None found..")
  37.         if hasItem.isCraftable then
  38.             -- Can be crafted
  39.             print("Attempting ME crafting..")
  40.             if crafter(sItem, eCount) then
  41.                 exporter(sItem, eCount)
  42.             else
  43.                 print("ME Craft failure")
  44.                 print("Unable to provide")
  45.             end
  46.         else
  47.             -- Cannot be crafted
  48.             print("ME Crafting unable")
  49.             print("Unable to provide")
  50.         end
  51.  
  52.     else
  53.         --has it
  54.         if hasItem.amount >= eCount then
  55.             -- attempt export
  56.             exporter(sItem, eCount)
  57.         else
  58.             print("ME system cannot provide full amount")
  59.             print("Attempting to craft remainder...")
  60.  
  61.             restCount = eCount - hasItem.amount
  62.             if crafter(sItem, restCount) then)
  63.                 exporter(sItem, restCount)
  64.             else
  65.                 print("Crafting failure")
  66.                 print("exporting: ", hasItem.amount, " of ", eCount)
  67.                 exporter(sItem, hasItem.amount)
  68.             end
  69.         end
  70.     end
  71.    
  72. end
  73.  
  74. -- retreive active work orders
  75. woOrder = ci.getWorkOrders()
  76.  
  77. -- Check for availability of resources in work orders
  78. -- loop through work orders
  79. for i=1, #woOrder,1 do
  80.     print("Checking work order number ", i, " of ", #woOrder)
  81.     -- retrieve table for resources for work order
  82.     woID = tonumber(woOrder[i].id)
  83.     woOrResources = ci.getWorkOrderResources(woID)
  84.    
  85.     -- check through resources
  86.     if woOrResources ~= nil then
  87.         for r=1, #woOrResources,1 do
  88.             availability = woOrResources[r].available
  89.             print("----")
  90.             print(woOrResources[r].displayName, ", available: ", availability)
  91.             -- if resource is not available, then call for extract
  92.             if availability == 0 then
  93.                 print("none found, attempting extract..")
  94.                 meExtract(woOrResources[r].item.name, woOrResources[r].needed, woOrResources[r].item)
  95.             else
  96.                 print("skipping")
  97.             end
  98.         end
  99.     end
  100.     print(i, " complete")
  101. end
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment