Conditional Skill Learning Through Items

Hi all,

What I want to do:
Make an item that will teach skills to an actor, ONLY if they have reached a certain level in a certain class. For instance, an actor can only learn Lv.2 black magic through a certain item if they've leveled up the black mage class enough.

What I've done:
Made the item trigger a state and a common event. In the common event, there are the conditions of the selected actor being 'afflicted' by said state, as well as knowing a 'dummy' skill that is learned by leveling up the class in question. When both conditions are met, the actor will learn the skill(s) I want them to learn. My problem with this method is that since it's running an event, it closes the menu, and I'd rather have it act like using an item normally (with no menu closing). I've gotten close to fixing this by adding in the common event the script SceneManager.push(Scene_Item); BUT that puts the menu back in the first item category on the first item. I want it to stay on the item/category that the cursor was previously on.

Suspected solves/workarounds:
I suspect the most efficient way of solving the problem is if there exists a scene interpreter compatible with MZ. This way, I could run the events in the menu without closing it at all. Alternatively, I could put a command at the end of the event telling the game to reopen the menu and go to the item scene AND in the correct index/category, as well as put the cursor back on the item, but I'm not sure if this method is even possible. I've read something about being able to define certain indexes of scenes (such as the key items category) so that they can be called directly, which would get me part of the way there. I'm just not well versed in coding so I'm not sure how to go about executing this.

Any and all workarounds/solutions to achieve the desired end result are welcome (even if it's a method I haven't thought of)! Thanks in advance for the help.

P.S. Feel free to move this thread to wherever if it's in the wrong location!
I believe that it's possible with Conditional Branches (if they work the same as with MV).

You can also fork Conditionals by the way. How your class leveling system works? It's through a script or you use a custom system with events as well?
I can use Conditional Branches to put the cursor back in the item menu, on the third category?

As for class leveling, that was actually going to be my next post haha I want to set it up so that there is a secondary EXP system (JP) that makes class level up independently from actors. So, actor 1 could be a level 13 black mage, switch jobs to be a level 7 knight, switch back to black mage and be job level 13 again, all without changing main character level that goes up with EXP. Not quite sure how to accomplish this though. I've been using VisuStella's Class Change System plugin (along with other plugins from them), but I'm not certain it will check all my boxes by itself.
I can use Conditional Branches to put the cursor back in the item menu, on the third category?
You need to be more clear. You want extra functionality? If it's the case, you achieve this with plugins or with custom code using the Script command.

As for class leveling, that was actually going to be my next post haha I want to set it up so that there is a secondary EXP system (JP) that makes class level up independently from actors. So, actor 1 could be a level 13 black mage, switch jobs to be a level 7 knight, switch back to black mage and be job level 13 again, all without changing main character level that goes up with EXP. Not quite sure how to accomplish this though. I've been using VisuStella's Class Change System plugin (along with other plugins from them), but I'm not certain it will check all my boxes by itself.
It's kinda possible to achieve that with events only. You can have separate variables for this. If you want extra functionality (like a custom menu with that), again, you will need a plugin.
Yes, I’ve been looking for a plug-in or script. In fact, someone’s been developing a script for this for me. This is what we have so far:

const CATEGORY_INDEX = 1
const ITEM_ID = 1
SceneManager.push(Scene_Item)
setTimeout(() => {
SceneManager._scene._categoryWindow.select(CATEGORY_INDEX)
SceneManager._scene._categoryWindow.processOk()
const itemIndex = SceneManager._scene._itemWindow._data.findIndex(item => item && item.id === ITEM_ID)
SceneManager._scene._itemWindow.select(itemIndex)
SceneManager._stack.push(Scene_Menu)
}, 250)

This successfully brings me back into a specified category, yay! Now I’m just trying to figure out how to script putting the cursor on a specific item, to make it seem like I never left the menu.
Try making the CATEGORY_INDEX not a constant, as it will keep the same value forever. Or, create a new variable for keeping the "position" in the menu screen.
So I should change the first "const" to "var" in case I want to redefine the variable later, correct?
or
How would I make the variable for keeping "position"?
So I should change the first "const" to "var" in case I want to redefine the variable later, correct?
or
How would I make the variable for keeping "position"?

Every time you call the code, your value is kept at 1, because you declared it as an constant. If you change to a common var, it will keep the previous value.
SceneManager._scene._categoryWindow.select(CATEGORY_INDEX)
const itemIndex = SceneManager._scene._itemWindow._data.findIndex(item => item && item.id === ITEM_ID)

As they are now, they always will return 1. If you want the item index to be kept, it need to be a var instead of const. If it's changed, even you leave the screen, the variable will keep the same value of before.

JavaScript:
var _index = 1;
const _maxIndex = 10;

function pressDown () {
if (buttonPressed(down)) {
    _index += 1;
    if (_index > _maxIndex) {
        _index = 1; // Go back to the original value
    }
}
}

It's just a non-functional code (at least on RPG Maker) that shows how an index works. On this example, even if you leave the fictional screen and come back, the value of _index will remain the last one, as it's global and keeps it's original value. _maxIndex will never change to anything other than 10 on this example.
I see that I need to use var instead of const - I've replaced the terms in the code, and it is still working how it did before - but I'm not sure how to implement any of the code you gave with the code I have so far. Unfortunately I'm still in the pretty early phases of learning JS basics haha so bear with me

Original thread: https://forums.rpgmakerweb.com/threads/conditional-skill-learning-through-items.153022/