Set equipable Item Attribute

cepoimario

New member
Hello Team,

I am am trying to set an equipable item attribute in the slot that i created however i can't seems to find the correct method.

Currently i am able to modify the values from the the main gird inventory using the following but this does not seem to apply elsewhere besides the main grid
,the "Current Stack Size" attribute is getting its value from my system and updated every from for now
C#:
void Update()
    {
        var container = inventory.GetContainerWithName("AmmoPouch"); //This var is from my system
        
        for (int i = 0; i < container.Count; i++)
        {
            var ss =container[i].Item.Data.itemInfo.Item.ID;
                var item = InventorySystemManager.GetItem(container[i].Item.Data.itemInfo.Item.ID);
                Debug.Log(item);
                item.GetAttribute<Attribute<int>>("Current Stack Size").SetOverrideValue(container[i].Item.CurrentStackSize);
            }
            
        }
    }

Further more i would like the equipped item to be removed when the "Current Stack Size" attribute is = 0 but again can't find the correct way to do so .
1609720099851.png


Thanks in advance
 
I think you are slightly confused on how item stacks work.

Items are stored in the inventory within Item Collections. An Item Collection is a list of Item Stacks (int, item). The Item Stack is what defines the amount of item you have. So when you add 2 apple, you have 2 apple. If you add 3 more apples you have 5 apples. This is all automatic, you do not have to do it manually using attributes.

You are trying to use attributes to define the stack amount, that is wrong. The attributes are used for defining values specific to that item for example "Attack", or "Description".

I would recommend you read the entire Getting Started section of the documentation again, Especially Terminology: https://opsive.com/support/documentation/ultimate-inventory-system/getting-started/

Make sure you understand the differences between Mutable/Immutable & Common/Unique Items, read about it in the documentation. Only Mutable items can change attribute values at runtime.

I hope that helps guide you in the correct path
 
Thank you very much for your answer , to put this in to perspective i currently have my own rudimentary inventory system that also contains a container of dictionnaires that whole game is dependent on that main system and would like to keep it that way , the item stacking would only partially work as in my case , for instance i have a magazine item that can contain 30 bullets and would like to have stacks of magazines containing x amount of bullets. i have managed to setup an item definition for my magazine and added an item attribute of bullet amount . right now when equipping the magazine in the ultimate inventory system i will also equip it in my system and assign the proper bullet amount from the item attribute .
C#:
 var container = inventory.GetContainerWithName("AmmoPouch"); // My Inventory System Container
        
        for (int i = 0; i < container.Count; i++)
        {
            if (container[i].Item != null)
            {
                var ss =container[i].Item.Data.itemInfo.Item.ID; //The Item Data From My Inventory Contains An ItemInfo Data That is Assigned When Equiping The Itemp
                var item = InventorySystemManager.GetItem(container[i].Item.Data.itemInfo.Item.ID); // I Will Then Search For That Specific Item In The Ultimate Inventory System
                item.GetAttribute<Attribute<int>>("Bullet Amount").SetOverrideValue(container[i].Item.CurrentStackSize);// And Set The Current Bullet Amount To Match My System Once Equiped to Allow It to Update In the Ultimate Inventory System When I Unequip It In Case Some Bullet Were Used   
                Debug.Log(item.GetAttribute<Attribute<int>>("Bullet Amount").GetValue() + "Grid");
            }
              
            }
            
        }

This is almost working however the visual values in the Ultimate Inventory System Will Only Update When i Equip /Unequip the item .

Kindly let me me know what function is triggered when updating the visual elements in my case an ItemView Module of IntAttributeItemView ,as i wasn't able to find it yet.
 
Ah I see.
I assume you are have your ItemView within an Item View Slot Container (example InventoryGrid or ItemHotbar)?

if that's the case simply calling the draw function should do the trick.
Code:
itemViewSlotContainer.Draw();

if you do not have a reference to the itemViewSlotContainer, and you want to force the draw directly from the inventory you might be able to.
Most of the times ItemViewSlotContainers have a "Draw On Inventory Update" function.
1609836532368.png
You just have to execute the Inventory Update event, you can do so from anywhere in the code.
Code:
EventHandler.ExecuteEvent(inventory, EventNames.c_Inventory_OnUpdate);

I hope this helps
 
Top