MZ Help to make LEVEL UP like in Might and Magic VII (you have the XP, but must go to a trainer to lvl up!)

Hi! I'm not thaaat good in RMMZ javascript, but I was looking for some way to alter the level up system for something like the old and gold Might and Magic VII For Blood and Honor (oh man, I loved that!).
In that game, you do adquire xp from slaying monsters and fulfilling quests, but you do not automatically gain the next level number until you go to a trainer in the town and pay for it.

So, I highly suspect that my answer lays in the function Game_Actor.prototype.changeExp, that calls the Game_Actor.prototype.levelUp() function. All sounds good until I stumble in the crypto code from VisuStella Core Engine that seems to have it's own levelUp function, since the code go there when a debug in the console, but, as you know, it's encrypted.

I'm almosting overwriting this back to the original levelUp() function from objects.js, but in the meantime I'll be doing my testings, I wondered if some of you know if what the VisuStella CoreEngine do with the levelup function is something critical to that plugin.
In the VisuStella wiki I saw things like restore HP/MP and maxLevel... maybe it'll be messed up, I think.
So, I highly suspect that my answer lays in the function Game_Actor.prototype.changeExp, that calls the Game_Actor.prototype.levelUp() function.
Sounds right.

I wondered if some of you know if what the VisuStella CoreEngine do with the levelup function is something critical to that plugin.
That's really a you question. Review the plugin parameters and how you have it set up - is it something critical to you?

Even if it's not, overwriting it might cause other parts of the code to malfunction, depending on how they modified everything. It's difficult to try to make changes that accommodate a specific plugin when that code is obfuscated.
If anyone does sort this out, I could definitely use this information for MV as well.
That's really a you question. Review the plugin parameters and how you have it set up - is it something critical to you?
Thanks for the insight Turan! You're right... I love the QoL improvements of VisuStella basic plugins and I'm pretending to keep them in my project. I'll do my best to not interfere with them and yet program my own solutions in between.


By the end of the day, I kind of sorted out, because the Game_Actor.prototype.changeExp is not being overwritten by VisuStella, only the Game_Actor.prototype.levelUp. And since my goal was to stop the auto-leveling, I replaced the changeExp and moved the level up part of the code to a new function I created:
JavaScript:
Game_Actor.prototype.changeExp = function(exp, show) { //Replaced function in my plugin
    this._exp[this._classId] = Math.max(exp, 0);
    const lastLevel = this._level;
    const lastSkills = this.skills();
    if (show && this._level > lastLevel) {
        this.displayLevelUp(this.findNewSkills(lastSkills));
    }
    this.refresh();
};
Game_Actor.prototype.ganharNv = function(show) { //New function in my plugin
    const lastLevel = this._level;
    const lastSkills = this.skills();
    if (!this.isMaxLevel() && this.currentExp() >= this.nextLevelExp()) {  //while replaced by if
        this.levelUp();
    }
    if (this.currentExp() < this.currentLevelExp()) { //while replaced by if
        this.levelDown();
    }
    if (show && this._level > lastLevel) {
        this.displayLevelUp(this.findNewSkills(lastSkills));
    }
    this.refresh();
}

And I changed the "whiles" for "ifs" to give only ONE level per time, if the player already accumulated xp for more levels.
I wondered if some of you know if what the VisuStella CoreEngine do with the levelup function is something critical to that plugin
It actually doesn't completely overwrite the levelUp function, it just monkey-patches it to add in some code to restore health and mana upon leveling.

You can safely overwrite the function as long as your plugin is placed higher than CoreEngine in the plugin manager. If you overwrite the function with a plugin that is placed lower than CoreEngine, it won't break anything critical, but you would lose the health/mana restoration upon leveling.

Original thread: https://forums.rpgmakerweb.com/threads/help-to-make-level-up-like-in-might-and-magic-vii-you-have-the-xp-but-must-go-to-a-trainer-to-lvl-up.157853/