Max Items v1.2

Introduction
Allows for more control over the maximum number of items that may be carried, as well as displaying information about them in the inventory.

Features
  • Control the maximum number of items that may be carried. Can use evals/code, allowing for the maximum to be changed mid-game.
  • Customise how the information is displayed in the inventory/item scene.
  • Change the colours of the numbers dynamically.
How to use
Adjust the parameters as you see fit.
Most of the parameters should be self-explanatory, but there's a few that probably warrant some extra explanation.

Override_drawItemNumber:
By default, in RMMV, the quantity of items is displayed as follows:
(Item Name) :xx
where the position of the ':' is fixed, regardless of the number of digits in the quantity.
This may result in overlapping with the ':' if the quantity owned is 3 or more digits long.
To avoid this, this plugin provides an option to override the default drawItemNumber function with a customisable one.
This is required for any customisation of the item number.

PrefixPositionMode:
This allows you to choose how the position of the prefix is determined.
Automatic - Prefix is automatically placed behind the number.
Manual - Prefix location is manually set.

Notetags
The following notetags are available for items, weapons, and armours:

<max:x>
Specifies the maximum carrying quantity of that item. x must be a value greater than 0.

<maxeval>
//code
</maxeval>
Evaluates code to determine the maximum carrying quantity of that item.
Must return a value greater than 0.

<showitemmax>
<hideitemmax>
Overrides the default setting and shows or hides the max carrying quantity.

<hidenumberprefix>
Hides the prefix for the item number.

<hidenumber>
Hides the number. Nothing will be drawn.

<numbercolour>
//code
</numbercolour>
Overrides the default setting and evaluates code to determine the number colour.

Script
Spoiler: CODE
JavaScript:
//==========================================
// APHO_MaxItems.js
//==========================================
/*:
* @title Max Items
* @author Apho
* @plugindesc v1.1 Allows for more control over the maximum number of items that may be carried, as well as displaying information about them in the inventory.
*
* @param DefaultMax
* @text Default Max.
* @type string
* @desc Default maximum carrying quantity. This is an eval.
* @default 99
*
* @param Override_drawItemNumber
* @text Override drawItemNumber?
* @type boolean
* @desc Override the default drawItemNumber function and use a custom one?
* @default true
*
* @param ItemNumberPrefix
* @parent Override_drawItemNumber
* @text Item Number Prefix
* @type string
* @desc Stuff shown before the number of items owned.
* @default :
*
* @param PrefixPositionMode
* @parent ItemNumberPrefix
* @text Prefix Position Mode
* @type select
* @option Automatic
* @value 0
* @option Manual
* @value 1
* @desc Positioning of the prefix.
* @default 0
*
* @param PrefixPosition
* @parent ItemNumberPrefix
* @text Prefix Position
* @desc Prefix is fixed at this location. (Manual mode only)
* @type string
* @default width - this.textWidth('00')
*
* @param DrawItemMax
* @parent Override_drawItemNumber
* @text Draw Item Max?
* @desc Append the max carrying quantity to the owned quantity in the inventory by default?
* @type boolean
* @default false
*
* @param DrawItemMaxPrefix
* @parent DrawItemMax
* @text Draw Item Max Prefix
* @desc Stuff to show before the max carrying quantity.
* @type string
* @default /
*
* @param DrawItemMaxSuffix
* @parent DrawItemMax
* @text Draw Item Max Suffix
* @desc Stuff to show after the max carrying quantity.
* @type string
* @default
*
* @param DrawItemMax_AutoHidePrefix
* @parent DrawItemMax
* @text Auto Hide Number Prefix
* @desc Automatically hide the number prefix whenever max carrying quantity is drawn?
* @type boolean
* @default true
*
* @param ItemNumberColour
* @parent Override_drawItemNumber
* @text Item Number Colour
* @desc Colour of the item number. This is an eval.
* @type string
* @default $gameParty.numItems(item) >= $gameParty.maxItems(item) ? "#FF0000" : "#FFFFFF"
*
* @param HighNumberOverride
* @parent Override_drawItemNumber
* @text High Number Override
* @desc Override the item number with a string upon exceeding specified value?
* @type boolean
* @default false
*
* @param HighNumberOverrideThreshold
* @parent HighNumberOverride
* @text High Number Override Threshold
* @desc The item number will be replaced if it exceeds this value.
* @type number
* @default 99
*
* @param HighNumberOverrideString
* @parent HighNumberOverride
* @text High Number Override
* @desc String that will replace the item number upon exceeding the threshold.
* @type string
* @default 99+
*
* @param HighNumberOverride_AutoHidePrefix
* @parent HighNumberOverride
* @text Auto Hide Number Prefix
* @desc Automatically hide the number prefix for high numbers?
* @type boolean
* @default false
*
* @param NumberWidth
* @text Number Width
* @desc Amount of space that should be reserved for the item number. Leave blank for default.
* @type string
* @default this.textWidth('000')
*
* @help
* Allows for more control over the maximum number of items that may be carried.
* You may also customise how that information will be displayed to the player.
*
* PLUGIN PARAMETERS
* Most of the parameters should be self-explanatory, but there's a few that
* probably warrant some extra explanation.
* Override_drawItemNumber:
* By default, in RMMV, the quantity of items is displayed as follows:
* (Item Name)          :xx
* where the position of the ':' is fixed, regardless of the number of digits
* in the quantity.
* This may result in overlapping with the ':' if the quantity owned is 3 or
* more digits long.
* To avoid this, this plugin provides an option to override the default
* drawItemNumber function with a customisable one.
* This is required for any customisation of the item number.
*
* PrefixPositionMode:
* This allows you to choose how the position of the prefix is determined.
* Automatic - Prefix is automatically placed behind the number.
* Manual - Prefix location is manually set.
*
* NOTETAGS
* The following notetags are available for items, weapons, and armours:
* <max:x>
* Specifies the maximum carrying quantity of that item. x must be a value
* greater than 0.
*
* <maxeval>
* //code
* </maxeval>
* Evaluates code to determine the maximum carrying quantity of that item.
* Must return a value greater than 0.
*
* <showitemmax>
* <hideitemmax>
* Overrides the default setting and shows or hides the max carrying quantity.
*
* <hidenumberprefix>
* Hides the prefix for the item number.
*
* <hidenumber>
* Hides the number. Nothing will be drawn.
*
* <numbercolour>
* //code
* </numbercolour>
* Overrides the default setting and evaluates code to determine the number
* colour.
*
* NOTES
* - When using a formula to determine maximum carrying quantity, if the value is
*   reduced mid-game and the player had more than they can carry, the player
*   does not lose the excess; however they will be unable to obtain more.
* - If a max quantity has not been specified, and the default formula in this
*   plugin evaluates to 0 or undefined, RMMV's original default applies.
*   (99, may be changed by other plugins)  
* - If you are using YEP_CoreEngine, or any plugin that changes the default
*   item limit, place this plugin below them in the plugin manager.
*
* TERMS OF USE
* - Free for commercial and non-commercial use, as long as I get a free copy
*   of the game.
* - Edits allowed for personal use.
* - Do not repost or claim as your own, even if edited.
*
* VERSION HISTORY
* v1.2 - 2023/10/18 - Bugfix for crashing during battle test when using the <max> notetag.
* v1.1 - 2023/09/25 - Bugfix for crashing when checking an item that does not exist.
* v1.0 - 2023/09/08 - Initial release.
*/
(function(){
    var parameters = PluginManager.parameters('APHO_MaxItems');
    CheckMaxEval = function(notetag, item)
    {
        const MaxEvalOpen = '<maxeval>';
        const MaxEvalClose = '</maxeval>';
        let ReadMaxEval = false;
        let MaxEvalInfo = "";
        for (var n = 0; n < notetag.length; n++)
        {
            let NoteData = notetag.split(/[\r\n]+/);
            let line = NoteData[n];
            if (line && line.match(MaxEvalOpen))
            {
                ReadMaxEval = true;
            }
            else if (line && line.match(MaxEvalClose))
            {
                ReadMaxEval = false;
            }
            else if (ReadMaxEval == true)
            {
                MaxEvalInfo += line + '\n';
            }
        }
        return eval(MaxEvalInfo)
    };
    const Game_Party_maxItems = Game_Party.prototype.maxItems;
    Game_Party.prototype.maxItems = function(item) {
        if(item)
        {
            if(CheckMaxEval(item.note, item) && CheckMaxEval(item.note, item) > 0)
            {
                return CheckMaxEval(item.note, item);
            }
            else if(item.meta.max)
            {
                return parseInt(item.meta.max);
            }
        }
        return Function("return " + parameters['DefaultMax'])() || Game_Party_maxItems.call(this, item);
    }
    const Game_Party_gainItem = Game_Party.prototype.gainItem;
    Game_Party.prototype.gainItem = function(item, amount, includeEquip) {
        if($gameParty.numItems(item) <= this.maxItems(item))
        {
            Game_Party_gainItem.call(this, item, amount, includeEquip);
        }
        else
        {
            var container = this.itemContainer(item);
            if (container) {
                var lastNumber = this.numItems(item);
                var newNumber = lastNumber + amount;
                container[item.id] = newNumber.clamp(0, $gameParty.numItems(item));
                if (container[item.id] === 0) {
                    delete container[item.id];
                }
                if (includeEquip && newNumber < 0) {
                    this.discardMembersEquip(item, -newNumber);
                }
                $gameMap.requestRefresh();
            }
        }
    };
    var Override_drawItemNumber = JSON.parse(parameters['Override_drawItemNumber']);
    if(Override_drawItemNumber)
    {
        CheckColourEval = function(notetag, item)
        {
            const ColourEvalOpen = '<numbercolour>';
            const ColourEvalClose = '</numbercolour>';
            let ReadColourEval = false;
            let ColourEvalInfo = "";
            for (var n = 0; n < notetag.length; n++)
            {
                let NoteData = notetag.split(/[\r\n]+/);
                let line = NoteData[n];
                if (line && line.match(ColourEvalOpen))
                {
                    ReadColourEval = true;
                }
                else if (line && line.match(ColourEvalClose))
                {
                    ReadColourEval = false;
                }
                else if (ReadColourEval == true)
                {
                    ColourEvalInfo += line + '\n';
                }
            }
            return eval(ColourEvalInfo)
        };
        var ItemNumberPrefix = String(parameters['ItemNumberPrefix']);
        var PrefixPositionMode = parseInt(parameters['PrefixPositionMode']);
        var DrawItemMax = JSON.parse(parameters['DrawItemMax']);
        var DrawItemMaxPrefix = String(parameters['DrawItemMaxPrefix']);
        var DrawItemMaxSuffix = String(parameters['DrawItemMaxSuffix']);
        var DrawItemMax_AutoHidePrefix = JSON.parse(parameters['DrawItemMax_AutoHidePrefix']);
        var HighNumberOverride = JSON.parse(parameters['HighNumberOverride']);
        var HighNumberOverrideThreshold = parseInt(parameters['HighNumberOverrideThreshold']);
        var HighNumberOverrideString = String(parameters['HighNumberOverrideString']);
        var HighNumberOverride_AutoHidePrefix = JSON.parse(parameters['HighNumberOverride_AutoHidePrefix']);
        Window_ItemList.prototype.drawItemNumber = function(item, x, y, width) {
            if(item.meta.numbercolour)
            {
                this.changeTextColor(CheckColourEval(item.note, item));
            }
            else
            {
                this.changeTextColor(eval(parameters['ItemNumberColour']));
            }
            if (this.needsNumber() && !item.meta.hidenumber) {
                let TextToDraw = $gameParty.numItems(item);
                let NeedsDrawItemMax = (DrawItemMax || item.meta.showitemmax) && !item.meta.hideitemmax;
                let NeedsNumPrefix = !item.meta.hidenumberprefix
                if(HighNumberOverride && $gameParty.numItems(item) > HighNumberOverrideThreshold)
                {
                    TextToDraw = HighNumberOverrideString;
                    if(NeedsNumPrefix && HighNumberOverride_AutoHidePrefix)
                    {
                        NeedsNumPrefix = false;
                    }
                }
                if(NeedsNumPrefix && DrawItemMax_AutoHidePrefix && NeedsDrawItemMax)
                {
                    NeedsNumPrefix = false;
                }
                if(NeedsNumPrefix)
                {
                    switch(PrefixPositionMode)
                    {
                        case 0:
                            TextToDraw = ItemNumberPrefix + TextToDraw;
                        break;
                        case 1:
                            this.drawText(ItemNumberPrefix, x, y, eval(parameters['PrefixPosition']), 'right');
                        break;
                    }
                }
                if(NeedsDrawItemMax)
                {
                    TextToDraw = TextToDraw + DrawItemMaxPrefix + $gameParty.maxItems(item) + DrawItemMaxSuffix;
                }
                this.drawText(TextToDraw, x, y, width, 'right');
            }
        };
    }
    const Window_ItemList_numberWidth = Window_ItemList.prototype.numberWidth;
    var NumberWidth = parameters['NumberWidth'];
    Window_ItemList.prototype.numberWidth = function() {
        if(NumberWidth)
        {
            return eval(NumberWidth)
        }
        else
        {
            return Window_ItemList_numberWidth.call(this);
        }
    };
})();

Notes
  • When using a formula to determine maximum carrying quantity, if the value is reduced mid-game and the player had more than they can carry, the player does not lose the excess; however they will be unable to obtain more.
  • If a max quantity has not been specified, and the default formula in this plugin evaluates to 0 or undefined, RMMV's original default applies. (99, may be changed by other plugins)
  • If you are using YEP_CoreEngine, or any plugin that changes the default item limit, place this plugin below them in the plugin manager.
Terms of use
  • Free for commercial and non-commercial use, as long as I get a free copy of the game.
  • Edits allowed for personal use.
  • Do not repost or claim as your own, even if edited.
  • Do not use for training AI models. This includes, but is not limited to, inputting the plugin contents or part thereof into AI models that train on user input.
Version history
v1.2 - 2023/10/18 - Bugfix for crashing during battle test when using the <max> notetag.
v1.1 - 2023/09/25 - Bugfix for crashing when checking an item that does not exist.
v1.0 - 2023/09/08 - Initial release.

Download link
GitHub

Spoiler: SCREENSHOT
things.png
will try this as i am using ammunition for my game, hope its compatible with the plugins i am using.
Thank You for this and more power.
Oh, would you look at that. I was just recently pondering what to do. I kinda wanted to have limited amounts of certains items, but yanfly's plugin is kinda backwards in how it displays things and it's consistently confusing may players, so this might come in handy.

Just gotta hope it works with my custom menu and the rest of my plugins. Thanks for making this either way!


Edit: of course it doesn't lol. Say, your ToS allows edit only for personal use? Can we like... Change that? xD
What exactly doesn't work, and what are you trying to edit?

The ruling is there for a reason; I don't want to end up having unofficially edited versions publicly available because that would make troubleshooting and fixing issues a lot harder. If you're getting someone else to edit it, that's still fine as long as you're just using it for your own project(s) and not redistributing it.
What exactly doesn't work, and what are you trying to edit?

The ruling is there for a reason; I don't want to end up having unofficially edited versions publicly available because that would make troubleshooting and fixing issues a lot harder. If you're getting someone else to edit it, that's still fine as long as you're just using it for your own project(s) and not redistributing it.
I have a custom menu plugin, so the plugin simply doesn't do anything. I can have infinite amounts of items and the 1 / x is also not displayed, which is kinda expected.

Might also be a conflict with yanfly stuff? I don't know, it doesn't throw any errors unless I put it at the bottom of the plugin order.

I would just have it made compatible with my project. The reason I'm asking about the terms is because I'm making a commercial game, which is still personal use I guess. Just wanted to clarify that it was okay.

I don't expect you to make it work of course, you can hardly make it compatible with everyone's custom stuff.
I would just have it made compatible with my project. The reason I'm asking about the terms is because I'm making a commercial game, which is still personal use I guess.
Yeah, when terms refer to "personal use" that should include your game's release - it's just saying don't distribute your modified version to the public.

Original thread: https://forums.rpgmakerweb.com/threads/max-items-v1-2.161017/