ivanzrer

Untitled

Nov 1st, 2024 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. ci = peripheral.find("colonyIntegrator")  or error("No CoIn 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.     --print(sItem)
  8.  
  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(result)
  15.             print("export success")
  16.         end
  17.     end
  18.  
  19.     -- check for item in storage
  20.     hasItem, err = bridge.getItem({name = eTable.name})
  21.     if err or (hasItem.name == nil) then
  22.         --doesnt have it
  23.         if hasItem.isCraftable then
  24.             craftSuccess, err = bridge.craftItem({name=sItem, count=eCount})
  25.             if err then
  26.                 print("ME Craft failure")
  27.                 print("Unable to provide")
  28.             else
  29.                 print("ME system Crafting requested...")
  30.             end
  31.         else
  32.             print("ME Crafting unable")
  33.             print("Unable to provide")
  34.         end
  35.         --print("debug:", "count: ", hasItem.count)
  36.         --print("debug:", "debug table failure")
  37.         --print("debug:", "error: ", err)
  38.     else
  39.         --has it
  40.         if hasItem.amount >= eCount then
  41.             -- attempt export
  42.             exporter(sItem, eCount)
  43.         else
  44.             print("ME system cannot provide full amount")
  45.             print("exporting: ", hasItem.amount, " of ", eCount)
  46.             exporter(sItem, hasItem.amount)
  47.         end
  48.     end
  49.    
  50. end
  51.  
  52. -- retreive active work orders
  53. woOrder = ci.getWorkOrders()
  54.  
  55. -- Check for availability of resources in work orders
  56. for i=1, #woOrder,1 do
  57.     print("Checking work order number ", i, " of ", #woOrder)
  58.     -- retrieve table for resources for work order
  59.     woID = tonumber(woOrder[i].id)
  60.     woOrResources = ci.getWorkOrderResources(woID)
  61.    
  62.     -- check through resources
  63.     if woOrResources ~= nil then
  64.         for r=1, #woOrResources,1 do
  65.             availability = woOrResources[r].available
  66.             print("----")
  67.             print(woOrResources[r].displayName, ", available: ", availability)
  68.             if availability == 0 then
  69.                 print("none found, attempting extract..")
  70.                 meExtract(woOrResources[r].item.name, woOrResources[r].needed, woOrResources[r].item)
  71.             else
  72.                 print("skipping")
  73.             end
  74.         end
  75.     end
  76.     print(#woOrder, " complete")
  77. end
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment