Drive

Horror lover
Member
Joined
Jan 14, 2017
Messages
11
Reaction score
3
First Language
Spanish
Primarily Uses
RMMZ
I have created a items list in the Data folder called Food and I would like to test to see if they work by adding them to the inventory, but I think it could only be done if I create an Event by calling the script or something.
In summary Is there a way to add items to inventory using a script?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,708
Reaction score
2,813
First Language
English
Primarily Uses
RMMZ
$gameParty.gainItem(item, quantity)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,340
Reaction score
8,388
First Language
German
Primarily Uses
RMMV
a items list in the Data folder
what kind of list?
and are you talking to add them to the database, or about adding database items to the player inventory?

The code above is for adding database items to the player inventory - if the items are not in the database it will not work.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,708
Reaction score
2,813
First Language
English
Primarily Uses
RMMZ
Yeah, the missing part is that you would need to open whatever external file contained the data and use it to construct a Game_Item. I have the same questions as Andar does.
 

Drive

Horror lover
Member
Joined
Jan 14, 2017
Messages
11
Reaction score
3
First Language
Spanish
Primarily Uses
RMMZ
what kind of list?
and are you talking to add them to the database, or about adding database items to the player inventory?

The code above is for adding database items to the player inventory - if the items are not in the database it will not work.
I'm experimenting a bit with the RPG Maker MZ code in general to understand its control structures and such, and created a Foods.json file based a bit on Items.json
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,708
Reaction score
2,813
First Language
English
Primarily Uses
RMMZ
So this would basically involve a plugin where you expand DataManager's initialisation to create a $dataFoods global variable, and you'd then have to write an isFood function, add a check for that to Game_Party's itemContainer function...there are a number of things you'd have to change in order to have a new item type that draws from a json file.
 

Drive

Horror lover
Member
Joined
Jan 14, 2017
Messages
11
Reaction score
3
First Language
Spanish
Primarily Uses
RMMZ
So this would basically involve a plugin where you expand DataManager's initialisation to create a $dataFoods global variable, and you'd then have to write an isFood function, add a check for that to Game_Party's itemContainer function...there are a number of things you'd have to change in order to have a new item type that draws from a json file.
The lines of code I have added are as follows, although I am not 100% sure if they are correct. I'm also getting used to the Javascript Syntax while tinkering around because I'm a Java student

managers.js

JavaScript:
DataManager.isFood = function(item){
    return item && $dataFood.includes(item);
}

objects.js

JavaScript:
Game_Item.prototype.isFood = function(){
    return this._dataClass === "cook";
}

Game_Item.prototype.object = function() {
    if (this.isSkill()) {
        return $dataSkills[this._itemId];
    } else if (this.isItem()) {
        return $dataItems[this._itemId];
    } else if (this.isWeapon()) {
        return $dataWeapons[this._itemId];
    } else if (this.isArmor()) {
        return $dataArmors[this._itemId];
    }  else if (this.isFood()){
        return $dataFoods[this._itemId];
    }  else {
        return null;
    }
};

Game_Item.prototype.setObject = function(item) {
    if (DataManager.isSkill(item)) {
        this._dataClass = "skill";
    } else if (DataManager.isItem(item)) {
        this._dataClass = "item";
    } else if (DataManager.isWeapon(item)) {
        this._dataClass = "weapon";
    } else if (DataManager.isArmor(item)) {
        this._dataClass = "armor";
    } else if (DataManager.isFood(item)){
        this._dataClass = "cook";
    } else {
        this._dataClass = "";
    }
    this._itemId = item ? item.id : 0;
};

Game_Enemy.prototype.itemObject = function(kind, dataId) {
    if (kind === 1) {
        return $dataItems[dataId];
    } else if (kind === 2) {
        return $dataWeapons[dataId];
    } else if (kind === 3) {
        return $dataArmors[dataId];
    } else if (kind === 4){
        return $dataFoods[dataId];
    } else {
        return null;
    }
};

Game_Party.prototype.foods = function(){
    return Object.keys(this._foods).map(id => $dataFoods[id]);
}
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,708
Reaction score
2,813
First Language
English
Primarily Uses
RMMZ
Decent start, but you're forgetting to add the creation of $dataFoods in DataManager.

Also keep in mind that some of the branches based on kind draw their values from something the developer set in the database, and you don't have that for your food type, so you'll have to work around those cases.
 

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
301
Reaction score
160
First Language
English
Primarily Uses
RMMZ
Indeed. You would need to initialize the variable which can be as simple as putting this above your IIFE (or within might work too):
JavaScript:
// Outside of IIFE (hence "global" variable):
$dataFoods = null;

// Inside or outshould (should work - but I put mine outside IIFE for this)
DataManager._databaseFiles.push(
    { name: "$dataFoods", src: "Food.json" }
);

The internal RM manager will handle loading it up
 
Last edited:

Latest Threads

Latest Profile Posts

Got distracted... again. So now I'm on project.... 5? 6? I can't even remember off the top of my head how many plugins I have in the works. Though I blame the latest two on a coding youtuber I watch occasionally. He codes in C++ but walks through the process well enough that it inspires me to do similar things for JS plugins. So... blame him for my lack of activity. lol
It's my birthday today! Mom and I went to my favorite Japanese restaurant for lunch and they gave me a Japanese dessert as a birthday surprise. Their salad is SO GOOD. Now we're back home chilling!
Game Theory is great to practice and all... but it is zero substitute for playtesting a game and saying, "Am I having fun?".
Orbiting the cactus
unborn180.png
Here's this for an idea I might do: A Touhou RPG set in the universe of the Hoi4 mod "The New Order: Last Days of Europe". Expect BurgSys Yukari, the Great Fairy Trial, and funni clock Flandre

Forum statistics

Threads
113,754
Messages
1,077,194
Members
147,785
Latest member
keewhee
Top