Advertisement
Wassaa

mergedScripts

Jan 9th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. local chest = peripheral.wrap("container_chest_5")
  2. local oreMot = peripheral.wrap("extractor_11")
  3. local dustMot = peripheral.wrap("extractor_10")
  4. --local oreExt = peripheral.wrap("extractor_6")   -- ore extractor
  5. local size = chest.getInventorySize()
  6. local oresDir = "north"
  7. local endDir = "west"
  8. local oreSig = "left"
  9. local dustSig = "right"
  10. local oresToPush = {}
  11. local ores = {"15:0","14:0", "2001:0"}
  12.  
  13. if not fs.exists("/ores") then
  14.         print ("creating ores file")
  15.         local f = io.open("/ores", "w")
  16.         f:write(textutils.serialize(ores))
  17.         f:close()
  18. end
  19. function copyToDisk()
  20.     if fs.exists("/disk") then
  21.         local f = io.open("/disk/ores", "w")
  22.         f:write(textutils.serialize(ores))
  23.         f:close()
  24.     end
  25. end
  26. print("size is: " .. size)
  27. function getOresFile()
  28.     local f = io.open("/ores", "r")
  29.     local data = f:read("*l")
  30.     ores = textutils.unserialize(data)
  31.     f:close()
  32.     copyToDisk()
  33.    
  34. end
  35.  
  36. --see if item is extractable
  37. function isOre(ore)
  38.     for k,v in pairs(ores) do
  39.       if (ore == v) then
  40.         return true
  41.       end
  42.     end
  43.     return false
  44. end
  45.  
  46. --loop throught the inventory
  47. function stuffToSend()
  48.     --chest.condenseItems()
  49.     for i=1,size do
  50.         --print (i)
  51.         local id = chest.getStackInSlot(i)
  52.         if (id ~= nil) then
  53.             local combID = tostring(id["id"])..":"..tostring(id["dmg"])
  54.             local iName = tostring(id["name"])
  55.             --print (combID)
  56.            
  57.             if isOre(combID) and (string.find(iName, "Ore") ~= nil or string.find(iName, "ore") ~= nil) then
  58.                 print (iName.." to tha list to push")
  59.                 local leng = table.getn(oresToPush) + 1
  60.                 oresToPush[leng] = i
  61.                 --chest.pushItem(oresDir,i,64)
  62.             end
  63.         end
  64.     end
  65.     sendStuff()
  66. end
  67.  
  68.  
  69. function sendStuff()
  70.     if table.getn(oresToPush) ~= 0 then
  71.         for k,v in pairs(oresToPush) do
  72.             print (chest.getStackInSlot(v)["name"])
  73.             while chest.getStackInSlot(v) ~= nil do
  74.                 chest.pushItemIntoSlot(oresDir,v,64,1)
  75.                 getResult(1)
  76.                 getResult(2)
  77.                 --os.sleep(0.5)
  78.                 print ("loop")
  79.             end
  80.         end
  81.     end
  82.     oresToPush = {}
  83. end
  84.  
  85.  
  86. function notDone()
  87.     for i = 1, 9 do
  88.         local slot = oreMot.getStackInSlot(i)
  89.         local slot1 = dustMot.getStackInSlot(i)
  90.         if slot ~= nil or slot1 ~= nil then
  91.             return true
  92.        
  93.         end
  94.     end
  95.     return false
  96. end
  97.        
  98.        
  99.  
  100. function slotTable(nr, rig)
  101. --print (rig.getStackInSlot(nr))
  102. return rig.getStackInSlot(nr)
  103. end
  104.    
  105. function getResult(mode)
  106.  
  107.     if mode == 1 then
  108.         --print("ore machine")
  109.         machine = oreMot
  110.         matSlot1 = 1
  111.         matSlot2 = 4
  112.         resSlot1 = 5
  113.         resSlot2 = 2
  114.         resSlot3 = 8
  115.         resSlot4 = 9
  116.         signal = oreSig
  117.         opDir = oresDir
  118.     else
  119.         --print("dust machine")
  120.         machine = dustMot
  121.         matSlot1 = 2
  122.         matSlot2 = 3
  123.         resSlot1 = 7
  124.         resSlot2 = 4
  125.         signal = dustSig
  126.         opDir = "south"
  127.        
  128.     end
  129.     --check if machines have stuff to work with, if not take away Red
  130.     if slotTable(matSlot1, machine) == nil and slotTable(matSlot2, machine) == nil then
  131.         print (tostring(matSlot1) .. "and" .. tostring (matSlot2) .. " are empty")
  132.         rs.setOutput(signal, false)
  133.     else
  134.         rs.setOutput(signal, true)
  135.     end
  136.        
  137.     --first result material (dust/solution) gets moved
  138.     if slotTable(resSlot1, machine) ~= nil then
  139.         machine.pushItemIntoSlot(opDir, resSlot1, 64, resSlot1 - 3)
  140.     end
  141.     --move more sutff
  142.     if slotTable(resSlot2, machine) ~= nil then
  143.         machine.pushItemIntoSlot(opDir, resSlot2, 64, resSlot2)
  144.     end
  145.    
  146.     if machine == oreMot then
  147.         if slotTable(resSlot3, machine) ~= nil then
  148.             --print ("pushing")
  149.             machine.pushItem(endDir, resSlot3, 64)
  150.         --else
  151.             --print("done")
  152.         elseif slotTable(resSlot4, machine) ~= nil then
  153.             machine.pushItem(endDir, resSlot4, 64)
  154.         end
  155.     end
  156. end
  157. --run functions
  158. getOresFile()
  159. stuffToSend()
  160. while notDone() do
  161. getResult(1)
  162. getResult(2)
  163. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement