Hi all. Does anyone know of a built-in or simple method to get an itemId, Item, ItemDefinition, or ItemBlueprint from a deployed entity? I've been looking all over for a "clean" solution, but I've not been able to find anything.
Solved Get item from deployed entity
Discussion in 'Rust Development' started by ignignokt84, Mar 22, 2017.
-
Something like that is the common way:
Example from RemoverTool
Code:static Dictionary<string, string> PrefabNameToDeployable = new Dictionary<string, string>(); static Dictionary<string, string> PrefabNameToItemName = new Dictionary<string, string>(); void InitializeItems() { foreach (var item in ItemManager.GetItemDefinitions()) { if (!ItemNameToItemID.ContainsKey(item.displayName.english.ToLower())) ItemNameToItemID.Add(item.displayName.english.ToLower(), item.itemid); var itemdeployable = item?.GetComponent<ItemModDeployable>(); if (itemdeployable == null) continue; if (!PrefabNameToDeployable.ContainsKey(itemdeployable.entityPrefab.resourcePath)) PrefabNameToDeployable.Add(itemdeployable.entityPrefab.resourcePath, item.displayName.english); if(!PrefabNameToItemName.ContainsKey(itemdeployable.entityPrefab.resourcePath)) PrefabNameToItemName.Add(itemdeployable.entityPrefab.resourcePath, item.shortname); } }
-
@Fujikura - Thanks for this! It had just clicked in my brain that I should attack from the other direction and see if I could get the entity from the item and just build a reference map - that is exactly what I needed
-
Great to see this, i ran into the same issue aswell.