private void ConsumeSomething(string something, int amount) { foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions()) { var physicalItemDef = definition as MyPhysicalItemDefinition; if (physicalItemDef == null || physicalItemDef.CanSpawnFromScreen == false) { continue; } if (definition.DisplayNameText == something) { MyEntity invObject = MySession.Static.ControlledEntity as MyEntity; MyInventory inventory = invObject.GetInventory(0) as MyInventory; if (inventory != null) { var builder = (MyObjectBuilder_PhysicalObject)VRage.ObjectBuilders.MyObjectBuilderSerializer.CreateNewObject(definition.Id); inventory.ConsumeItem(physicalItemDef.Id, amount, MySession.Static.LocalCharacterEntityId); } break; } } }