I had this working last week, using OnEntitySpawned to clear a corpses inventory on death but now its stopped working. Any help would be appreciated. Thanks.
Solved Clearing inventory of corpse?
Discussion in 'Rust Development' started by Mr_Jeff, Jan 24, 2017.
-
Maybe with the code, it will be easier to see what happend
-
Sorry was on iDevice.
It defiantly worked at one point then stopped after last weeks update.
Thanks.
May have the wrong bit but im sure it had
if (entity is BaseCorpse)
Code:void OnEntitySpawned(ItemContainer container) { if (container.itemList.Count > 0) { var items = container.itemList[0]; item.RemoveFromContainer(); item.Remove(0f); } }
Last edited by a moderator: Jan 24, 2017 -
Some evident error first you have to loop for getting all items in container and next using a correct variable like you declare items but use item without "s"
-
-
Code:void OnEntitySpawned(BaseNetworkable entity) { if (entity is BaseCorpse) { var corpse = entity.GetComponent<LootableCorpse>(); if (corpse != null) { if (corpse.playerSteamID != 0) { items.RemoveFromContainer(); items.Remove(0f); } } } }
Last edited by a moderator: Jan 24, 2017 -
Getting this to work but then get object issue. Hmmm.
Code:void OnEntitySpawned(BaseNetworkable entity, ItemContainer container) { if (entity is BaseCorpse) { var corpse = entity.GetComponent<LootableCorpse>(); if (corpse != null) { containerMain.Kill(); } } }
`item.Remove(0f)' is inaccessible due to its protection levelLast edited by a moderator: Jan 25, 2017 -
Wulf Community Admin
Code:void OnEntitySpawned(BaseNetworkable entity, ItemContainer container) { var corpse = entity as LootableCorpse; if (corpse == null) return; container.itemList.Clear(); }
-
(NullReferenceException: Object reference not set to an instance of an object) that now. -
Wulf Community Admin
[DOUBLEPOST=1485309725,1485309163][/DOUBLEPOST]Here's a working example, may be a more direct way to clear all, but it works:
Code:void OnEntitySpawned(BaseNetworkable entity) { var corpse = entity as LootableCorpse; if (corpse == null) return; foreach (var container in corpse.containers) container.itemList.Clear(); }
container 1 = wear
container 2 = belt -
You dude are amazing. It works.
Thanks