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,824
First Language
English
Primarily Uses
RMMZ
$gameParty.gainItem(item, quantity)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,372
Reaction score
8,395
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,824
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,824
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,824
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

IlluminaughtyStore.jpg
:kaojoy:
Welcome to the Illuminaughty store.
Yes... they are "wearing Illuminati branded everything, reclining on huge Illuminati body pillows. Occasionally they'll "teehee" at each other and have pillow fights with Illuminati branded pillows full of hundred dollar bills."
BCj
Working on Escalia again, feels good. Have this overwhelming urge to map as well, but need to get some extra tiles commissioned first :D
Lee Sang wrote on Bandito's profile.
Hi, I've just tried your plugin "Game is Active" and when I tested it on Android, it gave me an error, something about "Cannot read property 'underfined' of underfined.
With my project, I want the player to have access to all the tools they need to get from New Game to Credits as soon as possible; I want the player's progress to only be impeded by the player not knowing how to use the tools the game provides.
Just a little close up shot...
w2xZocX.jpg

Forum statistics

Threads
113,867
Messages
1,078,035
Members
147,957
Latest member
Broskiman1
Top