NickNDS

Get Cargo Containers Example

Nov 27th, 2020
623
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Initialize list
  2. List<IMyCargoContainer> cargoContainerList = new List<IMyCargoContainer>();
  3.  
  4. //Get all accessible cargo containers
  5. GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(cargoContainerList);
  6.  
  7. //Get all cargo containers on the same grid by comparing the grid the programmable block is on to each cargo container
  8. GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(cargoContainerList, block => block.CubeGrid == Me.CubeGrid);
  9.  
  10. //Get all cargo containers by name
  11. string cargoContainerName = "[Count]"; //You will want a setting at the top of the script you can easily change
  12. string name = cargoContainerName.ToLower(); //Before using it multiple times like this loop below, make a temporary lower case version to compare with the lower case names
  13. GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(cargoContainerList, block => block.CustomName.ToLower().Contains(name));
  14.  
  15. //You can combine the checks to get containers on the same grid with the key in their name
  16. GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(cargoContainerList, block => block.CubeGrid == Me.CubeGrid && block.CustomName.ToLower().Contains(name));
RAW Paste Data