Making Inventory Containers (Banks, NPC loots, Treasure Chests)

It’s really off topic for tis thread…

Have you considered freezing time while the windows are open? If you’re dragging items to the crafting table and get interrupted, you’re risking data loss… In any event, you need to get the UI to open and the crafting working FIRST, then then start worrying about adding in interruptions. Some of the issues you’ve encountered in the past are trying to do too many things at the same time, which has lead to unintended consequences.

As we’re adding multiple setups

  • Inventory + Equipment
  • Inventory + OtherInventory
  • Inventory + Crafting

It might make sense to create three different HidingPanels, one with each configuration…

But for now… we’ll handle things this way…
Add the following to ShowHideUI in the Fields:

        [SerializeField] private GameObject craftingTable = null;
        //[SerializeField] CraftingTableUI craftingTableUI; //Whatever your UI is for the crafting table

        public bool HasCraftingTable => craftingTable != null;
        public void ShowCraftingTable(GameObject go)
        {
            uiContainer.SetActive(true);
            craftingTable.SetActive(true);
            //call setup on crafting table ui
        }

Now your CraftingTable will want to find the ShowHideUI whose HasCraftingTable == true (much like in the Bank) and call ShowCraftingTable.

I’m trying to take it slow, for now just trying to get the UI to properly open up

Well, it’s an idea… but I want the player to risk getting attacked as well. It just makes things a bit more… fun :sweat_smile:

I have a function called ‘OpenCraftingUI()’ in ‘CraftingTable.cs’ that I tried coding last night. It’s responsible for the UI, do I call it there?

I’ll open a new thread for this, since it’s clearly going off topic (done, check your notifications)

And one last thing… the parameters here are pointless :stuck_out_tongue_winking_eye: (the compiler complains, and the system works perfectly fine without them)

Are you saying the GameObject go is pointless or the SetActive(true); pointer is pointless???

You use the go parameter to pass to the setup on the CraftingTableUI so it knows so it can communicate with the crafting table.

the gameObject go (at least for now :sweat_smile:)

OK I know my questions are a little bit rapid nowadays, and this is a function I’ve been putting aside for now, but it’s really bugging me. I have a severe issue where extracting/banking stackable items in large quantities takes a lot of time, and I want to get rid of it. My thought is that if the player clicks on something stackable, instead of withdrawing it one-by-one, display to him a UI that requests for a number of items to extract from the bank, and that number can be anything the player wants, as long as it’s a numeric value (so it can’t accept alphabetical values)

If it’s larger than the quantity the bank has, just extract the entire stack for him (the value shall not exceed the stack number). If it’s lower, extract the quantity he needs. This is my request, and in the meanwhile I’ll go ahead and give it a go (or at least try develop the UI for it) :slight_smile: - I’ll update my comment as I go (for the UI, I’ll use what the ‘New Game Menu’ text UI used)

Dragging it takes the full stack, no? If you’re using the click to move stuff, do this:

  • Click moves 1
  • Ctrl+Click moves all - you know how many items are in the stack
  • Shift+Click opens a UI with a slider. Again, you know how many items are in the stack for the max of the slider

It’s an idea, but… it sounds a little too complex for the players. I don’t want them to press countless buttons to achieve a specific objective, I want to keep this as simple and hassle-free as possible as well, especially with extremely simple functions that players are expecting, like this one, because again… it’s a simple point-and-click game system, so I think we can try mine for the moment (no offence meant btw, just personal preference) :slight_smile:

I wanted to do something at first that involves a right-click UI to make everyones’ life easier, but since Brian mentioned that it’s a little too complex, I think for now I’ll just settle for something a little simpler. If you try withdraw a stackable item, just show up a UI that asks you for a number, and then we can withdraw the number given by the player of that item (again, if the number exceeds the max stack for that item, then only withdraw the max number)

The simpler the system is for the player, the better

You underestimate players. This is how most games’ inventories do it - or some variation on it - and players that have played games with inventories before will pretty much automatically assume that’s how it will work. But you can do a UI if you want. It’s your game

That makes it even better, so now I have a selling point… my game is simpler and hassle-free :stuck_out_tongue_winking_eye: (I just hope we can actually get it to the stage of extraction, xD)

How can i populate the slots of the containers ?

You mean like for a treasure chest?
On the same GameObject as the otherInventory Container, add a script that adds the items to the Inventory. Something like this:

public class InventoryLoader : MonoBehaviour
{
    [System.Serializable]
    struct LoaderRecord
    {
          public InventoryItem item;
          public int number;
     }
     
     [SerializeField] private LoaderRecord[] itemsToLoad;
    
      void Awake()
      {
            Inventory inventory = GetComponent<Inventory>();
            foreach(LoaderRecord record in itemsToLoad)
            {
                   inventory.AddToFirstEmptySlot(record.item, record.number);
            }
      }
}
1 Like

thank you

Hey Brian. Just curious, can we also please get instructions on how to blend the bank into your Third Person migration gitbook? :slight_smile:. I revised the bank system, and it seems a bit… too complex tbh.

When I’m home, I’ll give that a go myself and keep you updated. Just thought to bring this idea up, xD

The only problem with putting it in the tutorial is that the bank itself isn’t in the version of the project that I’m using, and there’s no guarantee that it will work for everybody.

Eventually, it could be a side tutorial. Here’s the thing, though… the process to get from PlayerFreeLookState to opening the bank window pretty much the same as the process to open a shop. Once that happens, the rest sort of handles itself… Since the InventoryUI is already a WindowController, all that you need to do is to have a

  • BankFinder
  • A PlayerBankingState that can take in the bank
  • An InputAction/Event to open the bank (or rely on the “One Click”… the more things get added, the more the One Click makes perfect sense.

So this is your challenge. :stuck_out_tongue:

Not sure what I missed out on, but I did not make my ‘InventoryUI.cs’ a WindowController inheritant… (and I’m not sure how doing so now will mess this project up)

Anyway, will give the rest a go for now :slight_smile:

Actually, it may not be, I was typing that from work. InventoryWindow is the actual WindowController for the InventoryUI and Equipment.

fair enough… but for the BankFinder, if it’s inheriting from a RangeFinder, what sort of data is this one inheriting from? I tried with ‘OtherInventory’, but C# rejected it

Where T: MonoBehaviour, ITarget

you can guess the syntax errors coming out of this one… :sweat_smile:

public class BankFinder : RangeFinder<T> where T : MonoBehaviour, ITarget 
{

}

If not, we have 2 for now:

The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

and for the ‘Where’ keyword:

Constraints are not allowed on non-generic declarations

That’s what you get for waking up and coding before work, because work won’t give you a chance I guess…

Privacy & Terms