Forum rules - please read before posting.

Manage inventory menu with keyboard

Hello,

I set up my game with Direct input with keyboard only and hotspot detection method with player vicinity nearest only. I am struggling currently with inventory.

1) My inventory can navigate with keyboard and can click with 'InteractionA' button. I want inventory items interact with hotspots, for example, when the player is proximity to a hotspot, press 'InteractionA ' the specific items from inventory, it executes Inventory interactions of the hotspot. I have seen the tutorial but it is only for Point and Click, I don't know how I do with direct method and keyboard.

2) When I press item from inventory, that item appears in the center of the screen when I exit inventory. How do I delete or hide it?

3) How do I can combine two items in my case? I know that I have to use Combine interactions section, what I don't know is that since my method is Direct, how can I select one item and then the other to combine it.

Regards,
Lrei

Comments

  • edited March 2021

    press 'InteractionA ' the specific items from inventory, it executes Inventory interactions of the hotspot.

    I'm not quite clear of your intent. Do you want a single press of InteractionA to automatically cause an item held by the Player to be used by the Hotspot?

    If so, you can have your Hotspot's "Use" interaction ActionList check if you're carrying a specific item, and then run the appropriate combine Interaction. The "Inventory: Check" Action can be used to determine if you're carring an appropriate item, and - if so - the "ActionList: Run" Action can then be used to run a separate "Use item on Hotspot" Interaction ActionList.

    If you instead want to have a list of available Inventory items appear - and choosing one of them then combines them with the Hotspot - you're going to want to switch your "Interaction method" to "Choose Hotspot Then Interaction", to bring up an Interaction menu to let you choose exactly how the Hotspot is interacted with. This is the same behaviour as used by the 2D Demo.

    When I press item from inventory, that item appears in the center of the screen when I exit inventory. How do I delete or hide it?

    An item will appear at the cursor when it becomes selected. If you want to de-select the item, use the Inventory: Select Action and set the Method to Deselect Active.

    If you want it to remain selected, but not show as an icon, go to the Cursor Manager and set the When inventory selected property from Change Cursor to Change Hotspot Label.

    How do I can combine two items in my case? I know that I have to use Combine interactions section, what I don't know is that since my method is Direct, how can I select one item and then the other to combine it.

    Navigating menus directly doesn't prevent you from selecting items - that's why the item is appearing in the centre of the screen. When an item is selected, using another one will cause the two to be combined.

    How exactly do you wish for the combine mechanics to work? You can create a separate inventory icon that shows the selected inventory in a certain part of your Menu, or rely on Choose Hotspot Then Interaction mode to bring up a list of possible combinations (see above). Custom scripting is also an option, but it does depend on the behaviour you want. If you can share more detail on the mechanics you're looking for (mockups / screenshots would be welcome, if possible), I can try to advise further.

    It's worth noting, also, that the "Combat Example" package over on the Downloads page includes a keyboard-controlled Inventory system. It does make use of custom scripts (to allow for 3D items), but it does allow for item combining, and also demonstrates the use of items on Hotspots.

  • "Choose Hotspot Then Interaction" is not exactly what I want, I only have one type of interaction. The function I want is that when the player is proximity to a hotspot, the player opens the inventory menu, selects an item, then run Inventory interactions of the hotspot, but it can also work if the player is proximity to a hotspot, presses InteractionA, it will run Use interaction without selecting inventory. The latter is already implemented with hotspot detection method with player vicinity nearest only and Hotspot's "Use" interaction. In general, what I mean is that it is the player decides if he wants to use inventory and which item to interact with hotspot or not, there are two different options.

    An example of this is the player is proximity to a door, if he presses InteractionA, it will run interaction with the door's hotspot saying 'I need the key to open it'. When the player gets the key, he approaches the door, if he also presses InteractionA, it will continue to run interaction with dialogue needing the key, but if he opens the inventory, selects the key, it will run the interaction that the door is opened.

    Regarding to the combination of two items, I want that for example the player opens the inventory, if he presses the keyboard C button, not InteractionA, the item is selected, but it doesn't close the inventory, the system detects that it is going to combine two item and waiting for the player to select another item to combine, then the player select another item with the C button and if it can combine those two items, it automatically combines, if it cannot combine, it runs the actionlist saying 'I cannot combine those two items'. Additionally, the player can also deselect the item with the C button.

    I do not know if I have explained that I want to do exactly.

  • Thanks for the clarification.

    It seems you're after the default way of interacting items in Context Sensitive mode - the same interface as used by the 3D Demo. You select an item, and then - while selected - interacting with either a Hotspot or another item results in the two being combined. The only difference being that you're navigating the Menu directly, instead of a mouse. Does that sound right?

    The inventory behaviour is the same regardless of input method - the main difference is that of visual feedback. When an item is selected with the cursor, the cursor (by default) changes to that item's icon, giving you feedback that it's currently selected. This is what you're seeing when you asked earlier about the icon showing up in the centre of the screen.

    When it comes to giving this feedback in a different way, you have a few options - such as highlighting the item in the list, or showing a separate icon in e.g. the corner of the screen. However, it's first important to make sure that the behaviour is correct. The actual feedback / user interface changes are a secondary issue.

    How are you opening/closing the Inventory menu? It should be that an item remains selected after closing it. If the item's appears in the centre of the screen (as it was before), try then using a Hotspot. That should then run the appropriate Inventory/Hotspot interaction.

    Assuming that works, how then do you want to visualise that an item is selected (once the Menu is closed and the Player is in normal gameplay)? Again, screenshots/mockups will help understand the exact intent.

    As for inventory-inventory combining, it may be best to rely a simple script that selects an item but doesn't close the menu - but as it's another layer of complexity, it's probably best to get Hotspot/Inventory interactions sorted first.

  • Does that sound right?

    Yes, that is right about inventory interactions.

    How are you opening/closing the Inventory menu? It should be that an item remains selected after closing it. If the item's appears in the centre of the screen (as it was before), try then using a Hotspot.

    I use InteractionA to open and close the Inventory menu, and also select item.
    How do I use a Hotspot? I don't understand much about When inventory selected: Change Hotspot Label. I change Change Cursor to Change Hotspot Label, when I select item from inventory, the item doesn't appear in the centre of the screen, that is what I want, but it has nothing happen after I selected.

    Assuming that works, how then do you want to visualise that an item is selected (once the Menu is closed and the Player is in normal gameplay)?

    I don't want to visualise the item selected. When the player select item is proximity to a hotspot, it will interact, if not, nothing happen with item selected.

    I think screenshots of my game is difficult to understand because I don't have everything implemented, but I attach a similar game that I want to implement.

    Between 4:45-5:02 is the function that I want to do as I have explained before.

  • edited April 2021

    If I'm following you: if you open the inventory, and you happen to be near a Hotspot at the time, then using an item causes the menu to close, and the Hotspot/Inventory interaction automatically run?

    That should be possible with a simple script:

    using UnityEngine;
    using AC;
    
    public class AutoUseItemOnHotspot : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnInventorySelect += OnInventorySelect; }
        private void OnDisable () { EventManager.OnInventorySelect += OnInventorySelect; }
    
        private void OnInventorySelect (InvItem invItem)
        {
            if (KickStarter.player.hotspotDetector.NearestHotspot)
            {
                PlayerMenus.GetMenuWithName ("Inventory").TurnOff ();
                KickStarter.player.hotspotDetector.NearestHotspot.RunInventoryInteraction (invItem);
            }
        }
    
    }
    

    Place in a C# script named AutoUseItemOnHotspot, place in the scene, and amend the "Inventory" name in the code to match your own Inventory, if it differs.

    Is that the behaviour you're looking for?

  • Yes! Is the behaviour I am looking for, now how do I close inventory menu?

  • Apologies - that was missing from the script. I've amended the above - try it again.

  • Thanks very much!

  • As for the item combining: it may be a bit more involved than this, but the following script should cause 'c' keypresses to select/deselect items while the Inventory menu is open - provided that it's an AC menu, and not Unity UI:

    using UnityEngine;
    using AC;
    
    public class CustomCombine : MonoBehaviour
    {
    
        private Menu inventoryMenu;
    
        void Update ()
        {
            if (Input.GetKeyDown (KeyCode.C))
            {
                if (inventoryMenu == null) inventoryMenu = PlayerMenus.GetMenuWithName ("Inventory");
                if (inventoryMenu.IsOn () && inventoryMenu.selected_element is MenuInventoryBox)
                {
                    if (InvInstance.IsValid (KickStarter.runtimeInventory.SelectedInstance))
                    {
                        KickStarter.runtimeInventory.SelectedInstance.Deselect ();
                        return;
                    }
    
                    MenuInventoryBox inventoryBox = inventoryMenu.selected_element as MenuInventoryBox;
                    InvInstance invInstance = inventoryBox.GetItem (inventoryMenu.selected_slot);
                    if (InvInstance.IsValid ())
                    {
                        invInstance.Select ();
                    }
                }
            }
        }
    }
    

    While an item is selected, using another item will result in a combination attempt. You can define a default combine response (i.e. "I can't use these things together") by assigning an ActionList in the Inventory Manager's Unhandled combine field.

  • I got it, thank you

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.