MZ How do I create a new Item Sub Category?

My problem is the following: I have a category of items which do all work kinda similar with changed parameters only. Now I think that the way I implemented them is kinda weird, as the effects are all in the damage formula bar, where they don't really belong. This leads to weird side effects, like the usability outside a battle. Now, while I actually have now some experience with JavaScript, analyzing what I exactly need to change feels kinda impossible. There are just so many functions and different things that are all called items inside the code that I feel overwhelmed and just don't know where to start. My question is:

- How do I make a new subcategory of items that have a similar function with different parameters? (I Imagine it like making an extension of a class in Java)
- What are the methods I need to overwrite for this subcategory?
- What are the most important methods of Items in RPG maker MZ that I need to understand?
- Why does the code of the RPG maker mix Items with other things like skills?
Some of this can't really be addressed because it's so high level and conceptual. Not knowing what specific effects you're trying to achieve, we can't tell you how to implement it.

Generally speaking, a lot can be taken out of damage formulae and put into VisuStella notetags (see Mechanics-Related in the Battle Core).

- How do I make a new subcategory of items that have a similar function with different parameters? (I Imagine it like making an extension of a class in Java)
You probably do not need to in order to achieve what you want.

- Why does the code of the RPG maker mix Items with other things like skills?
It makes logical sense, since they all share fundamental functionality. Look at any RPG you've played - items and skills do the same things. It's only a difference of resource management.

You can see it in the database, too - item and skill entries in the database are nearly identical.

So why wouldn't you make them use the same code? It would make less sense to duplicate large portions of code just because these two things are called different words in the game. The only real difference at all is when using it in the menu outside of battle - you do not typically have a "using character" for items.
Well, the core code is not intuitive here. I looked for a "getItemType" function in Game_Item, but there's none. What you can do is search for "itypeId" across the core code (rmmz_objects, rmmz_windows, ...), as this is the attribute in any item to set its type. You can look into data/items.json to get a feeling.

So I found some hits in rmmz_windows. I think you need to alias (you should google what aliasing in javascript is) all functions that use "itypeId".

Yeah, in the Java world, the class "item" would control whether the Window class should draw it or not, so making a new class to derive from the base class sounds promising. However, the RPG Maker's core code handles the flow differently.

The most popular way to add a new item type is by understanding "NoteTags" (Example see here: http://www.yanfly.moe/wiki/Items_and_Equips_Core_VisuStella_MZ#Notetags)

The core code automatically parses the tags and converts them into a JSON object called "meta". So you can add a tag to any item like this:

Code:
<Item Type: Material>

Let's alias a method from rmmz_windows in your plugin:

Code:
const alias = Window_ItemList.prototype.includes;
Window_ItemList.prototype.includes = function(item) {
  if (item.meta["Item Type"] == "material") {
    return TRUE OR FALSE; // here you can write your own JS code
  }
  return alias.call(this, item)

Now you have learned about NoteTags and aliasing core methods. After that, I recommend you to look into rmmz_scenes, rmmz_windows, and rmmz_objects to learn how all the components interact with each other.
If you are using the VisuStella (free) Core plugins, you can do this in the parameter settings of Items and Equip Core.
Let's alias a method from rmmz_windows in your plugin:

Code:
const alias = Window_ItemList.prototype.includes;
Window_ItemList.prototype.includes = function(item) {
  if (item.meta["Item Type"] == "material") {
    return TRUE OR FALSE; // here you can write your own JS code
  }
  return alias.call(this, item)

Now you have learned about NoteTags and aliasing core methods. After that, I recommend you to look into rmmz_scenes, rmmz_windows, and rmmz_objects to learn how all the components interact with each other.
I think I already saw that thing with the alias methods in other posts, where it's used to ensure compatibility. To be honest, it looks so weird for me that I am just not confident enough to use that. I tried it, but then the game crashed for some reason and I never touched it again. I think I need to understand better what actually happens here. Correct me if I am wrong:
Alias saves the function Window_ItemList.prototype.includes, then you overwrite the original method with the stuff you want to add, and then you call alias and give him your own function and the item as parameters... right?

Probably I just need to get used to it.

You probably do not need to in order to achieve what you want.
Probably, probably, if I think about it, I could also do it with database Inheritance (http://www.yanfly.moe/wiki/Database_Inheritance_VisuStella_MZ) and some of the JS notetags, But I have to admit that I kind of shy away from them, simply because I then write code in a "non-development environment", which makes finding bugs even more difficult.
Some of this can't really be addressed because it's so high level and conceptual. Not knowing what specific effects you're trying to achieve, we can't tell you how to implement it.
Well, I guess understanding what's happening is not exactly a bad thing for me, because if I am really focused on achieving something with a specific way, it can happen that I write code that just rips apart anything with brute force just so that the compiler stops throwing errors at me.

it's actually not really complicated, I just try to make items that cost TP and give HP, MP and EXP.
The problem is just that it doesn't fit into the damage typings because they are all only one type of damage.
it's actually not really complicated, I just try to make items that cost TP and give HP, MP and EXP.
The problem is just that it doesn't fit into the damage typings because they are all only one type of damage.
You shouldn't need any code for this except the TP cost portion, because the editor doesn't let you attach costs to items.

So you can either try to do that, or an easier way to do it is to just use the VisuStella Skills and States.

Make a skill that does the HP/MP/EXP gain and removes the item with a common event.

Give it a custom cost notetag <Elixir Cost: 1> or whatever your item is called.

And then you only want to see that skill when you have the item, so
Code:
<JS Skill Visible>
visible=$gameParty.numItems($dataItems[ID]);
</JS Skill Visible>
where ID is the ID of your elixir or whatever. In this scenario, your item would not be a consumable.

You could change it to be a consumable item that teaches a skill and turns a switch on, which is referenced by the switch visibility notetag. Then using the skill turns the switch back off so it can only be used once.

I just think doing something like this is way easier than making a new class of consumable item that checks for TP costs and why on Earth database inheritance...?
I just think doing something like this is way easier than making a new class of consumable item that checks for TP costs and why on Earth database inheritance...?
thats just because of the notetag copy function, its technically not needed, but helpful for consistency.

You shouldn't need any code for this except the TP cost portion, because the editor doesn't let you attach costs to items.
yeah, thats kinda the crux, which is why so far thats the only point where i worked with the js notetags. it's not like my current solution doesn't work, it feels just like it's not a really robust solution.
I think I already saw that thing with the alias methods in other posts, where it's used to ensure compatibility. To be honest, it looks so weird for me that I am just not confident enough to use that. I tried it, but then the game crashed for some reason and I never touched it again. I think I need to understand better what actually happens here. Correct me if I am wrong:
Alias saves the function Window_ItemList.prototype.includes, then you overwrite the original method with the stuff you want to add, and then you call alias and give him your own function and the item as parameters... right?

Probably I just need to get used to it.
Exactly. You override a function while you keep the original so you can call it again. Aliasing is one of the essential tools for RPG Maker plugin developers, as they enable you to inject your code while the core code is still invoked.

then you call alias and give him your own function and the item as parameters... right?
As you can see, you call the aliased method, which is a reference to the core code, only if your custom code results negative. In other words, your item is not a "Material", but what is it then? A skill? A weapon? This is why we then call the alias / original code.

Please get familiar with aliasing. You can alias any method, getters, setters, voids (e.g., an "update" function)...
Exactly. You override a function while you keep the original so you can call it again. Aliasing is one of the essential tools for RPG Maker plugin developers, as they enable you to inject your code while the core code is still invoked.


As you can see, you call the aliased method, which is a reference to the core code, only if your custom code results negative. In other words, your item is not a "Material", but what is it then? A skill? A weapon? This is why we then call the alias / original code.

Please get familiar with aliasing. You can alias any method, getters, setters, voids (e.g., an "update" function)...
Found out why it didn't work for me, I needed to use call (this) instead of just use the method directly.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-create-a-new-item-sub-category.154421/