Determining if article slot in the workbench is full?Solved
There are some malicious players who harm the world. They build buildings in the air and fill them with items to make arrow boards, slabs, and other items. When the slot is full, the produced items will drop the load on the server, and the server delay will be very high. The server lost the link and other issues. I referred to Hurtworld Hooks and only learned to write judgments when making items, but my English was too poor. I couldn't find one to determine whether the item slot was full. I wanted to stop these malicious players from making cards for the server pause.

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;
}
5e128e49266ae.png 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. .

slot 0 Not null
slot 1 Not null
slot 2 Not null
slot 3 null
slot 4 Not null
slot 5 Not null
slot 6 Not null

this return empty

slot 0 Not null
slot 1 Not null
slot 2 Not null
slot 3 Not null
slot 4 Not null
slot 5 Not null
slot 6 Not null

this return empty

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.

5e128e49266ae.png 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?

5e128e49266ae.png 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

Locked automatically