Learning skills when switching classes?

Discussion in 'RPG Maker MV' started by LpLance, Oct 19, 2016.

  1. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English
    There is a point in my game where your characters will switch (or evolve) to a different class. For example: your mage becomes a sorceress after completing her story events, this grants her extra MP, a slightly higher M.atk stat, and is SUPPOSED to give her access to advanced skills through leveling up. Let's say she could only learn up to fire2 as a mage but can learn fire3 as a sorceress once she reaches the right level, and gains it automatically if she is past that level when changing classes.


    Here's the problem though, I can't get that last part to work. When I initiate the class change she doesn't learn the level-up skills she passed. Anybody know how to fix this?
     
    #1
  2. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    This is the code for changing class:


    Game_Actor.prototype.changeClass = function(classId, keepExp) {
    if (keepExp) {
    this._exp[classId] = this.currentExp();
    }
    this._classId = classId;
    this.changeExp(this._exp[this._classId] || 0, false);
    this.refresh();
    };


    and at this line, it changes the actor EXP:


    this.changeExp(this._exp[this._classId] || 0, false);


    So my guess is that your actor does not have EXP as the new class, does it?


    You probabbly need to set it to keep the exp:


    [​IMG]
     
    Last edited by a moderator: Oct 19, 2016
    #2
  3. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English
    And that would give them the skills they passed? Also, I don't know anything about scripting so this is probably going to be a dumb question, but how do I define the level after changing class? I can't control what level the player will be at.
     
    #3
  4. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Ah sorry I edited the prior post, haven't noticed the exp parameter before, its when you are defining the class change, like the image:



    You will want to mark it
     
    Last edited by a moderator: Oct 19, 2016
    #4
  5. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English


    Nope, I've been doing that from the start. Their levels are fine, just where I want them to be. When the class change occurs they keep the same level curves and exp that they had and that's working perfectly.


    I need them to learn the skills they passed though. Like if the mage learned a sorceress exclusive spell at 30 but didn't become a sorceress until level 31, I would want her to learn it automatically. As things stand, she would skip that skill entirely and not learn it at all.
     
    #5
  6. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Sorry Im not sure about how you re doing it right now.


    Like if it's a sorceress spell, a mage could not learn it, right?


    If the spell is already in the mage list (in the RPG Maker Database), then it's also a mage spell and not sorceress exclusive.


    If it is only on the sorceress list, the mage would not learn while being a mage.


    If the sorceress class is only available after level 31, why do you need the skill to be learned at level 30?


    Maybe this idea wont work with the default RPG Maker skill system.


    I'm sorry, I'm kind of confuse, but I want to help you achieve it [:
     
    #6
  7. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English


    In order:


    Yes, the mage cannot learn sorceress level spells wile still being a mage.


    No, the spell is only listed in the database and in the sorceress's level-up skills, not the mage's.


    Yes, the mage cannot learn those skills until she becomes a sorceress.


    The class change is available via story progression, meaning I don't know what level the character will be at when becoming a sorceress. Those levels I gave there were just an example.


    And even if it doesn't work with the current system, maybe there is a plugin somewhere that can do this.


    However, regardless of the success here, I'm glad you took the time to help.
     
    #7
    Lantiz likes this.
  8. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English
    Actually, I may have just figured it out. Even though I would prefer a cleaner way of doing it...


    My solution is this (In case anyone else wants to do something similar):


    1. Create a variable that is the current level of the player who's class I want to change. (This should all be in one event by the way.)


    2. Have the event switch the character's class to the desired class.


    3. (This is the messy part) Create conditional branches that check the player's level variable we created in step 1. Have it check if the variable is greater than or equal to the level the skill is learned at, if so, have it add the skill. This should be done in descending order, for example: create the branch for a skill learned at level 10 first, then create another branch within that one that checks for level 15 and so on. These checks should continue until you've reached the last skill in the list as the system will correctly add their new skills upon level up afterwards.
     
    #8
  9. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    I found the problem:


    Changing the class also changes the exp which is based on the new class curve. 


    When the exp is changed the engine will level up or down the actor, and the actor will only gain new skills when theres a level up in the process and yet, he'll only get the skills for the current level and the next ones depending on how many times the level up occurs.


    So if there are no level ups, no skill changes...


    Click here to get the plugin


    If the link stop working, it's a simple code:

    Code:
    var _old_game_actor_changeClass = Game_Actor.prototype.changeClass;
    Game_Actor.prototype.changeClass = function(classId, keepExp) {
        _old_game_actor_changeClass.call(this, classId, keepExp);
        this.currentClass().learnings.forEach(function(learning) {
            if (learning.level <= this._level) {
                this.learnSkill(learning.skillId);
            }
        }, this);
    };
     
    Last edited by a moderator: Oct 19, 2016
    #9
  10. LpLance

    LpLance Villager Member

    Messages:
    11
    Likes Received:
    3
    First Language:
    English


    It works. Thank you so much for this! This will make things much easier than doing a bunch of conditional branches.
     
    #10
    Lantiz likes this.
  11. Lantiz

    Lantiz Biterkid Veteran

    Messages:
    719
    Likes Received:
    1,064
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Also the conditional branchs has fails.


    The level of the actor is based on its class, so whenever you change the class, the level can change and you need to have a lot of attention to the level variable.


    Also other party members can change class, right? So you can't keep track only of the player... assumming you use a party.


    Anyway, glad to help.


    Fair winds mate!
     
    #11

Share This Page