Forum rules - please read before posting.

Different icons for multiple inventory item ranges?

Using the method you described for money:

For money, go to the Inventory Manager and create an Inventory item called Money.  Check Can carry multiple?, and if you've also got Carry on start? checked, you can specify how many units of currency you're carrying.  To deduct currency, use the Inventory: Add or remove Action - when you set it up to remove Money, you'll be able to decide how much money to remove.  And to check if you have enough money, use the Inventory: Check Action - when you select Money, you'll be able to query how much exactly the Player is carrying, and act accordingly.

Is it possible to set different icons based on the amount of a certain item a player is carrying? For instance, in MI2, there are these different sprites:
image
It would be handy if here:
image
If Can  carry multiple?  is chosen, you could set a different icon for each range of amounts.
For instance, 1 could use that graphic, 2 could use the second and 3 the third, once you hit 4-8 you could use the forth graphic, then 8-19 could use the pen-ultimate graphic, and finally anything over and including 20 could use the last graphic.

This is really just a casual suggestion, for now though I expect the solution to having a different image for different amounts would be to either change the icon when some money is received by checking the amount and swapping the image, or using a money variable that is checked? I'm not sure using different items would work since the amount of money needs to remain consistent whenever and wherever it is collected?

Comments

  • I think this is too specific to be a built-in feature - the deliberations of what graphic is used for which amounts would never be consistent, and the UI for allowing for that would be overly complex.

    Better to rely on some simple scripting: the OnInventoryAdd and OnInventoryRemove custom events are called when the inventory is modified - even if you're changing the amount of an item held by the player.  You can use this to modify the "Main graphic" texture - which you can get an API reference for by right-clicking the field.

    Example:

  • Thanks! That looks really nice, I'll give it a spin. I thought it might a bit complicated/specific for a feature, as for cluttered UI, I was imagining you'd add a range and set the floor and ceil of the count range much like the sortingMap is configured, with an Add Range button and a couple of value boxes to denote lowest and highest amount before a new picture is loaded. Only suggesting! Thanks again for the script, really tight looking!
  • edited September 2018
    I've tried extending this to change the name of the item to match the amount (1 coin, 2 coin(s)):
            if (item.id == moneyItemID && amount < 2)
            {
                item.label = amount.ToString() + " coin";
                Debug.Log(amount.ToString());
            }
            else if (item.id == moneyItemID && amount > 1)
            {
                item.label = amount.ToString() + " coins";
                Debug.Log(amount.ToString());
            }
    But I can't get the item's image to change, the amount to say anything other than "1 coin" nor does the debug return anything except 1 if I keep picking the same hotspot up. If I change the "add or remove" action to "set amount?" and "Increase amount by:" the debug will always give that amount, for instance if I set it to increase amount by 2, the debug will always say 2 whenever I pick the same item up repeatedly. The images reflect this amount, however, so the script is working, and so is the labelling part.

    As a test I tried "Place in separate slots" and the first item added is labelled "1 coin" but every subsequent slot is labelled "money" which is the default label. Is there any way I'm missing of increasing the objects count?
  • Here's a video where I go through all possible iterations of this: https://gfycat.com/DistinctGoodnaturedArizonaalligatorlizard
  • My bad.  Replace "amount" with "item.count" - the former refers to the change that was made.
  • I must admit I was a bit confused by why it was amount instead of count! I was going to try count but I think I got something wrong as usual and count didn't fuzzy for me! 😜 Thanks!
  • Hi Chris and zebbi - any chance one of you could refresh that pasteall link? It would be really handy for me right now ;-)

  • I believe this was it:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class MoneyIconExample : MonoBehaviour
    {
    
        public int moneyItemID;
        public Texture[] amountTextures = new Texture[6];
    
    
        private void OnEnable ()
        {
            EventManager.OnInventoryAdd += OnInventoryModify;
            EventManager.OnInventoryRemove += OnInventoryModify;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnInventoryAdd -= OnInventoryModify;
            EventManager.OnInventoryRemove -= OnInventoryModify;
        }
    
    
        private void OnInventoryModify (InvItem item, int amount)
        {
            if (item.id == moneyItemID && amount > 0)
            {
                if (amount >= 20)
                {
                    item.tex = amountTextures[5];
                }
                else if (amount >= 8)
                {
                    item.tex = amountTextures[4];
                }
                else if (amount >= 4)
                {
                    item.tex = amountTextures[3];
                }
                else if (amount == 3)
                {
                    item.tex = amountTextures[2];
                }
                else if (amount == 2)
                {
                    item.tex = amountTextures[1];
                }
                else
                {
                    item.tex = amountTextures[0];
                }
    
                PlayerMenus.ResetInventoryBoxes ();
            }
        }
    
    }
    
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.