How to make skill-learning items be restricted by class?

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
I feel like this is kind of complicated, so let me explain it step by step.

I want to have three classes of Magic in my game, but I want them all to fall under the general category of Magic. Specifically, there's Offensive Magic, Supportive Magic and Utility Magic, but I only want there to be one universal magic category. Er... let me explain...

Let's say that you go to a Magic Shop to buy some Magic Books that can teach you... well... magic. Our Hero can learn any of the three kinds of magic, so whether you buy Fire (Offensive), Cure (Supportive) or Teleport (Utility), you can use that magic book on the Hero no matter what. They can learn anything at all! And when you go into battle, all of those spells will be neatly placed under a single Magic menu.

But the Wizard in your party can ONLY use Offensive Magic like Fire. He's better at offensive magic than other characters, thanks to his high magic stat, so it's not really a drawback that he can only learn that one kind of spell. So if you buy the Cure spell from the magic shop, you'll just get an error sound if you try and use that book on him - he'll only be able to learn Fire out of those three spells. But the thing is... they're all considered "Magic" in the database, not split into three categories internally. But somehow... he can only learn some of those spells - the Offensive ones, and nothing else.

Some characters will be able to learn two different types, such as Supportive AND Utility (their stats would generally be lower than those of the specialized users of those types of magic), though only the Hero can learn all 3. But the point is, I need to be able to have each character only have ONE Magic heading in their battle menu, regardless of how many types of magic they can actually learn.

So uh... how can I achieve this?
 

KawaiiKid

Local Weeb
Veteran
Joined
Oct 13, 2015
Messages
389
Reaction score
214
First Language
English
Primarily Uses
RMMV
Go to types, and add your skill types. "offensive magic, support magic, utility magic. Then when you make spells, under type, choose that type. Go to classes, and on the right side double click traits, go to the skill page, and add skill type: whatever type you want that class to be able to use.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Go to types, and add your skill types. "offensive magic, support magic, utility magic. Then when you make spells, under type, choose that type. Go to classes, and on the right side double click traits, go to the skill page, and add skill type: whatever type you want that class to be able to use.

But that won't work. Or at least I'm pretty sure it won't.

I mean, that's how you'd normally do it, but it won't work for this scenario because I need each spell to fall under the same universal Magic category so that there's only one Magic menu per character in battle. For example, if the Hero had Fire, Cure and Teleport, then with your suggestion, their battle menu would read something like:

Attack
Offensive Magic
Supportive Magic
Utility Magic
Item
Defend

...When I want it to read:
Attack
Magic
Item
Defend

Regardless of which kind of Magic each character can use.
 

Sword_of_Dusk

Ace Attorney
Veteran
Joined
Sep 13, 2015
Messages
732
Reaction score
721
First Language
English
Primarily Uses
RMMV
You'll need a plugin then.
Use that one, and make all magic just under the type "magic". Then go under each class and assign which spells they can learn.
We're on the MZ support forum, and I don't know if Yanfly's MV Skill Learn works in MZ.

@TakumaGao Try this if you intend to go with KawaiiKid's option, although you can't hide whole skill types. And then I don't know if you were gunning for learning skills in this way.

Edit: Right, forgot the items part of this problem. I know nothing offhand that I'm sure works with MZ, but I'll hunt around when I get a moment.
 
Last edited:

KawaiiKid

Local Weeb
Veteran
Joined
Oct 13, 2015
Messages
389
Reaction score
214
First Language
English
Primarily Uses
RMMV
We're on the MZ support forum, and I don't know if Yanfly's MV Skill Learn works in MZ.

@TakumaGao Try this if you intend to go with KawaiiKid's option, although you can't hide whole skill types. And then I don't know if you were gunning for learning skills in this way.

Edit: Right, forgot the items part of this problem. I know nothing offhand that I'm sure works with MZ, but I'll hunt around when I get a moment.
Right, I forgot a lot of people don't know about Fossil. Here is that, just incase:https://forums.rpgmakerweb.com/inde...-plugins-in-mz-300-plugins-fossilized.135523/
That let's you use the majority of MV plugins in MZ. I always suggest MV plugins for MZ though and just use them with fossil, since Visustella charges more for a single plugin than you would get for yanfly's old library of $5 for double the entirety of Visustella. Most of the plugins work exactly the same.
 

Sword_of_Dusk

Ace Attorney
Veteran
Joined
Sep 13, 2015
Messages
732
Reaction score
721
First Language
English
Primarily Uses
RMMV
Right, I forgot a lot of people don't know about Fossil. Here is that, just incase:https://forums.rpgmakerweb.com/inde...-plugins-in-mz-300-plugins-fossilized.135523/
That let's you use the majority of MV plugins in MZ. I always suggest MV plugins for MZ though and just use them with fossil, since Visustella charges more for a single plugin than you would get for yanfly's old library of $5 for double the entirety of Visustella. Most of the plugins work exactly the same.
I'm actually aware of FOSSIL. I only posted the MZ version because it bundles a bunch of things into it. Besides, it doesn't actually solve OP's problem.
 

KawaiiKid

Local Weeb
Veteran
Joined
Oct 13, 2015
Messages
389
Reaction score
214
First Language
English
Primarily Uses
RMMV
I'm actually aware of FOSSIL. I only posted the MZ version because it bundles a bunch of things into it. Besides, it doesn't actually solve OP's problem.
I was referring to op not knowing about fossil. And how does the plugin I linked not directly adress what he asked? It does exactly what he wants to do?
 

Sword_of_Dusk

Ace Attorney
Veteran
Joined
Sep 13, 2015
Messages
732
Reaction score
721
First Language
English
Primarily Uses
RMMV
I was referring to op not knowing about fossil. And how does the plugin I linked not directly adress what he asked? It does exactly what he wants to do?
Ah, I had forgotten items can be used as a cost.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Okay so... I just looked through those plugins and... I don't think either of those are what I'm looking for...

I want to create an Item, that is used on Actors, so that they can learn skills, but that is restricted to only being used on certain characters, despite the fact that they can use the correct skill type.


1656538520873.png

Basically this is what I want to do. I want to have this item teach the Fire skill when used on a character, but ONLY certain characters that are allowed to learn Offensive magic. All magic is filed into the same menu/skill category, so I can't restrict it based on skill category.

Take the main character for example. She can learn *any* kind of magic (and she's the only one capable of doing this), so her Magic menu in battle will look like this:

1656538672554.png

See? It's all dumped into one menu, one skill category. So for her, I could take any of these spellbook items and give them to her. BUT if I wanted to teach a spell in the same manner to my Wizard, he could ONLY accept the Fire spell because he can ONLY learn spells that are considered Offensive (red), but NOT spells that are considered Supportive (blue) or Utility (green), even though he has the same Magic skill category that the main character does.

So... yeah, understand now? Any ideas how I can achieve this?
 
Last edited:

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Okay guys, I think I've *kind of* had a breakthrough.

What I did first was I made individual Magic skill types for each character. They all say Magic, but each one is a separate category.

Then, I made multiple identical Fire skills, with the only difference being that each one is assigned to the unique Magic category per character. So for example, there's a Fire that can only be used by the Heroine's Magic type, and a Fire that can only be used by the Wizard's Magic type.

Then, I took that Fire Book item and made it so that it will teach a character every single variant of Fire, for each skill type. But of course, if they can't actually use it, it won't show up in their skill list, so each character only gets 1 version of Fire! So it works now... right?

Well... not really. Because see... there's still no way to stop from being able to use the Fire Book item on a character that can't learn any variant of Fire, or that has already learned the skill previously. For example, if I use the Fire Book on the Knight, who can't use *any* magic, the item is still consumed from the inventory, and if you have already taught the Heroine the Fire spell, you can still waste another one on her even though it shouldn't let you. So... I've figured out how to make the Books teach the right skills to the right characters... but I have no idea how to keep the game from allowing you to use the Books on an invalid character.

So... What do I do?
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,990
Reaction score
3,170
First Language
English
Primarily Uses
RMMV
Save this as a *.js file and include it as a plugin.
Code:
Game_BattlerBase.prototype.meetsUsableItemConditions = function(item) {
if ($dataItems[item.id].meta.notClass && $dataItems[item.id].meta.notClass.includes(this.currentClass().id))
    return false;

    return this.canMove() && this.isOccasionOk(item);
};

Then you put the notetag <notClass: [id1, id2, id3]> into your item and it should give you the error buzzer if you try to use it on one of the classes you listed in the brackets. It can be as many IDs in there as you want to restrict.

I did not test this in a game, let me know if it doesn't work correctly.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Save this as a *.js file and include it as a plugin.
Code:
Game_BattlerBase.prototype.meetsUsableItemConditions = function(item) {
if ($dataItems[item.id].meta.notClass && $dataItems[item.id].meta.notClass.includes(this.currentClass().id))
    return false;

    return this.canMove() && this.isOccasionOk(item);
};

Then you put the notetag <notClass: [id1, id2, id3]> into your item and it should give you the error buzzer if you try to use it on one of the classes you listed in the brackets. It can be as many IDs in there as you want to restrict.

I did not test this in a game, let me know if it doesn't work correctly.

It doesn't work :(

1. The item can be used on every character, regardless of what I put into the notetags.
2. However it DOES cause a buzzer to occur if you use it on someone that already had the book used on them! So that's a success at least!
3. However... as soon as you enter the skill menu after using the item on them... the game crashes lol
 

KawaiiKid

Local Weeb
Veteran
Joined
Oct 13, 2015
Messages
389
Reaction score
214
First Language
English
Primarily Uses
RMMV
Suggesting another MV plugin, but worth testing if you have fossil:
This will allow you to put in a notetag that makes items usable only by certain classes, or actors, or anything really.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Suggesting another MV plugin, but worth testing if you have fossil:
This will allow you to put in a notetag that makes items usable only by certain classes, or actors, or anything really.

Hmm... but that won't stop you from using the item if you already know the skill it teaches, will it?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,990
Reaction score
3,170
First Language
English
Primarily Uses
RMMV
1. The item can be used on every character, regardless of what I put into the notetags.
2. However it DOES cause a buzzer to occur if you use it on someone that already had the book used on them! So that's a success at least!
3. However... as soon as you enter the skill menu after using the item on them... the game crashes lol
That's all very weird...this shouldn't have any effect on what has been used on an actor, and it shouldn't have anything to do with the skill menu.

Why didn't you give any information about the crash? It should say something off the bat, and if you press F8 and go to the Console tab, you should be able to screenshot the full error trace.

I did a quick test and it doesn't work because the value is stored as a string, not numbers. So simply adding toString() after currentClass().id should help with that, but it still fails in my testing.

Perhaps that function just doesn't get used to determine eligibility when using items from the menu.
Suggesting another MV plugin, but worth testing if you have fossil:
This will allow you to put in a notetag that makes items usable only by certain classes, or actors, or anything really.
As far as I know, this is also not applicable. This enables you to set requirements for whether a battler can use an item in battle. When using an item in the menu, the game has no concept of an actor "using" that item.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
That's all very weird...this shouldn't have any effect on what has been used on an actor, and it shouldn't have anything to do with the skill menu.

Why didn't you give any information about the crash? It should say something off the bat, and if you press F8 and go to the Console tab, you should be able to screenshot the full error trace.

I did a quick test and it doesn't work because the value is stored as a string, not numbers. So simply adding toString() after currentClass().id should help with that, but it still fails in my testing.

Perhaps that function just doesn't get used to determine eligibility when using items from the menu.

As far as I know, this is also not applicable. This enables you to set requirements for whether a battler can use an item in battle. When using an item in the menu, the game has no concept of an actor "using" that item.

Oops, didn't think of screenshotting the error message! Is there a way I can pull up old error messages? I already deleted the script and set everything back to the way that it was before.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,990
Reaction score
3,170
First Language
English
Primarily Uses
RMMV
Okay, so this works in my testing.
Code:
Game_Action.prototype.hasItemAnyValidEffects = function(target) {
if ($dataItems[this.item().id].meta.notClass && $dataItems[this.item().id].meta.notClass.includes(target.currentClass().id.toString()))
    return false;

return this.item().effects.some(effect =>
        this.testItemEffect(target, effect)
    );
};

You can make the notetags exactly like before.

I still can't speak to your prior errors. It should already prevent them from using the item if they already have the skill learned. And nothing in here should be able to cause a crash. So if something like that comes up, there may be something else wrong in your project.
 

TakumaGao

Veteran
Veteran
Joined
May 22, 2019
Messages
193
Reaction score
50
First Language
English
Primarily Uses
RMMZ
Okay, so this works in my testing.
Code:
Game_Action.prototype.hasItemAnyValidEffects = function(target) {
if ($dataItems[this.item().id].meta.notClass && $dataItems[this.item().id].meta.notClass.includes(target.currentClass().id.toString()))
    return false;

return this.item().effects.some(effect =>
        this.testItemEffect(target, effect)
    );
};

You can make the notetags exactly like before.

I still can't speak to your prior errors. It should already prevent them from using the item if they already have the skill learned. And nothing in here should be able to cause a crash. So if something like that comes up, there may be something else wrong in your project.

This works now! Thank you so much! You're a lifesaver! Sorry for being kind of dumb lol

Though there is one minor oddity, though I'm not sure if this is a plugin thing or an RPG Maker MZ engine thing...

If I put 2 Fire Books in my inventory, and then use them on 2 characters, it doesn't immediately close out of the character selection scene. I can't use more than I have, but shouldn't it go back to the main item menu once all of the items have been expended? Is that normal behavior for MZ or is it due to the script?
 

Latest Threads

Latest Profile Posts

ScreenShot_8_10_2022_7_15_21.png
Looks like Mike's got a new party member in Robbi...

Calf survival story with a happy ending.
well here's that concept art!
WIN_20220812_16_53_56_Pro (2).jpg
Whaddya think? Name suggestions?
Some character designs of 'Coin Locker'.
(there may be some future designs along the process.)


Untitled1294_20220813055849.png
1660339609612.png
Really need to come up with better names for my folders.

Forum statistics

Threads
124,456
Messages
1,163,796
Members
163,276
Latest member
Ciberfreak
Top