Forum rules - please read before posting.

Change "Use" to "Give" at runtime.

Dear Chris and AC followers,
I'm wondering if it's possible to change the way an inventory item syntax is displayed when hovering a NPC rather than a hotspot.
Basically I'd like to have "Use" only when interacting with an inventory item, therefore I have "Use ITEM on HOTSPOT" syntax. However, if my item is hovering a hotspot which also has a NPC component attached to it, I'd like the syntax to be the one I've written down for Give: "Give ITEM to NPC".
So I basically want that my Use change the syntax to Give at runtime, without changing the select mode nor the action list which is already set on "Use", but simply the way I show the label/syntax.
I saw a thread about overriding the Use syntax for specific needs, but what I'm looking for is probably more simple, just swapping to Give syntax if the Hotspot I'm hovering has a NPC component...
Any suggestion?

Comments

  • It would depend on your Interface settings.

    If your game supports multiple inventory interactions, items have a dedicated "Give" select mode. You can set this dynamically at the moment a Hotspot is selected:

    using UnityEngine;
    using AC;
    
    public class GiveToNPCs : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += OnHotspotSelect;
            EventManager.OnHotspotDeselect += OnHotspotDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect -= OnHotspotSelect;
            EventManager.OnHotspotDeselect -= OnHotspotDeselect;
        }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            if (InvInstance.IsValid (KickStarter.runtimeInventory.SelectedInstance))
            {
                bool isCharacter = (hotspot.gameObject.GetComponent <Char>());
                KickStarter.runtimeInventory.SelectedInstance.SelectItemMode = (isCharacter) ? SelectItemMode.Give : SelectItemMode.Use;
            }
        }
    
        private void OnHotspotDeselect (Hotspot hotspot)
        {
            if (InvInstance.IsValid (KickStarter.runtimeInventory.SelectedInstance))
            {
                KickStarter.runtimeInventory.SelectedInstance.SelectItemMode = SelectItemMode.Use;
            }
        }
    
    }
    

    Otherwise, you'll have to fake a "give" mode by rewriting the item's prefix strings:

    using UnityEngine;
    using AC;
    
    public class GiveToNPCs : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += OnHotspotSelect;
            EventManager.OnHotspotDeselect += OnHotspotDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect -= OnHotspotSelect;
            EventManager.OnHotspotDeselect -= OnHotspotDeselect;
        }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            if (InvInstance.IsValid (KickStarter.runtimeInventory.SelectedInstance))
            {
                bool isCharacter = (hotspot.gameObject.GetComponent <Char>());
                KickStarter.runtimeInventory.SelectedInstance.InvItem.hotspotPrefix1 = (isCharacter) ? "Give" : "Use";
                KickStarter.runtimeInventory.SelectedInstance.InvItem.hotspotPrefix2 = (isCharacter) ? "to" : "on";
            }
        }
    
        private void OnHotspotDeselect (Hotspot hotspot)
        {
            if (InvInstance.IsValid (KickStarter.runtimeInventory.SelectedInstance))
            {
                KickStarter.runtimeInventory.SelectedInstance.InvItem.hotspotPrefix1 = "Use";
                KickStarter.runtimeInventory.SelectedInstance.InvItem.hotspotPrefix2 = "on";
            }
        }
    
    }
    
  • Thanks a lot! First case on my end works perfectly!

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.