Automatically add a tool to hotbar

claudius_I

New member
Hello, i want to add automatically add a tool (when category is tool) to hotbar when i added a new object to inventory only if there is a empy slot in the hotbar.

There is possible to do that? can you guide me?

Thanks

Claudio

Sorry for my bad english.
 
It is not possible out of the box.
But you can write some custom code for it.

When an Item is added in the Inventory an event is triggered:
c_Inventory_OnAdd_ItemInfo_ItemStack

Checkout the examples on this page:

you can get the ItemCategory from the itemInfo. and from there compare with your tools category.
Once you know if the item is a tool, you can find the hotbar, loop through each slot. And once you find an open space you set the item there.
Code:
var isTool = toolCategory.InherentlyContains(itemInfo.Item);
if(isTool){
    // Add to Hotbar.
    uint panelManagerID = 1;
    var panelName = "Hotbar";
    var hotbar = InventorySystemManager.GetItemViewSlotContainer<ItemHotbar>(panelManagerID, panelName);
    for (int i = 0; i < hotbar.SlotCount; i++) {
        if(hotbar.GetItemAt(i).Item != null){ continue; }
        hotbar.AddItem(itemInfo, i);
        break;
    }
}

I hope that helps
 
Top