[SOLVED] Changeable Max Level

Greetings, everyone!

In my project, characters have Basic Classes that allow them to grow up to level 30.
After that, they must pick one of the Advanced Classes available, where they'll now be able to grow up to level 50.

I'm doing the Class changing part through events, but I'm having a hard time trying to change the max level ingame.

Looking for answers in the forum, I've found some threads, and in one of those, @ATT_Turan provided some code that I compiled in a .js file and added in my game as a plugin.

The code reads as below:

Code:
Game_Actor.prototype.maxLevel = function() {
    switch (this.actorId())
    {
    // List actor IDs and which variable they're associated with
        case 1:
    //Brenda
            return $gameVariables.value(11);
        case 2:
    //Cedric
            return $gameVariables.value(12);
        case 3:
    //Yvanna
            return $gameVariables.value(13);
        case 4:
    //Argus
            return $gameVariables.value(14);
        case 5:
    //Flora
            return $gameVariables.value(15);
        case 6:
    //Corvo
            return $gameVariables.value(16);
        case 7:
    //Mahara
            return $gameVariables.value(17);
        case 8:
    //Makuro
            return $gameVariables.value(18);
        default:
            return 50;
    }
};

Game_Actor.prototype.changeExp = function(exp, show) {
    this._exp[this._classId] = Math.max(exp, 0);
    if (this.isMaxLevel())
        this._exp[this._classId] = this.expForLevel(this._level);

    var lastLevel = this._level;
    var lastSkills = this.skills();
    while (this.currentExp() >= this.nextLevelExp()) {
        this.levelUp();
        if (this.isMaxLevel())
            this._exp[this._classId] = this.expForLevel(this._level);
    }
    while (this.currentExp() < this.currentLevelExp()) {
        this.levelDown();
    }
    if (show && this._level > lastLevel) {
        this.displayLevelUp(this.findNewSkills(lastSkills));
    }
    this.refresh();
};

Unfortunately, it's not working as intended, as characters are able to level up far beyond level 99.
1720361789583.png


Could someone please help me in this endeavor?
The code reads as below

did you just want the basic classes to level to 30 and the advanced ones to 50, or were you going to use the variables as well?

EDIT: also include a screenshot of your plugin manager. if thats your change to the max level function, you may have another plugin further down overwriting it
did you just want the basic classes to level to 30 and the advanced ones to 50, or were you going to use the variables as well?

EDIT: also include a screenshot of your plugin manager. if thats your change to the max level function, you may have another plugin further down overwriting it
Basic Classes 30, Advanced Classes 50.
Some characters don't acquire Advanced Classes, but they are able to reach Level 50.

And the plugin manager screenshot follows:
1720368930078.png
In my project, characters have Basic Classes that allow them to grow up to level 30.
After that, they must pick one of the Advanced Classes available, where they'll now be able to grow up to level 50.
This is not what you show in your code below. Your code has nothing to do with the actor's class, it's looking at their ID.

So which is it? Is the level limit determined by their current class, or by a number in a variable? If it's by the class, it makes no sense to allocate a variable for every actor.


The code reads as below:
This can be done much more efficiently:
Code:
Game_Actor.prototype.maxLevel = function()
{
    return $gameVariables.value(this.actorId() + 10);
};

However, as I'm writing this you confirmed
Basic Classes 30, Advanced Classes 50.
Some characters don't acquire Advanced Classes, but they are able to reach Level 50.
I would suggest something like
Code:
Game_Actor.prototype.maxLevel = function()
{
// I don't know which of your class IDs are basic and which are advanced. This has basic classes
// as 1-19 (e.g. < 20). Change it as appropriate.
    if (this.actorId() <= 8)
        return this.currentClass().id < 20 ? 30 : 50;
    return 50;
};

If you read through the documentation for the VisuStella core, it already has a notetag that modifies an actor's max level. So anything along these lines may not be compatible with that plugin - did you test it with only this plugin active?
This is not what you show in your code below. Your code has nothing to do with the actor's class, it's looking at their ID.

So which is it? Is the level limit determined by their current class, or by a number in a variable? If it's by the class, it makes no sense to allocate a variable for every actor.



This can be done much more efficiently:
Code:
Game_Actor.prototype.maxLevel = function()
{
    return $gameVariables.value(this.actorId() + 10);
};

However, as I'm writing this you confirmed

I would suggest something like
Code:
Game_Actor.prototype.maxLevel = function()
{
// I don't know which of your class IDs are basic and which are advanced. This has basic classes
// as 1-19 (e.g. < 20). Change it as appropriate.
    if (this.actorId() <= 8)
        return this.currentClass().id < 20 ? 30 : 50;
    return 50;
};

If you read through the documentation for the VisuStella core, it already has a notetag that modifies an actor's max level. So anything along these lines may not be compatible with that plugin - did you test it with only this plugin active?
I was using varibles so that, when the character changes their class, I'd simply change their correspondig variable to 50.

And no, I haven't tested with only the forementioned plugin active, gonna give it a try and try to adjust the code accordingly.
I was using varibles so that, when the character changes their class, I'd simply change their correspondig variable to 50.
I think checking their class is much simpler than checking their actor ID then checking a variable (and making sure you correctly set the variable) 😉

If the plugin works on its own and you need any help configuring it for your specific classes, we can do that - but we can't do much if it's incompatible with VisuStella's plugins. Those are distributed with their code obfuscated, so we can't see how to make code that's compatible with them.
1720376386316.png

1720376413934.png

It's working perfectly! Thank you so very much!

Original thread: https://forums.rpgmakerweb.com/threads/solved-changeable-max-level.170106/