As the title, how would I get the player info and container location in the hook OnItemRemovedFromContainer?
Code:void OnItemRemovedFromContainer(ItemContainer container, Item item) { Puts("OnItemRemovedFromContainer works!"); }
Get player info and container location in OnItemRemovedFromContainer
Discussion in 'Rust Development' started by TheOnlyTermin, May 14, 2016.
-
Here's a small snippet, not all containers have owner players though, and not all have entity owners, either. Tweak it from here.Code:
void OnItemRemovedFromContainer(ItemContainer container, Item item) { if (container == null || item == null) return; var player = container?.playerOwner ?? null; var entityOwner = container?.entityOwner ?? null; if (player == null || entityOwner == null) return; if (player.IsDead() || !player.IsConnected()) return; -
Thanks! Is it possible to get the player who removed the items?
-
Sort of. Only if they move it to their body. Using a NextTick() you can see where the item goes after it's moved. If it goes to a player's container, you can use container entityOwner or possibly playerOwner on that "new" container, and get the player from there. If the item is dropped from a crate/box, I don't believe you can find out who dropped it.
