Forum rules - please read before posting.

How would you trade inventory between players?

I'm trying to make an inventory system similar to "Day of the Tentacle", where I can use items on "Switch Player" buttons to swap them over.

I've had moderate success by setting up the "Switch Player" buttons as a separate inventory and using combine events to trade items, but the main issue I ran into is that AC doesn't let me "Add" or "Remove" a "Selected Item" from one player's inventory to another. I need to script each item separately, which will eventually amount to a lot of iterations between players and items.

Am I missing something in AC that easily lets me transfer the "Selected Item" instead of specify 100+ different transactions? What's a better way to set up the exchange?

Comments

  • edited August 2019

    You can simplify things a lot by relying on ActionList parameters for e.g. the "Item to add" and "Item to remove" fields, so that you can run a separate "Transfer Item" ActionList, setting the "Inventory item" property value at the time you run it.

    However, it's probably easiest to just rely on a bit scripting.

    To transfer inventory item with ID=3 from the active Player to a Player with ID=2, you just need to call:

    int itemToTransferID = 3;
    int newPlayerID = 2;
    KickStarter.runtimeInventory.Add (itemToTransferID, 1, false, newPlayerID);
    KickStarter.runtimeInventory.Remove (itemToTransferID);
    

    To set the "itemToTransferID" automatically, you can map it to the currently-selected item or the last-clicked item:

    int itemToTransferID = KickStarter.runtimeInventory.SelectedItem.id;
    int itemToTransferID = KickStarter.runtimeInventory.LastSelectedItem.id;
    

    How you set the "newPlayerID" would be down to how the code above is run. If the "Player icons" are connected to AC's menu system, you can do so from the OnMenuElementClick custom event.

    Perhaps something like this:

    using UnityEngine;
    using AC;
    
    public class MenuEventExample : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementClick += MyClickMenuEvent;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementClick -= MyClickMenuEvent;
        }
    
        private void MyClickMenuEvent (AC.Menu _menu, MenuElement _element, int _slot, int buttonPressed)
        {
            InvItem selectedItem = KickStarter.runtimeInventory.SelectedItem;
            if (selectedItem == null)
            {
                return;
            }
    
            int itemToTransferID = selectedItem.id;
            if (_menu.title == "PlayersMenu")
            {
                if (_element.title == "BernardIcon")
                {
                    // Bernard was clicked, so player ID = 2
                }
                else if (_element.title == "Hoagie")
                {
                    // Hoagie was clicked, so player ID = 3
                }
            }
        }
    
    }
    
  • Setting parameters seemed to do the trick. I have one ActionList that removes the item from all players when the ID is set, and three other ActionLists that give the items back to specific players. As long as I keep the lists up to date, it handles all the combinations very smoothly.

    I can't get the script to compile yet, but I can give it another go when I have more time to learn C+.

    Thanks again, Chris!

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.