There may be some differences in translation. I use Google Translate.
To put it simply, I want to determine whether the workbench or player's slot is full, and whether there are free slots.
You can use the CanCraft hook to check when a player is crafting.
Then you can use the `Storage` of the `Crafter` to ge the `Inventory` class. When you have that, you can loop over all inventory items and see if the inventory slots are full or not.
Here is a little example, it's not tested so not sure if it works:
object CanCraft(Crafter crafter, PlayerSession session, ICraftable recipe, int count)
{
Inventory inv = crafter.Storage;
for (int i = 0; i < inv.Capacity; i++)
{
ItemObject slot = inv.GetSlot(i);
//TODO: Check if slot is null (meaning it's empty) and cancel the craft.
}
return null;
} MrBlue
You can use the CanCraft hook to check when a player is crafting.
Then you can use the `Storage` of the `Crafter` to ge the `Inventory` class. When you have that, you can loop over all inventory items and see if the inventory slots are full or not.Here is a little example, it's not tested so not sure if it works:
object CanCraft(Crafter crafter, PlayerSession session, ICraftable recipe, int count) { Inventory inv = crafter.Storage; for (int i = 0; i < inv.Capacity; i++) { ItemObject slot = inv.GetSlot(i); //TODO: Check if slot is null (meaning it's empty) and cancel the craft. } return null; }
I tried your code to get the item slot work, but I wrote a judgment. In any case, it will return that the slot is not empty. Do I need to store the ItemObject obtained in the slot into the new list to determine ? My logic is poor, I don't understand. .
The easiest way would be checking if there is at least one slot empty. If there isn't, block the crafting and show a message.
That way it will block the items dropping on the ground.
MrBlue
The easiest way would be checking if there is at least one slot empty. If there isn't, block the crafting and show a message.
That way it will block the items dropping on the ground.
Yes, it will check, but after I add the judgment, it will only judge whether the first slot is empty. I wo n’t judge other slots, what can I do
The number of workbench slots is the same. I have judged that all the workbench slots are now working, but the player slots are not fixed. Do you have any ideas?
MrBlue
The easiest way would be checking if there is at least one slot empty. If there isn't, block the crafting and show a message.
That way it will block the items dropping on the ground.
Thanks, now it works perfectly