i want to access barrels's loot when they spawn and add 1 scrap to them, i still dont know exactly how to do this but i was thinking something like
i know the syntaxis is wrong and that is what i am needing, this is kind of a pseudocodeCode:void OnEntitySpawned(BaseNetworkable entity, ItemContainer container) { if (entity.name == "loot-barrel-1" || entity.name == "loot-barrel-2") { Item item = ItemManager.CreateByItemID(109266897, 1);//create scrap item item.MoveToContainer(container); } }
Solved Accesing entity's items?
Discussion in 'Rust Development' started by Bruno Puccio, Mar 1, 2018.
-
I'm not sure but i think SimpleLoot might have some answers.
-
Hello, you must use "Contains" instead of "==" OR you may compare to the "ShortPrefabName" instead of "name"
entity.name will give you the complete prefab name as ShortPrefabName give you only the name "loot-barrel-1"
Also, when you create an item with CreateByItemID or similar method, you may verify if your item as successfully been created
You have to get container from entity as the hook changed
Code:void OnEntitySpawned(BaseNetworkable entity) { var containers = entity as LootContainer; if (entity.ShortPrefabName == "loot-barrel-1" || entity.ShortPrefabName == "loot-barrel-2") { if (containers != null) { Item item = ItemManager.CreateByItemID(109266897, 1); //create scrap item item?.MoveToContainer(containers.inventory); } } }
-
-
Code:if(item != null) item.MoveToContainer(containers.inventory);