private static void InventoryBaseTransferItem_Implementation(MyInventoryTransferEventContent eventParams) { if (!MyEntities.EntityExists(eventParams.DestinationOwnerId) || !MyEntities.EntityExists(eventParams.SourceOwnerId)) { return; } MyEntity sourceOwner = MyEntities.GetEntityById(eventParams.SourceOwnerId); MyInventoryBase source = sourceOwner.GetInventory(eventParams.SourceInventoryId); MyEntity destOwner = MyEntities.GetEntityById(eventParams.DestinationOwnerId); MyInventoryBase dst = destOwner.GetInventory(eventParams.DestinationInventoryId); var items = source.GetItems(); MyPhysicalInventoryItem?foundItem = null; foreach (var item in items) { if (item.ItemId == eventParams.ItemId) { foundItem = item; } } if (foundItem.HasValue) { dst.TransferItemsFrom(source, foundItem, eventParams.Amount); } }
private void Update(long deltaFrames) { var items = _sourceInventory.Items; foreach (var item in items) { if (_destInventory.CanAddItems(item.DefinitionId, 1) && _destInventory.TransferItemsFrom(_sourceInventory, item, 1)) { return; } } }