Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Assemblers Annoyance

Discussion in 'Gameplay Help' started by Spaceballs, Apr 20, 2015.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Spaceballs Trainee Engineer

    Messages:
    32
    Playing survival on 10x10x10x, and assemblers seem to take more ingots than the need from my ingot container. After some time producing parts, the input slots get clogged with ingots and I need to manually put them back into ingot container. I tried using Assembly Cleaning script here http://steamcommunity.com/sharedfiles/filedetails/?id=373239403&searchtext=
    but does not work or I'm not using it correctly. I place program block, add the code in control pannel, hit run. nothing happens.

    Is there a way I can use sorter blocks to clear the input slots on assemblers?
     
  2. tankmayvin Senior Engineer

    Messages:
    2,863
    I recommend using the inventory sort mod. Then you label every assembler so that it can only pull X amount of every ore and never clogs.
     
  3. mexmer Senior Engineer

    Messages:
    1,977
    weird, i downloaded script, made few changes to suit my taste, but still works
    Code:
    StringBuilder values;
    void Main()
    {
        List<IMyTerminalBlock> assemblers = new List<IMyTerminalBlock>();
        List<IMyTerminalBlock> containers = new List<IMyTerminalBlock>();
        List<IMyTerminalBlock> containersin = new List<IMyTerminalBlock>();
        List<IMyTerminalBlock> containersout = new List<IMyTerminalBlock>();
        values = new StringBuilder();
    
        GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(containers);
        for (int i=0; i<containers.Count; i++)
        {
            if (containers.CustomName.Contains("Ingot"))
                containersin.Add(containers);
            else if (containers.CustomName.Contains("Components"))
                containersout.Add(containers);
        }
    
        GridTerminalSystem.GetBlocksOfType<IMyAssembler>(assemblers);
        values.Append("found " + containersin.Count.ToString() + " ingot stores, " + containersout.Count.ToString() + " component stores, "  + assemblers.Count.ToString() + " assemblers\n");
    
        if (containersin.Count > 0 && containersout.Count > 0)
        for(int i = 0; i < assemblers.Count; i++)
        {
            		cleanAssembler(assemblers as IMyAssembler, containersin, containersout);
        }
        IMyTextPanel screen2 = (IMyTextPanel) GridTerminalSystem.GetBlockWithName("LCD Assemblers");   
      if (screen2 != null)   
      {
        screen2.WritePublicText(values.ToString());
        screen2.ShowPublicTextOnScreen();
      }
    }
    
    void cleanAssembler(IMyAssembler assembler, List<IMyTerminalBlock> containersin, List<IMyTerminalBlock> containersout)
    {
        if (assembler.IsProducing)
            return;
    
        IMyInventory containerDestination = null;
    
        // search our containers until we find an empty one
        for (int n = 0; n < containersin.Count; n++)
        {
            IMyInventory containerInv = containersin[n].GetInventory(0);
            if (!IsFull(containerInv))
            {
                containerDestination = containerInv;
                values.Append("Moving from " + assembler.CustomName + " to " + containersin[n].CustomName);
                break;
            }
        }
    
        if (containerDestination == null)
            return;
    
        IMyInventory assemblerInv = assembler.GetInventory(0);
        var assemblerItems = assemblerInv.GetItems();
        values.Append(" " + assemblerItems.Count.ToString() + " ingot(s)\n");
        for (int i = assemblerItems.Count -1; i >= 0; i--)
        {
            assemblerInv.TransferItemTo(containerDestination, i, null, true, null);
        }
    
        containerDestination = null;
        // search our containers until we find an empty one
        for (int n = 0; n < containersout.Count; n++)
        {
            IMyInventory containerInv = containersout[n].GetInventory(0);
            if (!IsFull(containerInv))
            {
                containerDestination = containerInv;
                values.Append("Moving from " + assembler.CustomName + " to " + containersout[n].CustomName); 
                break;
            }
        }
    
        if (containerDestination == null)
            return;
    
        assemblerInv = assembler.GetInventory(1);
        assemblerItems = assemblerInv.GetItems();
        values.Append(" " + assemblerItems.Count.ToString() + " components(s)\n");
    
        for (int i = assemblerItems.Count -1; i >= 0; i--)
        {
            assemblerInv.TransferItemTo(containerDestination, i, null, true, null);
        }
    }
    
    float getPercent(IMyInventory inv)
    {
        return ((float)inv.CurrentVolume / (float)inv.MaxVolume) * 100f;
    }
    
    
    bool IsFull(IMyInventory inv)
    {
        if (getPercent(inv) >= 90)
            return true;
        else
            return false;
    }
    
    and timer block, that runs this script once a minute (should be enough)
     
  4. Kain Reaver Apprentice Engineer

    Messages:
    374
    That, or you could use a conveyor sorter set to drain all ingots, and turned off until you want to clear your assemblers.
     
Thread Status:
This last post in this thread was made more than 31 days old.