Hotbar attribute modification

Chris

New member
Hi,

I would like to override the value of an attribute when another item is assigned in its place in the shortcut bar.

1. When I am in inventory and click on Assign. My holster attribute changes
2. When I replace an assigned item. My case attribute changes or reverts to its default value.

I tried adding the following code to the AssignHotbarItemAction script but it failed:


[CODE = csharp] protected override void InvokeActionInternal (ItemInfo itemInfo, ItemUser itemUser)
{
var item = itemInfo.Item;
var holsterAttribute = item.GetAttribute <Attribut <Transform>> ("Holster");
if (holsterAttribute! = null)
{
holsterAttribute.SetOverrideValue (m_HolsterDefault);
}
if (m_AsyncFuncActions.Count <m_ItemHotbar.SlotCount) {

for (int i = m_AsyncFuncActions.Count; i <m_ItemHotbar.SlotCount; i ++) {
var localIndex = i;
m_AsyncFuncActions.Add (new AsyncFuncAction <int> ((localIndex + 1) .ToString (), () => localIndex));
}
} else if (m_AsyncFuncActions.Count> m_ItemHotbar.SlotCount) {
m_AsyncFuncActions.Trim (m_ItemHotbar.SlotCount);
}

base.InvokeActionInternal (itemInfo, itemUser);
}[/CODE]


and

C#:
 protected override bool CanInvokeInternal(ItemInfo itemInfo, ItemUser itemUser)
        {

            if (itemUser is IItemHotbarOwner itemHotbarOwner) {
                m_ItemHotbar = itemHotbarOwner.ItemHotbar;
            } else {
                m_ItemHotbar = itemUser.gameObject.GetComponent<IItemHotbarOwner>()?.ItemHotbar;
            }

            var item = itemInfo.Item;
            var holsterAttribute = item.GetAttribute <Attribut <Transform>> ("Holster");
            if (holsterAttribute! = null)
            {
                holsterAttribute.SetOverrideValue (m_Holster);
            }
            return m_ItemHotbar! = null
                   && itemInfo.ItemCollection.HasItem ((1, élément));

        }

Capture.PNG

Capture.PNG

Thanks in advance for the help
 
Hi Chris,

I'm not completely sure I understand what you are trying to achieve.

Looking through the code it seems you are setting the value of Holster in two places, in canInvoke and Invoke.

If I'm not mistaken what is happening is that CanInvoke first first setting the Holster to m_Holster and then Invoke gets fired and you reset the value to the default. So essentially you revert the change before you can see it happen.

My guess is that you should be doing the setOverride only in the Invoke function not the CanInvoke. And the item you want to reset the holster value from is actually the item that is already assigned in the slot you are about to assign the new item to.

Something around those lines?
Code:
//pseudo code, not working code

item.GetAttribute("Holster").SetOverrideValue(m_Holster)

var itemInSlot = hotbar.GetItemInSlot(index)

if(itemInSlot != null){
    itemInSlot.GetAttribute("Holster").setOverrdValie(m_Default)
}

SetItemToSlot(item)

Let me know if I'm completely off topic.

Note: CanInvoke is called before you click on the ItemAction when you open the ItemActionPanel to enable/disable the buttons depending of whether or not they can be invoked.
 
Hi Sangemdoko,

Thanks for quick feedback.

you understood well.

This is exactly what I want to do.

But I can't get the index of the item with:

C#:
var itemInSlot = hotbar.GetItemInSlot(index)


I tried :

C#:
var itemInSlot = m_ItemHotbar.GetComponentInChildren<ItemInfo>().Item;
            
    if (itemInSlot != null)           
    {
        itemInSlot.GetAttribute<Attribute<Transform>>("Holster").SetOverrideValue(m_HolsterDefault);

    }

The first part is now working :)
 
Oh... well that's a big oversight from me. There's no way to get an item from the item hotbar. I've been so focused on v1.1 which has all the new cool features that I didn't realise v1.0.X didn't have a function for that.

Add this in the ItemHotbar script:

C#:
        /// <summary>
        /// Get an item from the slot.
        /// </summary>
        /// <param name="slot">The item slot.</param>
        public virtual ItemInfo GetItemInSlot(int slot)
        {
            return m_ItemHotbarSlots[slot].ItemInfo;
        }
It'll be added in the next patch. If there are other usefull functions that are missing make sure to let me know and I'll add them
 
Great

Is it possible to equip and unequip an item when clicking on assign in the inventory?

The item would be both add to the hotbar and equipped
 
Yes of course, simply use the same code as in the equip item action.
Since your in the integration category I'm guessing you are using the UCC/UIS integration:
Code:
EventHandler.ExecuteEvent<ItemInfo, bool>(itemInfo.Inventory.gameObject, "OnItemActionEquipUnequip", itemInfo, m_Equip);
 
I tried.
The change of equipment works but not the assignment

C#:
/// <summary>
    /// Item action used to Move an item from one collection to another. It can be used to equip/unequip items too.
    /// </summary>
    [System.Serializable]
    public class AssignEquipUnequipItemAction : ItemActionWithAsyncFuncActionPanel<int>
    {
        [Tooltip("The name that should be displayed when the item can be equipped.")]
        [SerializeField] protected string m_EquipActionName = "Equip";
        [Tooltip("The name that should be displayed when the item can be unequipped.")]
        [SerializeField] protected string m_UnequipActionName = "Unequip";

        protected ItemHotbar m_ItemHotbar;

        private bool m_Equip;
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        public AssignEquipUnequipItemAction()
        {
            m_Name = "Equip";
        }

        /// <summary>
        /// Returns true if the item action be invoked.
        /// </summary>
        /// <param name="itemInfo">The item.</param>
        /// <param name="itemUser">The inventory user.</param>
        /// <returns>True if it can be invoked.</returns>
        protected override bool CanInvokeInternal(ItemInfo itemInfo, ItemUser itemUser)
        {
            var characterLocomotion = itemUser.gameObject.GetCachedComponent<UltimateCharacterLocomotion>();
            if (characterLocomotion != null && !characterLocomotion.Alive) {
                return false;
            }

            if (itemUser is IItemHotbarOwner itemHotbarOwner)
            {
                m_ItemHotbar = itemHotbarOwner.ItemHotbar;
            }
            else
            {
                m_ItemHotbar = itemUser.gameObject.GetComponent<IItemHotbarOwner>()?.ItemHotbar;
            }

            var item = itemInfo.Item;

            var attribute = item.GetAttribute<Attribute<bool>>(UltimateInventorySystemBridge.EquippedAttributeName);
            if (attribute != null && attribute.OverrideValue) {
                m_Equip = false;
                m_Name = m_UnequipActionName;
            } else {
                m_Equip = true;
                m_Name = m_EquipActionName;
            }

            return m_ItemHotbar != null
                   && itemInfo.ItemCollection.HasItem((1, item));
        }

        /// <summary>
        /// Move an item from one collection to another.
        /// </summary>
        /// <param name="itemInfo">The item info.</param>
        protected override void InvokeActionInternal(ItemInfo itemInfo, ItemUser itemUser)
        {
            if (m_AsyncFuncActions.Count < m_ItemHotbar.SlotCount)
            {

                for (int i = m_AsyncFuncActions.Count; i < m_ItemHotbar.SlotCount; i++)
                {
                    var localIndex = i;
                    m_AsyncFuncActions.Add(new AsyncFuncAction<int>((localIndex + 1).ToString(), () => localIndex));
                    EventHandler.ExecuteEvent<ItemInfo, bool>(itemInfo.Inventory.gameObject, "OnItemActionEquipUnequip", itemInfo, m_Equip);
                }
            }
            else if (m_AsyncFuncActions.Count > m_ItemHotbar.SlotCount)
            {
                m_AsyncFuncActions.Trim(m_ItemHotbar.SlotCount);
                EventHandler.ExecuteEvent<ItemInfo, bool>(itemInfo.Inventory.gameObject, "OnItemActionEquipUnequip", itemInfo, m_Equip);
            }

            base.InvokeActionInternal(itemInfo, itemUser);
        }

        protected override void InvokeWithAwaitedValue(ItemInfo itemInfo, ItemUser itemUser, int awaitedValue)
        {
            m_ItemHotbar.AssignItemToSlot(itemInfo, awaitedValue);
        }
    }

So for simplicity,

I would like when my guns are in the hotbar. The assigned weapons holster is visible

When the guns are not in the hotbar. The weapon holster is not visible
 
I have found solutions to my problem. But I am unable to update the holster location.

Capture.PNGCapture2.PNG

An idea to force the update?
 
On the Third Person Perspective Item component there is a holster ID. You could use that Id to put the item in the correct place
1601652801116.png
 
I tried with ID and I have the same problem.

If I only provide the ID in the weapon and I have ten weapons in the inventory.

We can see all the weapons attached to the holster
 
I'm not sure I understand what you wish to achieve.

Lets say you have 5 guns in the inventory, you wish to have one in main holster and the rest hidden?
or do you wish to have each gun in a different holster (with some limit, such as first 2-4 weapons)?
 
Justin has confirmed that it is not possible to do this yet. Unfortunately there's no plan to add this functionality any time soon.
If I were you I'd look into a custom solution.
 
Top