MV Octopath's Capture-like system

So, I want to implement a system like Capture from Octopath, see the video below.



I know the limitation of the engine so I want to make something similar, making the actor only learn the skill, like a blue mage, but I want to limit it to a max of 5 skills learned. If the actor has already learned 5 skills, a screen will appear asking if they want to replace a skill with the one they just learned.

The thing is, I don't know if it would be easier to do this with a common event or with the Skill Core and Action Sequences.
I already thought about what the coding will be, but I really need some help.


The idea is that, beforehand, the learned skills will be stored in 5 different variables and the skill that the enemy teaches as well.

JavaScript:
let skills = [$gameVariables.value(1), ..2, ..3, ..4, ..5];
let canLearn, rng, chance;
skills.forEach((s) => { if(s != 0) { canLearn = true; } else { canLearn = false; }  })

rng = Math.floor(Math.random() * 100) + 1;
chance = //make some calculation based on the target current HP

if (rng <= chance) {
    if(canLearn) {
        $gameActors.actor(6).learnSkill($gameVariables.value(53));
        $gameMessage.add('skill learned');
    } else {
        $gameMessage.add('Select one skill to change');
        $gameMessage.setChoices([$gameActors.actor(1).skills()[0].name, ..1, ..2, ..3, ..4, ..5], 1, -2);
        $gameMessage.setChoiceCallback(n => {
              if(n === 0) {
                //forgetSkill w/ ID stored in Learned 1 variable
                //learnSkill w/ ID stored in the Teached variable
                //Store the current skill ID in Learned 1
            } else if (n === 1) {
                //repeat for other choices
            }
        });
    }
}

It's a sketch, just to show what I thought might work.
I don't see a benefit to using game variables for this, unless you're using them for something external to this. Just define an array on the actor.

I'm using user as if you were doing this using notetags such as from Skill Core.

Also, that part with the actor skills names to construct the choices has very incorrect syntax.

Code:
user.learnedSkills = user.learnedSkills || [0, 0, 0, 0, 0];

let learnSlot = user.learnedSkills.indexOf(0);

let chance = // some calculation based on whatever

if (Math.randomInt(100) <= chance) 
{
    if(learnSlot > -1) 
    {
        user.learnSkill($gameVariables.value(53)); // Not sure where this variable is coming from, in Skill Core you'd do this.item().id or something
        user.learnedSkills[learnSlot] = // that skill ID
        $gameMessage.add('skill learned');
    }
    else 
    {
        $gameMessage.add('Select one skill to change');
        $gameMessage.setChoices(user.learnedSkills.filter(skill => skill > 0));
        $gameMessage.setChoiceCallback(n => 
        {
            user.forgetSkill(user.learnedSkills[n]);
            user.learnSkill(); // incoming skill ID
            user.learnedskills[n] = ;// incoming skill ID
        });
    }
}

Original thread: https://forums.rpgmakerweb.com/threads/octopaths-capture-like-system.163265/