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

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,319
Reaction score
8,379
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,707
Reaction score
2,807
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,707
Reaction score
2,807
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,707
Reaction score
2,807
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 Posts

Latest Profile Posts

Exploding Fruits and Rasaks Pixelfarm Assets | RPG Maker News #108

So ghosts can go through walls and stuff, and depending their type (according to fantasy media) they can or can't interact with objects to a certain degree...

So why they don't always fall through floors? Do they always float and sometimes simulate walking? If things go through them how can they hear/see? And why sometimes they have clothing? Do clothes die as well?
my birthday was yesterday...
i feel closer 2 being able 2 get a discount on the kids menu than i do being able to buy booze1627428008986.png
Getting to play your RM game on Steam Deck? How cool is that?
The best among us don't set out to be heroes. They don't want that job. They just set out to do the things nobody else wants to do. Because... someone has to do it.

Forum statistics

Threads
113,704
Messages
1,076,773
Members
147,726
Latest member
Switchboy0815
Top