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,711
Reaction score
2,822
First Language
English
Primarily Uses
RMMZ
$gameParty.gainItem(item, quantity)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,371
Reaction score
8,392
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,711
Reaction score
2,822
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,711
Reaction score
2,822
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,711
Reaction score
2,822
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

Ami
need a time to not open my MV,still addicted with new vegas

i wonder what addiction effect behind playing new vegas too much,maybe INT & Science gone worse in many days :D
cdjensen94 wrote on Kaliya's profile.
Are you the one who develops Kaliya's Visual Map Enhancements. If so I desperately need some help. I bought the plugin back a few months. I've only started using it recently.
Cause MP Damage instead of HP, Localization Plugin for Translation | RPG Maker News #112

Here in Fla were are seeing crazy covid spikes and some vaccinated getting bad infections. I had a mild fever on Thurs but it went down fast. How is everyone else doing. Hopefully you are all well. :)
Wish I was better at art, specifically that I was faster at it, bc this one NPC took Several Days to complete! It's gonna take So Extremely Long to do all of the art for my game, never mind writing it... Anyways, here's my gorgon, Hopernica Sthyxis!

57b88732c7abbcd84981dacf624a98495af61fcc.gifv

Forum statistics

Threads
113,832
Messages
1,077,780
Members
147,891
Latest member
TheMeq
Top