What is the Script call to get the current inventory count?

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
Hey everyone, due to some conflicting issues with some limit inventory plugins I've had to forgo using them in my current project, but due to the nature of how the game is supposed to be played, I would still like to limit how many items the player can carry with them. This can be achieved easily enough with variables and conditional branches but there doesn't seem to be an easy way to retrieve the player's current inventory count and store it into a variable. Does anyone know if there a Script Call or even plugin that I can use to achieve this effect?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
$gameParty._items[id]
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Do you have the items of that particular ID in your inventory?
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
Do you have the items of that particular ID in your inventory?
Sorry I must not have explained it well. I want to get the current amount of items in the player inventory and add it to a variable. For example, say you have 3 potions, 2 elixirs, and 1 phoenix down, then the script call would add 6 to the assigned variable.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Set a variable to 0, then:

Code:
for (var i in $gameParty._items) $gameVariables.setValue(varId, $gameParty._items[i])
replace the varID with id of the variable where you want to save the item count.
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
Set a variable to 0, then:

Code:
for (var i in $gameParty._items) $gameVariables.setValue(varId, $gameParty._items[i])
replace the varID with id of the variable where you want to save the item count.
I tried that using "$gameVariables.setValue(17, $gameParty._items)" in a script call and I got this error:
upload_2019-9-1_13-1-11.png
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
In vanilla MV the code works.
Hit f8 in the game to open the dev console, hopefully it shows the real readon why the bug triggered.

Btw. it wasn't the fully desired code, I forgot to include the variable as an additive.
Code:
for (var i in $gameParty._items) $gameVariables.setValue(varId, $gameVariables.value(varId) + $gameParty._items[i])
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
@Poryg Ok it was on my end why the code wasn't working, but it still doesn't solve my problem. The code will just keep adding to the variable and I would still need to check every item in the game when I want an easier way to manage how many items are in the inventory.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Well, if you want to prevent having to reset the variable to 0 everytime, this script would do it.

Code:
var itemCount = 0;
for (var i in $gameParty._items) itemCount += $gameParty._items[i];
$gameVariables.setValue(varId, itemCount);
where you just replace the varId with desired item id.

As for the checking every item in the game, well, you've asked for a way to check the item count with a script, I delivered what you asked for.
If it didn't solve your problem, then that means a small adaptation might be needed and it saved as a plugin to prevent you from having to check for every item if that's what you want.
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
@Poryg Perfect! Works like a charm! Thank you so much with the help and being patient with me. I super appreciate it.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
It's okay. I usually opt in for the simplest solution, although the simplest one is not always the most convenient one, so it was kind of my bad too.
Going a step further wouldn't be too difficult either though, for example this saved as a plugin
Code:
Game_Interpreter.prototype.command126 = function() {
    var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
    var itemCount = 0;
    if (value > 0) {
        for (var i in $gameParty._items) itemCount += i;
        if (itemCount + value > $gameVariables.value(maxcapId) ) value = $gameVariables.value(maxcapId) - itemCount;
    }
    $gameParty.gainItem($dataItems[this._params[0]], value);
    if (value + itemCount == $gameVariables.value(maxcapId)) $gameMessage.add("Picked up only " + $dataItems[this._params[0]].name + " x" + value + " - Inventory full!");
    return true;
};
would do all checks on the backend and it would warn the player if the inventory got full.

EDIT: Edited out one extra line of code
 
Last edited:

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
@Poryg That's really neat! i tried it out, but I get an error of maxCap is undefined even though I put the variable number for the Max Inventory Limit.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Fixed, sorry :D
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
@Poryg Hmm, now when I add items it lumps them all into one.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Typing from mobile is prone to errors :( Debugged on PC, so hopefully it's all good now. Added in an extra spice too!

Code:
Game_Interpreter.prototype.command126 = function() {
var value = this.operateValue(this._params[1], this._params[2], this._params[3]);
var itemCount = 0;
if (value > 0) {
for (var i in $gameParty._items) itemCount += $gameParty._items[i];
if (itemCount + value > $gameVariables.value(1) ) value = $gameVariables.value(1) - itemCount;
}
$gameParty.gainItem($dataItems[this._params[0]], value);
var gained = this._params[1] ? " lost!" : " gained!";
var itemName = $dataItems[this._params[0]].name;
var iconID = $dataItems[this._params[0]].iconIndex;
if (value + itemCount == $gameVariables.value(1)) $gameMessage.add("Picked up only " + "\\i[" + iconID + "] " + itemName + " x" + value + " - Inventory full!");
else $gameMessage.add("\\i[" + iconID + "] " + itemName + " x " + value + " " + gained);
return true;
};
 

Uzuki

Kawaii on the streets, Senpai in the sheets
Veteran
Joined
Aug 18, 2012
Messages
1,933
Reaction score
1,325
First Language
English
Primarily Uses
RMMV
@Poryg This is fantastic! Thank you so much for your help! Is it ok if I use this for a commercial project? I'll be sure to credit you and send you a copy of the finished project.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Sure, you can use it in a commercial project without a problem. Half of the code was taken from my scripting/plugin making tutorial series anyway, so I can't really hold it hostage even if I wanted :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Why is there so much month left at the end of money? D=
Hello humans! How goes your day in this journey of living? I hope it is good, for I am human like you, and I am feeling great! Worship the altar.
Sand is basically small rocks

Forum statistics

Threads
105,625
Messages
1,015,041
Members
137,285
Latest member
AndrewRobertson
Top