MV How to access a plugin function from another?

Hello! First time posting, sorry if I'm doing this in the wrong category. RPG maker in use is MV. My final objective is to change the subclass of my actor when equipping/unequipping an item (And to learn! I'm a teacher, and will start an RPG maker project with my students so I have to be prepared for anything).

For this reason I'm trying to modify Ellye's Class-Changing Equipment to work on Yanfly's subclasses. I got it down to:

Game_Actor.prototype.checkForClassChangeFromEquips = function(old_equip, new_equip) { if (old_equip !== null && typeof old_equip === 'object' && typeof old_equip.meta.change_subclass !== 'undefined') { this.actor().changeSubClass(0); } if (new_equip !== null && typeof new_equip === 'object' && typeof new_equip.meta.change_subclass !== 'undefined' && this._classId !== new_equip.meta.change_subclass) { this.changeSubClass(new_equip.meta.change_subclass); } this.releaseUnequippableItems(false); };

but main issue is "This.changeSubClass(blablabla). It says it's not a function.

For reference, the function from Yanfly's I'm trying to use:

Game_Actor.prototype.setSubclass = function(classId) { if (this._classId === classId) return; this.unlockClass(classId); this._subclassId = classId; this.refresh(); }; Game_Actor.prototype.changeSubclass = function(classId) { if (this._classId === classId) return; this.unlockClass(classId); if (this._subclassId === classId) classId = 0; this.setSubclass(classId); };

Edit: 8 hours working on this gave me a solution:

this._subclassId = new_equip.meta.change_subclass;

BUT this seems like a ticking bomb that will end up exploding. Even tho it works, I'd like for my first question to be answered if possible; would like to know how that could be done 😀
Hello! First time posting, sorry if I'm doing this in the wrong category. RPG maker in use is MV. My final objective is to change the subclass of my actor when equipping/unequipping an item (And to learn! I'm a teacher, and will start an RPG maker project with my students so I have to be prepared for anything).

For this reason I'm trying to modify Ellye's Class-Changing Equipment to work on Yanfly's subclasses. I got it down to:

Game_Actor.prototype.checkForClassChangeFromEquips = function(old_equip, new_equip) { if (old_equip !== null && typeof old_equip === 'object' && typeof old_equip.meta.change_subclass !== 'undefined') { this.actor().changeSubClass(0); } if (new_equip !== null && typeof new_equip === 'object' && typeof new_equip.meta.change_subclass !== 'undefined' && this._classId !== new_equip.meta.change_subclass) { this.changeSubClass(new_equip.meta.change_subclass); } this.releaseUnequippableItems(false); };

but main issue is "This.changeSubClass(blablabla). It says it's not a function.

For reference, the function from Yanfly's I'm trying to use:

Game_Actor.prototype.setSubclass = function(classId) { if (this._classId === classId) return; this.unlockClass(classId); this._subclassId = classId; this.refresh(); }; Game_Actor.prototype.changeSubclass = function(classId) { if (this._classId === classId) return; this.unlockClass(classId); if (this._subclassId === classId) classId = 0; this.setSubclass(classId); };

Edit: 8 hours working on this gave me a solution:

this._subclassId = new_equip.meta.change_subclass;

BUT this seems like a ticking bomb that will end up exploding. Even tho it works, I'd like for my first question to be answered if possible; would like to know how that could be done 😀
You were very close just a few mistakes...
  • It's because you're using "changeSubClass" and it's supposed to be "changeSubclass" with a lowercase "c"
  • your first part of the function is supposed to be "this" not "this.actor()" since it's already being called from inside the "Game_Actor" class 😉

so it should be this:
JavaScript:
    Game_Actor.prototype.checkForClassChangeFromEquips = function(old_equip, new_equip)
    {
        if (old_equip !== null && typeof old_equip === 'object' && typeof old_equip.meta.change_subclass !== 'undefined'){
            this.changeSubclass(0);
        }
        if (new_equip !== null && typeof new_equip === 'object' && typeof new_equip.meta.change_subclass !== 'undefined' && this._classId !== new_equip.meta.change_subclass){
            this.changeSubclass(new_equip.meta.change_subclass);
        }
        this.releaseUnequippableItems(false);
    };
works great for me 🙂

Sidenote... if you would like to retain the original functionality of Ellye's Class-Changing Equipment being able to change the primary class also. Then you would alias the function instead of overwriting it.

That would be done with something like this:
JavaScript:
    var _Game_Actor_checkForClassChangeFromEquips = Game_Actor.prototype.checkForClassChangeFromEquips;
    Game_Actor.prototype.checkForClassChangeFromEquips = function(old_equip, new_equip){
        _Game_Actor_checkForClassChangeFromEquips.apply(this, arguments);
        if (old_equip !== null && typeof old_equip === 'object' && typeof old_equip.meta.change_subclass !== 'undefined'){
            this.changeSubclass(0);
        }
        if (new_equip !== null && typeof new_equip === 'object' && typeof new_equip.meta.change_subclass !== 'undefined' && this._classId !== new_equip.meta.change_subclass){
            this.changeSubclass(new_equip.meta.change_subclass);
        }
        this.releaseUnequippableItems(false);
    };
I've attached a plugin file for easy reference 🙂

... ... ...

Another very simple way to achieve this if you don't want to make your own plugin file..
My custom script anywhere plugin can be used to make this happen also

Set that up like this:
1652132522306.png

Spoiler: Parameter Setup
Class: Game_Actor
Property of Function: prototype
Function: checkForClassChangeFromEquips
Post Script:
JavaScript:
        if (old_equip !== null && typeof old_equip === 'object' && typeof old_equip.meta.change_subclass !== 'undefined'){
            this.changeSubclass(0);
        }
        if (new_equip !== null && typeof new_equip === 'object' && typeof new_equip.meta.change_subclass !== 'undefined' && this._classId !== new_equip.meta.change_subclass){
            this.changeSubclass(new_equip.meta.change_subclass);
        }
        this.releaseUnequippableItems(false);
Oh my god. I'll have to make a call to my university to tell them to revoke my degree. I just can't believe I'm a programming teacher. On the bright side, I've learnt a lot in this 10 hours I've been researching to solve this issue, so we gucci.

Thanks a lot <3 I'll check your plugin out!
Oh my god. I'll have to make a call to my university to tell them to revoke my degree. I just can't believe I'm a programming teacher. On the bright side, I've learnt a lot in this 10 hours I've been researching to solve this issue, so we gucci.

Thanks a lot <3 I'll check your plugin out!

No prob. Happy to help out! ☺️ 👍

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-access-a-plugin-function-from-another.147421/