Checking if inventory is full?
Discussion in 'Rust Development' started by Sauron 2, Jul 23, 2016.
-
player.inventory.AllItems().Length
-
An example of when he filled out the inventory he will not be able to take KIT. -
Well there are 36 slots in a players inventory so...
if (player.inventory.AllItems().Length == 36)
You would also need to take into account seperate containers though, a user may not have a full "wear" container and if the kit item is not wearable you will loose it. So you would need to get the amount of items in the kit and check if the players inventory has enough slots in the right containers to take all the items -
Code:void CanAcceptItem(ItemContainer container, Item item) { Puts("CanAcceptItem works!"); }
-
What are you trying to do? -
Code:
void CanAcceptItem(ItemContainer container, Item item) { var player = container.GetOwnerPlayer(); }
-
Code:object canRedeemKit(BasePlayer player) { if(player.inventory.AllItems().Length == 36) return "Something."; else return null; }
-
Yes, but like I mentioned above, that is only very basically covering it. If the user has no 'wear' items on his total items will be 30, if the kit doesn't have 'wear' items it will still be allowed yet the player will lose all its contents. If you want proper coverage you need to do a lot more than that
-
-
The GiveItem (on PlayerLoot) method actually returns a bool (true when the item was given and false when it failed), it would actually be better if that return value is actually used in the plugin and when it fails to give an item, all items already given from the same kit at that time which succeeded should be taken away again and a message could then be displayed to the user stating that there is not enough room to redeem the kit.
Code:public bool GiveItem(Item item, ItemContainer container = null) { if (item == null) { return false; } int num = -1; this.GetIdealPickupContainer(item, ref container, ref num); if (container != null && item.MoveToContainer(container, num, true)) { return true; } if (item.MoveToContainer(this.containerMain, -1, true)) { return true; } if (item.MoveToContainer(this.containerBelt, -1, true)) { return true; } return false; }