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

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,747
Reaction score
11,349
First Language
English
Primarily Uses
RMMV
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?
Isn't it really easy to test that by disabling the plugin and using some items? O__o

But no, default MZ does not close the window automatically when you run out of items.
 

TakumaGao

Regular
Regular
Joined
May 22, 2019
Messages
294
Reaction score
100
First Language
English
Primarily Uses
RMMZ
Isn't it really easy to test that by disabling the plugin and using some items? O__o

But no, default MZ does not close the window automatically when you run out of items.

You raise a good point lol. But at least now I know that it's nothing wrong! :p Thanks again!
 

KawaiiKid

Local Weeb
Regular
Joined
Oct 13, 2015
Messages
507
Reaction score
324
First Language
English
Primarily Uses
RMMV
You can also do this with common events. Just make the item when used trigger a common event and then have a conditional branch in the common event triggered that requires the actor or whoever is using it to be a certain class and if they are it teaches them the skill and if they aren't well you can do whatever you want such as an error message or something
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,747
Reaction score
11,349
First Language
English
Primarily Uses
RMMV
You can also do this with common events.
Only kind of. Common events trigger after the item is used and consumed, so the player of the game would select the target, the item goes away.

You could make that common event refund the item so it comes back, but it's still not the same experience in the interface as when you try to use, say, a potion on a target that can't receive healing, and it simply doesn't let you.

I'm not saying that's a terrible thing to do, but from a software design perspective it's better to have parts of the game (especially the UI) react in predictable ways.

If you wanted to event the whole system and it departs from the item menu entirely into its own interface, I think that would be better.
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
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.


I have this code installed as a plugin, and when I put this on the notetag of a skill book item it blocks every single class not just the 3. What is the correct way to do this? Thanks bud.


DOES NOT WORK: <notClass: [13,24,35]>
I have also tried: <notClass: [id13, id24, id35]>


MZ project
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,747
Reaction score
11,349
First Language
English
Primarily Uses
RMMV
I have this code installed as a plugin, and when I put this on the notetag of a skill book item it blocks every single class not just the 3.
I'm not sure what to tell you. As I said in the post you quoted, it works in my tests :wink:

The first thing you did is the correct syntax, you would never type the letters "id."

I didn't test this with any other plugins, so if you're using anything that relates to items at all it could be screwing with it.

If you're not using any other plugins and it's not working for you in a vanilla project, then put up some screenshots of the item and your classes that the actors have.

Make sure any time you change anything in your project that you're starting a new play test, not loading a save.
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
I'm not sure what to tell you. As I said in the post you quoted, it works in my tests :wink:

The first thing you did is the correct syntax, you would never type the letters "id."

I didn't test this with any other plugins, so if you're using anything that relates to items at all it could be screwing with it.

If you're not using any other plugins and it's not working for you in a vanilla project, then put up some screenshots of the item and your classes that the actors have.

Make sure any time you change anything in your project that you're starting a new play test, not loading a save.
Tested it in both a new game project and my project and here are the results:

It appears single digit numbers work fine for classes. However, when you get to double digits things get wonky.

My current class list is Warrior 2, Shaman 13, Rogue 24, Elementalist 35. I have noticed if I put: <notClass: [24]>

Not only does Rogue get blocked, but so does Warrior. This seems to happen because it's reading the 2 and the 24 together instead of just 24. I tried quotations and it does not work. I.E. <notClass: ["24"]>

I am separating class types so that's why the numbers are spread atm. I plan to add more classes based on those types.

EDIT: Btw, none of my plugins are interfering with it. I tested all of them each one by one. And the new project does the exact same thing, so it has to be the plugin script. Create some classes in the double digits that have similar numbers and you'll see what I mean. 1/2/4/24 is a good test using <notClass: [24]> - the only character that can accept the skill is 1.

1661916998682.png
 
Last edited:

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,747
Reaction score
11,349
First Language
English
Primarily Uses
RMMV
I tried quotations and it does not work. I.E. <notClass: ["24"]>
That would never work, you should always follow notetag formats as written. Incidentally, you also didn't do this by omitting the spaces that I showed in my example notetag, but in this case that didn't hurt anything (in some plugins, it could).

Not only does Rogue get blocked, but so does Warrior. This seems to happen because it's reading the 2 and the 24 together instead of just 24.
Good call, that would be exactly the reason. So, modify the code as below:

Code:
Game_Action.prototype.hasItemAnyValidEffects = function(target) {
if ($dataItems[this.item().id].meta.notClass)
{
    var classArray=$dataItems[this.item().id].meta.notClass.split(',').map(element => element=Number(element));

    if (classArray.includes(target.currentClass().id))
        return false;
}

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

I haven't tested this with an in-game setup, but it works in my testing in the console. Let me know if you have any problems.

Please note this changes the format of the notetag from what I posted before: the class IDs must be separated by commas but no spaces, and the brackets are no longer used. e.g. <notClass: 2,24,35,64>
 

PaladinDude

Villager
Member
Joined
Aug 14, 2022
Messages
10
Reaction score
4
First Language
English
Primarily Uses
RMMZ
That would never work, you should always follow notetag formats as written. Incidentally, you also didn't do this by omitting the spaces that I showed in my example notetag, but in this case that didn't hurt anything (in some plugins, it could).


Good call, that would be exactly the reason. So, modify the code as below:

Code:
Game_Action.prototype.hasItemAnyValidEffects = function(target) {
if ($dataItems[this.item().id].meta.notClass)
{
    var classArray=$dataItems[this.item().id].meta.notClass.split(',').map(element => element=Number(element));

    if (classArray.includes(target.currentClass().id))
        return false;
}

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

I haven't tested this with an in-game setup, but it works in my testing in the console. Let me know if you have any problems.

Please note this changes the format of the notetag from what I posted before: the class IDs must be separated by commas but no spaces, and the brackets are no longer used. e.g. <notClass: 2,24,35,64>
That got it! Glad I could help with it and squish this bug with you. Thank you once again for your help!
 

Mad_Max

Villager
Member
Joined
Sep 7, 2023
Messages
14
Reaction score
2
First Language
SWE
Primarily Uses
RMMV
I have the same problem but in RMMV. Should this fix work for MV as well?
 

Latest Threads

Latest Profile Posts

Proper localization into several languages on a commercial rpg project might be one of the best signs that the developer is super invested into making the game something high effort, because it ain't cheap to hire good translators.
6 hour drive back from Florida and I was able to plan out 6 mini game Common Events for my Game Jam entry, including a new one I hadn't thought of before. Also had some new ideas to improve what I already have and the post game options to continuing playing the mini games that you liked or didn't get to try. Pretty productive drive.
Christmas decorations! !! :kaojoy:
20231209_114754.jpg
Sophie is already helping dismantle the tree...a month early, of course. Such a helpful kitten!
making horse character for game :D at the end it will have 8 directions puling wagon

2p8jdax

Forum statistics

Threads
136,877
Messages
1,270,970
Members
180,645
Latest member
lietpolshippper
Top