MZ Add items using scripting ?

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?
$gameParty.gainItem(item, quantity)
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.
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.
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
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.
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]);
}
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.
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

Original thread: https://forums.rpgmakerweb.com/threads/add-items-using-scripting.137702/