Learning how to code an inventory

MrMahus

Villager
Member
Joined
May 18, 2018
Messages
5
Reaction score
0
First Language
French
Primarily Uses
RMMV
Hi everybody !

I'm new on RPG MV and i was intrested in coding my own plugins. I know that there is a tons of plugin made by YEP etc.. But i really want to code them by myself and learn the logic behind coding plugins. I've a little background with 'coding' ( HTML, CSS, C, C++, JAVA, Python ) .

So i'm currently learning how to code a window and a Scene to create a kind of 'inventory' . What i want is a basic window with cells in it and every cell correspond to a 'slot' in your inventory. A cursor can be moved up/down/right/left to select a specific item in a specific slot in this inventory.

To give an idea of what i'm describing, this looks like what i want to code (just look the item stock, we don't care of features "equip" etc.. ) : http://corgi-engine-docs.moremountains.com/images/inventory1.jpg

What i've mad until now is simply code a basic window and a basic scene where i can draw an icon or text.. But i'm stuck : How can i define "slots" in my scene and how can i make them "selectable" ? Here is the "draft" code i've for the moment :

function Window_Sample() {
this.initialize.apply(this, arguments);
}

Window_Sample.prototype = Object.create(Window_Base.prototype);
Window_Sample.prototype.constructor = Window_Sample;

Window_Sample.prototype.initialize = function(x, y) {
var width = this.windowWidth();
var height = this.windowHeight();
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.refresh();
};

Window_Sample.prototype.windowWidth = function() {
return Graphics.width / 2;
};

Window_Sample.prototype.windowHeight = function() {
return Graphics.height / 2;
};

Window_Sample.prototype.refresh = function() {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
this.drawIcon(2, 0, 0);
this.drawIcon(3, 50, 0);

};

Window_Sample.prototype.open = function() {
this.refresh();
Window_Base.prototype.open.call(this);
};

function Sample_Scene() {
this.initialize.apply(this, arguments);
}

Sample_Scene.prototype = Object.create(Scene_MenuBase.prototype);
Sample_Scene.prototype.constructor = Sample_Scene;

Sample_Scene.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};

Sample_Scene.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
//create the window
this._sampleWindow = new Window_Sample(0,0);
this._sampleWindow.x = Graphics.width / 2 - 100;
this._sampleWindow.y = Graphics.height / 2 - 100;
// add window
this.addWindow(this._sampleWindow)
};

Sample_Scene.prototype.start = function() {
Scene_MenuBase.prototype.start.call(this);

}

Sample_Scene.prototype.update = function(){
Scene_MenuBase.prototype.update.call(this)
if (Input.isTriggered('cancel')){
SoundManager.playCancel();
SceneManager.goto(Scene_Map);
}

}

Any help will be appreciated :) !
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Read the game code. That is the best way to learn. Why don't you try modding the default game code first? For example the default inventory is a good starting point. You can find it in the core scripts, more precisely rpg_windows.
 

MrMahus

Villager
Member
Joined
May 18, 2018
Messages
5
Reaction score
0
First Language
French
Primarily Uses
RMMV
Okay thank you i'll try understand and manipulate the game code first ! :)
 

MrMahus

Villager
Member
Joined
May 18, 2018
Messages
5
Reaction score
0
First Language
French
Primarily Uses
RMMV
I've found the Window_ItemCategory which seems to handle the real inventory part of the game ( i mean the screen where selectable items can be seen and used ) But i don't really understand how modify the selector or the "Cursor" and i don't know how to create a certain number of "slots"
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Cursor is defined in earlier classes, I believe Window_Selectable.
Slots are handled via setHandler.
 

MrMahus

Villager
Member
Joined
May 18, 2018
Messages
5
Reaction score
0
First Language
French
Primarily Uses
RMMV
I've tried but i don't understand the logic behind this architecture of code. What i want is simple I assume but i can't do it i really need an example of code for

- Construct window
- Place an inventory scene on it
- Define some rows and cols each XX pixels to add a icon for each item on the inventory
- Draw a cursor on this scene
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Item drawing is handled via drawItem and drawAllItems methods. Cursor by drawCursor. Although the window first needs to be activated and I believe a selection needs to be made as well. Rows and cols are defined via maxRows and maxCols.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,470
Members
137,821
Latest member
Capterson
Top