MV How to Add Magic Through Scripts in Equips?

So, I have created a system through events where (I'll post the logic below):

If (Sword X is Equipped && Shield X is Equipped) {
Learn Magic X;
}

Using events, the magic only appears after I exit the status screen and come back. With scripts, I believe the result will be instantaneous (right?), that's, why I want to recreate this with scripts and need to know where, exactly, I need to go to insert my own piece of code. Can someone help me out?

Thanks in advance!
it doesn't matter if scripts or events, neither will be executed in screens other than the map and the battlescreen, because only those two screens have interpreters.

but why using this at all? if you add traits by equipment then that will have a direct effect. For example if you add skill type magic by shield and the magic skills by sword.

If you stilol want to go your route then you'll have to install a screen interpreter or menu interpretewr by plugins.
eventing stuff gets updated when the menu is closed, recreating can work,
but it needs an update function, but even that isn't always 100% guaranteed
unless its done correctly/

there are some plugin that update when adding new clothes, so this is doable
to script within the plugin or close the menu when changed equipment.
You could try Yanfly's Auto Passive States.

Have the sword and shield apply the same passive state, which has the Trait to grant the Skill.

Then the passive state would have the notetag:
Code:
<Custom Passive Condition>
condition = user.isEquipped($dataWeapons[69]) && user.isEquipped($dataArmors[42]);
</Custom Passive Condition>

inserting the appropriate IDs for the sword and armor.

I'm not sure what exact timing that will have in the menu for the actor to refresh and make the skill visible, but it's better than using event commands.
Well, if you want to try it, this is the method I used in my project:

First alias the allTraits function for actors and add the function to add the skill:

Spoiler: Aliased Function
JavaScript:
var alias_Actor_allTraits = Game_Actor.prototype.allTraits;
Game_Actor.prototype.allTraits = function() {
    var traits = alias_Actor_allTraits.call(this);
    this.specificEquipLearnsSkill();
    return traits;
};

Then add the code you need in that separate function (Making sure the PC FORGETS the skill that is learnable, otherwise, they'll keep it when they unequip the items:

Spoiler: New Function
JavaScript:
Game_Actor.prototype.specificEquipLearnsSkill= function() {
    this.forgetSkill(magic);
    if(this.isEquipped($dataWeapons[69]) && this.isEquipped($dataArmors[42])) this.learnSkill(magic);
};

Where Magic is the skill ID of the spell you want your PC to learn.
You can add as many skills as you want and as long as you know how, as many conditions to look for as you need.

Works like a charm in my game.
Guys, thanks for the replies.

What I want to do would be something similar to the dual slot of the Materia system from Final Fantasy 7, where you see the results right after you did the changes in the stats screen. The only difference is that I designed it to learn new magic only if you have both piece of armor equipped (say, to have Magic X you have both Sword X and Shield X equipped). So, instead of All+Fire materias to have Fire that hit all targets, I have Fire Sword + Fire Shield to learn Fire 2 for instance.

I used the common traits to add magic, but I can't add specific magic the way I mentioned before without events (unless I'm missing something).
I believe my method is valid.
(I'm pretty sure @ATT_Turan is usable too, but I don't use passive states currently.)

Outside of not knowing how to make the actual plugin, I don't see the issue in using my method.

Was there something in my explanation that I can expand on to help you understand it?
It would help if you:

- used RPG Maker's terminology

- said what you tried that didn't work

As @Maliki79 said, you've been given several solutions that ought to work. Which ones did you try? What happened that was different from what you wanted?

What is "magic"? Is it a Skill? A Skill Type? Both should work fine with the methods you've been given, but "magic" isn't a thing in RPG Maker MV.

Where are screenshots of what you've tried and how it looks in your menu?
I believe my method is valid.
(I'm pretty sure @ATT_Turan is usable too, but I don't use passive states currently.)

Outside of not knowing how to make the actual plugin, I don't see the issue in using my method.

Was there something in my explanation that I can expand on to help you understand it?

Actually, I need to know where to go on the scripts to add this piece of code. I remember that I need to "rewrite" the code above what was been done, besides that...
For what it's worth, I just took one minute to test what I posted previously and it works perfectly.

Actually, I need to know where to go on the scripts to add this piece of code.
What does "where to go on the scripts" mean? You paste the code he gave you into a text editor, save it as a *.js file, include it as a plugin.
Actually, I need to know where to go on the scripts to add this piece of code. I remember that I need to "rewrite" the code above what was been done, besides that...
So, it depends on which route you want to try. Mine will require a bit more JS know how to implement. ATT's YF route is more user friendly.

Just let us know which one you wanna try first and we can go from there.
For what it's worth, I just took one minute to test what I posted previously and it works perfectly.


What does "where to go on the scripts" mean? You paste the code he gave you into a text editor, save it as a *.js file, include it as a plugin.

I'm sorry, I didn't expressed myself well... I was talking about which piece of code I need to work into.

If I recall well from the tutorials I have saw here, I need to "overwrite" the code to make it work the way we have intended. Instead of the editor executing the "original code", it will execute our code (I hope I have clarified things here).

In other words, I need to know which piece of code I need to find to overwrite in the new code I'll place in the js folder.

From what you've explained, there's no much sense making it through scripts instead of events, since the skills won't be updated right after. What I really need then is the script that will make the game interpret the common event while in the equip menu.
I'm sorry, I didn't expressed myself well... I was talking about which piece of code I need to work into.

If I recall well from the tutorials I have saw here, I need to "overwrite" the code to make it work the way we have intended. Instead of the editor executing the "original code", it will execute our code (I hope I have clarified things here).
That is what a plugin does. The code @Maliki79 gave you will alias (not overwrite) the Game_Actor.allTraits() method.

In other words, I need to know which piece of code I need to find to overwrite in the new code I'll place in the js folder.
Maliki already wrote it for you, I don't understand what you think you need to find.

From what you've explained, there's no much sense making it through scripts instead of events, since the skills won't be updated right after.
How have you gotten that from what anyone said? You've been told twice that both of these methods (Maliki's code and my notetags for passive states) work perfectly and update while you're in the menu.

Works like a charm in my game.
For what it's worth, I just took one minute to test what I posted previously and it works perfectly.
Guys, many thanks for the help. @Maliki79, you got your place on the Special Thanks of Anew Fantasy.

I confused things a bit, but as I copy&pasted the code and started to edit it, things freshed out in my mind and I managed to do what I wanted.
Happy to help!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-add-magic-through-scripts-in-equips.168044/