Forum rules - please read before posting.

Need help with splitting items feature

I've been playing around with the scripting side of inventory, items and containers. And I realized that when you drag an item to the container, it has all the core features but I would like to implement a splitting item feature.

So lets say I open a Container with its own items. I click on an stackable item(has 5 stacks) in the container. so now its selected and I move over to one of the slots in my inventory, while I still have the item selected and hovering over the inventory slot(blank spot or where the same stackable item is) I want to be able to hold a key (lets say left shift) and then left click on the slot and it would drop 1 from the total stack to that slot.

I hope this is clear. But basically I want to be able to split items because when you use containers etc, it would be nice to have that ability so that you can for example store half of the items stack somewhere else for safe keeping while you have the rest in your inventory.

I would imagine you would need data for currently dragged item, which slot and inventory/container you are hovering over, and then decrementing by 1 from the total stacks that you have selected.

I tried experimenting the splitting in inventory itself but I'm already stuck and this is where I am at now:

            if (InvInstance.IsValid(KickStarter.runtimeInventory.LastSelectedInstance) && Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Mouse0))
            {
                InvItem item = KickStarter.runtimeInventory.SelectedItem;

                //??? How to retrieve the index of inventory slot you are hovering over
                int invenIndexToDrop; 

                KickStarter.runtimeInventory.PlayerInvCollection.Insert(new InvInstance(item, 1),0);//drops at index 0 but I need to replace it with the slot I am hovering over
            }

Comments

  • edited February 2022

    I'm sure Chris can give you proper advice here, but a while ago I wrote a custom script to handle my player inventory and other containers (which I use by changing the menu's inventory box type to "custom script"). It doesn't behave exactly the way you want yours to, but it does allow you to retrieve/deposit items one by one rather than the whole stack. I'll post it here, hopefully my implementation will give you a head-start:

    using AC;
    using UnityEngine;
    
    public class CustomInventories : MonoBehaviour
    {
    
        private void OnEnable() { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable() { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        private void OnMenuElementClick(Menu menu, MenuElement element, int slot, int buttonPressed)
        {
    
    
            MenuInventoryBox inventoryBox = element as MenuInventoryBox;
            InvInstance clickedInstance = inventoryBox.GetInstance(slot);
            InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
            InvCollection collectionClicked;
            InvCollection collectionSelected;
    
            if (inventoryBox != null && inventoryBox.inventoryBoxType == AC_InventoryBoxType.CustomScript)
            {
    
    
                // Click on an occupied slot while holding another item
                if (InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                {
                    collectionClicked = clickedInstance.GetSource();
                    collectionSelected = selectedInstance.GetSource();
    
                    // Swap items if the selected item came from a different collection (if multiple can be carried, add to stack)
                    if (collectionClicked != collectionSelected)
                    {
    
                        // Do nothing when items are the same and multiples are not allowed
                        if (!clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount < 2 && selectedInstance.ItemID == clickedInstance.ItemID)
                        {
                            KickStarter.runtimeInventory.SetNull();
                            return;
                        }
    
                        collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                        KickStarter.runtimeInventory.SetNull();
                        return;
                    }
                    // Combine items if they both come from the same collection
                    else
                    {
                        // Dealing with stackable items
                        if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1 && selectedInstance.ItemID == clickedInstance.ItemID)
                        {
                            // Merge stacks
                            if (buttonPressed == 1)
                            {
                               collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                               KickStarter.runtimeInventory.SetNull();
                                return;
                            }
                            // Take one from stack
                            if (buttonPressed == 2)
                            {
                                KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                return;
                            }
                        }
                        selectedInstance.Combine(clickedInstance, false);                    
                        return;
                    }
                }
    
                // Place item in free slot
                if (!InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                {
    
                    InvCollection collection = (inventoryBox.title == "Container") ? inventoryBox.OverrideContainer.InvCollection : KickStarter.runtimeInventory.PlayerInvCollection;
    
                    collection.Insert(KickStarter.runtimeInventory.SelectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                    KickStarter.runtimeInventory.SetNull();
                    return;
                }
    
                // Click on an item without holding anything
                if (InvInstance.IsValid(clickedInstance) && !InvInstance.IsValid(selectedInstance))
                {
    
                    // Dealing with stackable items
                    if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1)
                    {
                        // Take all by left clicking
                        if (buttonPressed == 1)
                        {
                            int count = clickedInstance.Count;
                            while (count > 0)
                            {
                                KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                count--;
                            }                        
                        }
                        // Take one from stack by right clicking
                        if (buttonPressed == 2)
                        {
                            KickStarter.runtimeInventory.SelectItem(clickedInstance);                        
                        }
                        return;
                    }
    
                    // Take item by left clicking
                    if (buttonPressed == 1)
                    {
                        KickStarter.runtimeInventory.SelectItem(clickedInstance);
                        return;
                    }
                    // Use action by right clicking
                    if (buttonPressed == 2)
                    {
                        clickedInstance.Use();
                        return;
                    }
    
    
    
                }
    
    
    
            }
    
    
    
        }
    }
    
  • I might as well share the other script I use to handle the Hotspot labels for moving the inventory/container items around. Do notice that I'm using component variables for the strings so that they can be localised to different languages later, but I left comments to show the content of the variables:

  • using UnityEngine;
    using AC;
    
    public class CustomContainerHotspot : MonoBehaviour
    {
    
        private void OnEnable() { EventManager.OnRequestMenuElementHotspotLabel += OnRequestMenuElementHotspotLabel; }
        private void OnDisable() { EventManager.OnRequestMenuElementHotspotLabel -= OnRequestMenuElementHotspotLabel; }
    
        private string OnRequestMenuElementHotspotLabel(Menu _menu, MenuElement _element, int _slot, int _language)
        {
            MenuInventoryBox menuInventoryBox = _element as MenuInventoryBox;
            InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
    
    
            if (menuInventoryBox != null && menuInventoryBox.inventoryBoxType == AC_InventoryBoxType.CustomScript)
            {
                InvInstance containerInstance = menuInventoryBox.GetInstance(_slot);
    
                // if selected item comes from container
                if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance) && KickStarter.runtimeInventory.SelectedInstance.GetSource() != KickStarter.runtimeInventory.PlayerInvCollection)
                {
    
                    // if target slot is in a container
                    if (InvInstance.IsValid(containerInstance) && menuInventoryBox.title == "Container")
                    {
    
                        // Hide interaction on self in same slot
                        if (selectedInstance == containerInstance)
                        {
                            // Unless it's stackable
                            if (selectedInstance.TransferCount != selectedInstance.Count && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                            {
                                return "[compvar:21138500:0]"; // Add to stack
                            }
                            else
                            {
                                return " ";                            
                            }
    
                        }
    
                        // if item is stackable
                        if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                        {
                            return "[compvar:21138500:0]"; // Add to stack
                        }
    
                    }
    
                    // if target slot is in inventory
                    if (InvInstance.IsValid(containerInstance) && menuInventoryBox.title == "InventoryBox")
                    {
                        // if item are the same and stackable
                        if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                        {
                            return "[compvar:21138500:0]"; // Add to stack
                        }
                        // if item are the same but not stackable
                        else if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.TransferCount == selectedInstance.Count)
                        {
                            // return " ";
                            return "[compvar:21138500:1]"; // Swap items // Actually, let's pretend it's a swap even though it isn't
                        }
                        // if items are different
                        else if (selectedInstance.ItemID != containerInstance.ItemID)
                        {
                            if (selectedInstance.TransferCount != selectedInstance.Count)
                            {
                                return " ";
                            }
                            return "[compvar:21138500:1]"; // Swap items
                        }
                        else
                        {
                            return " ";
                        }
    
                    }
    
                }
    
                // if selected item comes from inventory
                if (InvInstance.IsValid(KickStarter.runtimeInventory.SelectedInstance) && KickStarter.runtimeInventory.SelectedInstance.GetSource() == KickStarter.runtimeInventory.PlayerInvCollection)
                {
    
                    // if target slot is in a container
                    if (InvInstance.IsValid(containerInstance) && menuInventoryBox.title == "Container")
                    {
    
                        // if item are the same and stackable
                        if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                        {
                            return "[compvar:21138500:0]"; // Add to stack
                        }
                        // if item are the same but not stackable
                        else if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.TransferCount == selectedInstance.Count)
                        {
                            // return " ";
                            return "[compvar:21138500:1]"; // Swap items // Actually, let's pretend it's a swap even though it isn't
                        }
                        // if items are different
                        else if (selectedInstance.ItemID != containerInstance.ItemID)
                        {
    
                            if (selectedInstance.TransferCount != selectedInstance.Count)
                            {
                                return " ";
                            }
    
                            return "[compvar:21138500:1]"; // Swap items
                        }
                        else
                        {
                            return " ";
                        }
                    }
    
                    // if target slot is in inventory
                    if (InvInstance.IsValid(containerInstance) && menuInventoryBox.title == "InventoryBox")
                    {
    
                        // Hide interaction on self in same slot
                        if (selectedInstance == containerInstance)
                        {
                            // Unless it's stackable
                            if (selectedInstance.TransferCount != selectedInstance.Count && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                            {
                                return "[compvar:21138500:0]"; // Add to stack
                            }
                            else
                            {
                                return " ";
                            }
    
                        }
    
                        // if item is stackable
                        if (selectedInstance.ItemID == containerInstance.ItemID && selectedInstance.InvItem.canCarryMultiple && selectedInstance.InvItem.maxCount > 1 && containerInstance.InvItem.maxCount > containerInstance.Count)
                        {
                            return "[compvar:21138500:0]"; // Add to stack
                        }
                    }
    
                }
    
                return string.Empty;
    
            }
    
            return string.Empty;
    
        }
    }
    
  • @Rairun I appreciate it, and I will give your method a try and see if I can build on top of it

  • edited February 2022

    @Rairun oh and I also just wanted some clarification on where the script you have given "CustomInventories" would go or be attached to. Sorry I'm still quite new and learning AC. Like how exactly does that script get used.

    What I did was I went to Menu > Inventory > InventoryBox and then I set the inventory box type to Custom Script .

    And I simply attached the CustomInventories script to my Player object. Am I doing this correctly? do I need to attach that script to all objects that have the container script?

  • do I need to attach that script to all objects that have the container script?

    @Rairun's script reference Containers via the menu elements that display them, so only one instances is necessary as it's not specific to any one Container.

    It's worth mentioning that AC does have the ability to move items one-at-a-time when transferring from the Inventory to a Container - though the exact behaviour may not be what you're looking for.

    If an item's Slot capacity is greater than one, then the Selection mode property becomes visible. This determines the behaviour when clicking an item (to select it) when multiple instances of that item exist in that slot. Setting this to Stack will transfer an additional instance of the item to the cursor each time it's clicked.

    On the scripting side of things, AC provides a dedicated property to handle how many instances of a given item stack are to be selected/transferred, by way of the InvInstance class's TransferCount. Calling the CreateTransferInstance function after doing so creates a new InvInstance class with this amount, leaving the original instance reduced by the same amount.

    To update your code snippet, something more along these lines should do it:

    InvInstance invInstance = KickStarter.runtimeInventory.LastSelectedInstance;
    
    if (InvInstance.IsValid (invInstance) && Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Mouse0))
    {
        int currentAmount = invInstance.Count;
        int transferAmount = currentAmount / 2;
    
        invInstance.TransferCount = transferAmount;
        InvInstance transferInstance = invInstance.CreateTransferInstance ();
    
        KickStarter.runtimeInventory.PlayerInvCollection.AddToEnd (transferInstance);
    }
    
  • edited February 2022

    @ChrisIceBox Ohhh I feel so stupid, just before you commented, I noticed that in the Inventory tab, clicking on a stackable item, it has the the option for Selection Mode. I mean its not exactly the way I wanted but I thought it literally only had the option to move the stack as whole only.

    Thank you for the script clarification as well.

    Also the OnMenuElementClick() takes in buttonPressed as parameter as int type, I wanted to know if theres a way to use Input.GetKeyDown(KeyCode.LeftShift) instead of an integer and how can I even know which int value reflects which button it is. For example is 3 = middle mouse?

    I can see that buttonPressed = 1 is left click and 2 = right click. But what int value is left shift for example. Does the documentation show which int value represents which button/key pressed? Sorry just a little confused about that parameter

  • The buttonPressed parameter refers to the click state of the mouse - or its keyboard equivalent. 1 = left click / InteractionA, 2 = right click / InteractionB.

    If you're looking to have left-shift be an additional input requirement (so e.g. left click + left shift is required), then you can just have your Input.GetKeyDown check inside the event.

    If you're looking to only rely on left-shift, it might have to instead be a case of checking for this inside a regular Update function and then check if the mouse is currently over your intended element. This can be done by reading the value of PlayerMenu's MouseOverMenuElement property:

    if (Input.GetKeyDown (KeyCode.LeftShift) && KickStarter.playerMenus.MouseOverMenuElement != null && KickStarter.playerMenus.MouseOverMenuElement.title == "MyInventoryBoxElement")
    {
        //
    }
    
  • @ChrisIceBox Thanks chris, I currently have my custom inventory script set like this thanks to Rairun and yourself.

    public class CustomInventory : MonoBehaviour
    {
        private void OnEnable() { EventManager.OnMenuElementClick += OnMenuElementClick; }
        private void OnDisable() { EventManager.OnMenuElementClick -= OnMenuElementClick; }
    
        private void OnMenuElementClick(Menu menu, MenuElement element, int slot, int buttonPressed)
        {
    
            MenuInventoryBox inventoryBox = element as MenuInventoryBox;
            InvInstance clickedInstance = inventoryBox.GetInstance(slot);
            InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
            InvCollection collectionClicked;
            InvCollection collectionSelected;
    
    
    
            if (inventoryBox != null && inventoryBox.inventoryBoxType == AC_InventoryBoxType.CustomScript)
            {
    
                // Click on an occupied slot while holding another item
                if (InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                {
                    collectionClicked = clickedInstance.GetSource();
                    collectionSelected = selectedInstance.GetSource();
    
                    // Swap items if the selected item came from a different collection (if multiple can be carried, add to stack)
                    if (collectionClicked != collectionSelected)
                    {
    
                        // Do nothing when items are the same and multiples are not allowed
                        if (!clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount < 2 && selectedInstance.ItemID == clickedInstance.ItemID)
                        {
                            KickStarter.runtimeInventory.SetNull();
                            return;
                        }
    
                        collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                        KickStarter.runtimeInventory.SetNull();
                        return;
                    }
                    // Combine items if they both come from the same collection
                    else
                    {
                        // Dealing with stackable items
                        if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1 && selectedInstance.ItemID == clickedInstance.ItemID)
                        {
                            // Merge stacks
                            if (buttonPressed == 1)
                            {
                                collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                                KickStarter.runtimeInventory.SetNull();
                                return;
                            }
                            // Take one from stack
                            if (buttonPressed == 2)
                            {
                                KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                return;
                            }
                        }
                        selectedInstance.Combine(clickedInstance, false);
                        return;
                    }
                }
    
                // Place item in free slot
                if (!InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                {
    
                    InvCollection collection = (inventoryBox.title == "Container") ? inventoryBox.OverrideContainer.InvCollection : KickStarter.runtimeInventory.PlayerInvCollection;
    
                    collection.Insert(KickStarter.runtimeInventory.SelectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                    KickStarter.runtimeInventory.SetNull();
                    return;
                }
    
                // Click on an item without holding anything
                if (InvInstance.IsValid(clickedInstance) && !InvInstance.IsValid(selectedInstance))
                {
    
    
                    // Dealing with stackable items
                    if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1)
                    {
                        // Take all by left clicking
                        if (buttonPressed == 1)
                        {
                            Debug.Log("Take all by left clicking");
                            int count = clickedInstance.Count;
                            while (count > 0)
                            {
                                KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                count--;
                            }
                            return;
                        }
    
                        // Take one from stack by right clicking
                        if (Input.GetKey(KeyCode.LeftShift) && buttonPressed == 2)
                        {
                            Debug.Log("Take one by right clicking");
                            KickStarter.runtimeInventory.SelectItem(clickedInstance);
                            return;
                        }
    
                    }
    
                    // Use action by right clicking
                    if (buttonPressed == 2)
                    {
                        Debug.Log("Use action by right click");
    
                        //These two lines are so that the actionlist for Inventory > Check selected action is able to work
                        //when it comes to checking item category for that item. Since it requires to know the selected item data we need to select
                        //the clickedinstance and then deselect it because we don't want to be holding that item and then it will finally use the item
                        KickStarter.runtimeInventory.SelectItem(clickedInstance);
                        KickStarter.runtimeInventory.SelectedInstance.Deselect();
    
                        clickedInstance.Use();
                        return;
                    }
    
                }
    
            }
        } 
    }
    

    So when I have the inventory open, I can right click to use item, hold Left shift + right click to select item one by one from a stack, and left click will select All the item stack as whole.

    So the inventory part is okay and before I implement the splitting items feature, I noticed that after setting the Container > ContainerItems's Inventory Box Type: To Custom script.

    With the current script, when I add items to my inventory, the container also gets the items so its like a mirror/duplicate effect and I would like the container to be its own separate collection. But same controls as the inventory.

    If I set the Container > ContainerItems's Inventory Box Type: to the default Container mode then it fixes the mirror issue however the controls also return to its default state so left click would grab the item one by one when it should grab it as whole, right click deselects if you are holding a selected item or does nothing when if you are not selecting or holding any item.

    So basically I'm looking to get the same inventory control for the container as the custom inventory script.

  • There's a couple of ways you can customise behaviour with a Container.

    The first is to leave Inventory box type as Container, and then set the Click behaviour property below to Custom Script. This combination causes it to automatically sync itself with the active Container, but still allow for behaviour controlled through the OnMenuElementClick event.

    The second is to set Inventory box type to Custom Script, and then manually assign the active Container to the element when the menu turns on. This can be done by hooking into the OnMenuTurnOn event. Which Container you assign can be set through script, but the "active" one set by the Container: Open Action can be retrieved from the PlayerInput script:

    private void OnEnable () { EventManager.OnMenuTurnOn += OnMenuTurnOn; }
    private void OnDisable () { EventManager.OnMenuTurnOn -= OnMenuTurnOn; }
    
    private void OnMenuTurnOn (AC.Menu menu, bool isInstant)
    {
        if (menu.title != "Container")
        {
            return;
        }
    
        MenuInventoryBox containerElement = menu.GetElementWithName ("ContainerItems") as MenuInventoryBox;
        containerElement.OverrideContainer = KickStarter.playerInput.activeContainer;
    }
    

    If you need your current code to adapt based on whether its dealing with the Inventory or a Container being clicked, you can read the inventoryBox variable's title property, i.e.:

    if (inventoryBox.title == "ContainerItems")
    {
        // Run this for Container
    }
    else
    {
        // Run this for regular Inventory
    }
    
  • ^ I haven't tried this, but if by any chance the first script doesn't work, about a year ago Chris provided me with an alternate way to set OverrideContainer: https://www.adventurecreator.org/forum/discussion/comment/41879/#Comment_41879

  • edited February 2022

    @ChrisIceBox Thanks, I was pulling my hair out on this issue lol. I went with your second method. I do have a teeny visual bug that I need help on.

    So I open the inventory, Add 6 candies into my inventory. Then I open a Container that should have 3 candies, but right when you open the container, you see the candy stack number as the same to the candy in the inventory so it would show as 6 candies but right after I click in an empty area(whether its inventory or container) then it refreshes and shows the actual 3 candies.

    Heres some screenshot to demonstrate:
    Step 1: Inventory has 6 items

    Step 2 : Open Container to see the visual bug

    Step 3: Clicking in either inventory or container empty areas refreshes it

    Closing and opening the AC container also fixes the visual bug.

  • @ChrisIceBox and this is my final script based on your second method:

    public class CustomInventory : MonoBehaviour
    {
        private void OnEnable() {
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuElementClick += OnMenuElementClick;
    
        }
        private void OnDisable() {
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuElementClick -= OnMenuElementClick;
    
        }
    
    
        private void OnMenuTurnOn(AC.Menu menu, bool isInstant)
        {
            if (menu.title != "Container")
            {
                return;
            }
    
            MenuInventoryBox containerElement = menu.GetElementWithName("ContainerItems") as MenuInventoryBox;
            containerElement.OverrideContainer = KickStarter.playerInput.activeContainer;
        }
    
        private void OnMenuElementClick(Menu menu, MenuElement element, int slot, int buttonPressed)
            {
    
                MenuInventoryBox inventoryBox = element as MenuInventoryBox;
                InvInstance clickedInstance = inventoryBox.GetInstance(slot);
                InvInstance selectedInstance = KickStarter.runtimeInventory.SelectedInstance;
                InvCollection collectionClicked;
                InvCollection collectionSelected;
    
                if (inventoryBox != null && inventoryBox.inventoryBoxType == AC_InventoryBoxType.CustomScript)
                {
    
                    // Click on an occupied slot while holding another item
                    if (InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                    {
                        collectionClicked = clickedInstance.GetSource();
                        collectionSelected = selectedInstance.GetSource();
    
                        // Swap items if the selected item came from a different collection (if multiple can be carried, add to stack)
                        if (collectionClicked != collectionSelected)
                        {
    
                            // Do nothing when items are the same and multiples are not allowed
                            if (!clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount < 2 && selectedInstance.ItemID == clickedInstance.ItemID)
                            {
                                KickStarter.runtimeInventory.SetNull();
                                return;
                            }
    
                            collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                            KickStarter.runtimeInventory.SetNull();
                            return;
                        }
                        // Combine items if they both come from the same collection
                        else
                        {
                            // Dealing with stackable items
                            if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1 && selectedInstance.ItemID == clickedInstance.ItemID)
                            {
                                // Merge stacks
                                if (buttonPressed == 1)
                                {
                                    collectionClicked.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                                    KickStarter.runtimeInventory.SetNull();
                                    return;
                                }
                                // Take one from stack
                                if (buttonPressed == 2)
                                {
                                    KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                    return;
                                }
                            }
                            selectedInstance.Combine(clickedInstance, false);
                            return;
                        }
                    }
    
                    // Place item in free slot
                    if (!InvInstance.IsValid(clickedInstance) && InvInstance.IsValid(selectedInstance))
                    {
    
                        InvCollection collection = (inventoryBox.title == "ContainerItems") ? inventoryBox.OverrideContainer.InvCollection : KickStarter.runtimeInventory.PlayerInvCollection;
    
                        collection.Insert(selectedInstance, slot, OccupiedSlotBehaviour.SwapItems);
                        KickStarter.runtimeInventory.SetNull();
                        return;
                    }
    
                    // Click on an item without holding anything
                    if (InvInstance.IsValid(clickedInstance) && !InvInstance.IsValid(selectedInstance))
                    {
    
    
                        // Dealing with stackable items
                        if (clickedInstance.InvItem.canCarryMultiple && clickedInstance.InvItem.maxCount > 1)
                        {
                            // Take all by left clicking
                            if (buttonPressed == 1)
                            {
                                Debug.Log("Take all by left clicking");
                                int count = clickedInstance.Count;
                                while (count > 0)
                                {
                                    KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                    count--;
                                }
                                return;
                            }
    
                            // Take one from stack by right clicking
                            if (Input.GetKey(KeyCode.LeftShift) && buttonPressed == 2)
                            {
                                Debug.Log("Take one by right clicking");
                                KickStarter.runtimeInventory.SelectItem(clickedInstance);
                                return;
                            }
    
                        }
    
                        // Use action by right clicking
                    if (buttonPressed == 2)
                    {
                        if (inventoryBox.title == "ContainerItems")
                        {
                            Debug.Log("Not allowing to use item in container");
                            return;
                        }
    
                        Debug.Log("Use action by right click");
    
                        //These two lines are so that the actionlist for Inventory > Check selected action is able to work
                        //when it comes to checking item category for that item. Since it requires to know the selected item data we need to select
                        //the clickedinstance and then deselect it because we don't want to be holding that item and then it will finally use the item
                        KickStarter.runtimeInventory.SelectItem(clickedInstance);
                        KickStarter.runtimeInventory.SelectedInstance.Deselect();
    
                        clickedInstance.Use();
                        return;
                    }
    
                    }
    
                }
    
            }
    
    }
    
  • It might just be a case of having to call the Menu's Recalculate function after assigning the override Container, which updates the display of elements inside it.

    Try adding this to the end of the OnMenuTurnOn function:

    menu.Recalculate ();
    
  • edited February 2022

    @ChrisIceBox That did it, ill have to remember that line of code when I work with menus :D . Thank you for all your help. And apologies if I may have taken too much of your time.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.