When I use CanEquipItem hook i try:
And this don't work.Code:void CanEquipItem(PlayerInventory inventory, Item item) { item.MoveToContainer(inventory.containerMain); }
But when i use this:
this work fine.Code:[ChatCommand("testm")] void AddressCommand(BasePlayer player, string command, string[] args) { player.inventory.containerBelt.GetSlot(1).MoveToContainer(player.inventory.containerMain); }
Moving item to container?
Discussion in 'Rust Development' started by Kuhulin, Mar 27, 2017.
-
You probably misusing hook CanEquipItem.
Possible situation: Hook being called when Rust are checking if item can be equipped.
You are moving it to different container and when check ends rust moves item to the appropriate slot.
Possible solution: Override behavior of CanEquipItem by returning bool value. -
@VVoid is correct - you are not using the CanEquipItem hook quite right. This hook is called before the item is moved to any inventory, and should have a return type of object, not void. Then if you're looking to prevent an item from being equipped into the belt, then all you have to do is return false (after checking for said item/inventory) and the item will not be moved to the belt.
-
Essentially do what you where doing
But like so
Code:private object CanEquipItem(PlayerInventory inventory, Item item) { // Run your code here return false; // to bypass the default move }