1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Programmable Block | Moving Inventory Items (Assembler -> Storage)

Discussion in 'Programming Questions and Suggestions' started by An_Astronaut, Jan 16, 2015.

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

    An_Astronaut Trainee Engineer

    Messages:
    1
    Hello fellow Engineers!

    I have just started looking into the programming block and so far cannot keep up with the ideas rushing through my head! I have been waiting for this block for so long. I have been wanting to script up something to push all built items from an assembler into a specific storage container or just simple "tidying up" storage inventories. However, it appears to be this is not yet possible for the programmable block? I have been searching the forums, In-Game API and Google for an answer, but with the programming block being so new, I have a feeling this is not yet possible. Am I correct on this assumption? If so, is this a planned feature and, if not, could I be lead in the right direction?

    Thanks,
    An_Astronaut

    P.S. I consider myself proficient in C#.
     
  2. Digi

    Digi Senior Engineer

    Messages:
    2,393
    It is quite possible.
    https://forums.keenswh.com/post/guide-accessing-inventory-from-programmable-block-7224691?trail=15
    https://forums.keenswh.com/post/transfer-items-from-one-container-to-another-example-please-7250828?pid=1285806136#post1285794511
     
    Last edited by a moderator: Jan 16, 2015
  3. ScriptyNoob

    ScriptyNoob Apprentice Engineer

    Messages:
    133
    Try this:

     
  4. MegaMiner

    MegaMiner Junior Engineer

    Messages:
    625
    Here is my assembler clearing scrcipt, it keeps them from filling up with gravel or iron etc.

    Code:
    // Balance Assemblers - clears excessive materials clogging input queue
    // Copyright 2015 Anthony Q. Bachler (MegaMiner)
    // Released under the Gnu General Public License (GPL) v3.0+
     
    void Main(){ 
        var Assemblers = new List<IMyTerminalBlock>();  
        GridTerminalSystem.GetBlocksOfType<IMyAssembler>(Assemblers);
        if(Assemblers == null) return;  
     
        var Cargo = new List<IMyTerminalBlock>();
        GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(Cargo);
        if(Cargo == null) return;
        IMyInventoryOwner CargoOwner = null;
        IMyCubeBlock      CargoCube  = null;
     
        // Find the first working functional non-empty cargo container
        var CargoIndex = 0;
        for(CargoIndex = 0;CargoIndex<Cargo.Count;CargoIndex++){
    CargoOwner = (IMyInventoryOwner)Cargo[CargoIndex];
    CargoCube = (IMyCubeBlock)Cargo[CargoIndex];
    if(CargoCube.IsWorking && CargoCube.IsFunctional && !CargoOwner.GetInventory(0).IsFull) break;
    }
        if(CargoIndex >= Cargo.Count) return; // no empty cargo containers
        
        // check assemblers for clogging
        for(var Index = 0;Index<Assemblers.Count;Index++){
    if(Assemblers[Index] == null) continue;
    var AssyOwner = (IMyInventoryOwner)Assemblers[Index];
    var Inventory = (IMyInventory)AssyOwner.GetInventory(0);
    var Items = new List<IMyInventoryItem>();
    Items = Inventory.GetItems();
    VRage.MyFixedPoint MaxAmount;
     
    int i = -1;
    while(Inventory.IsItemAt(++i)){ // set MaxAmount based on what it is.
       if(Items[i].Content.SubtypeName == "Stone")     MaxAmount = (VRage.MyFixedPoint) 10.00;
       if(Items[i].Content.SubtypeName == "Iron")      MaxAmount = (VRage.MyFixedPoint)600.00;
       if(Items[i].Content.SubtypeName == "Nickel")    MaxAmount = (VRage.MyFixedPoint) 70.00;
       if(Items[i].Content.SubtypeName == "Cobalt")    MaxAmount = (VRage.MyFixedPoint)220.00;
       if(Items[i].Content.SubtypeName == "Silicon")   MaxAmount = (VRage.MyFixedPoint) 15.00;
       if(Items[i].Content.SubtypeName == "Magnesium") MaxAmount = (VRage.MyFixedPoint)  5.20;
       if(Items[i].Content.SubtypeName == "Silver")    MaxAmount = (VRage.MyFixedPoint) 10.00;
       if(Items[i].Content.SubtypeName == "Gold")      MaxAmount = (VRage.MyFixedPoint)  5.00;
       if(Items[i].Content.SubtypeName == "Platinum")  MaxAmount = (VRage.MyFixedPoint)  0.40;
       if(Items[i].Content.SubtypeName == "Uranium")   MaxAmount = (VRage.MyFixedPoint)  0.50;
     
       MaxAmount *= 2; // allow this times as much as needed 
     
       if(Items[i].Amount > MaxAmount) Inventory.TransferItemTo(CargoOwner.GetInventory(0) , i , null , true , Items[i].Amount - MaxAmount);
       }
    }
        }
    
    
     
Thread Status:
This last post in this thread was made more than 31 days old.