there still are several other ways, but no one can work miracles.
I simply don't want to waste the time to explain one of the other ways only for you to then pull another restriction out of nowhere why you can't do it that way.
So if you want more help, you need to give the full info on the game mechanik you want, before I start thinking on which way that can be done.
Okay, I will try to explain this in as much detail as I can.
Spells in the game consume only mana and take up spell slots provided by this plugin:
www.yanfly.moe
So each character may know a large number of spells, but at the same time can use only those that are active and are in the slots. The number of slots can be increased if your character gains expirience.
There are 7 types of elements and 4 characters, I'll be calling them a,b,c,d for simplicity
Character A can use Fire, Ice and Earth magic
Character B uses Wind and water.
Character C doesn't use any magic.
Character D can use Electro and Dark magic.
In the beginning, characters know only the basic spells of their school. Character A knows the "beginners flame" spell of the flame school. Character B knows the "Wind gust" spell of the wind school.
Additional spells characters can find in spell books in different parts of the world. Any character can learn any spell from their respective school, even the most difficult one. But they will not be able to use them effectively, because as long as the character does not have enough experience, the mana cost of complex spells will be too high.
There is more than one book of each spell, so you can find the same book in the dungeon, or buying from a merchant. Books can stack. You can sell the books and buy them.
It doesn't cost anything to learn the spell, you can do it at any time if you have the spell book, and if your character doesn't already know the spell.
Example: You found a spell book "waterfall" in the cave. In the description of the item you can see that this spell belongs to the water school (spell deals water damage). So If you try to use it on the character "A", who uses Fire,Ice and Earth spells, you will have a message "This character can't use water magic".
But if you use the book on the character "B", then this character will learn the spell "waterfall", for he can handle water magic, and will be able to equip it in his spell slot.
Restrictions: I don't want to do this by creating a common event for each spell, because in my combat system, characters can learn as many spells as they want and combine them by adding them to their active slots, so there will be plenty of spells, giving the player a lot of room for experimentation.
I don't mind creating a separate switch for each spell, or better yet, creating a database where each possible spell is assigned a number, and that way you can register all the spells in one variable that will determine which spell the character must learn depending on its value. The creation of hundreds of states for characters depending on the spell is not the last idea either.
This is ideal system. But given the complexity of the task, I think to do it the more easy way: The books will not affect all characters but will be applied to the whole party, that is, when you use the book, the A character (it doesn't matter what character, the only thing matter is the state) will be given a state depending on the spell. And then a common event will be triggered, with only state checks for the A character (just because all the books give the A character corresponding state).
If he's got "Waterfall" state on him, you'll be asked if you want the B character to learn Waterfall, for this spell can be learned only by the B character. If you use a "Stone wall" book, you'll be asked if you want the A character to learn the stone wall, for he uses Earth magic.
In fact, in the same way I can implement the primary system, that is, I can apply a state-spell on the character that uses the book, and then, in a common event, check whether this or that character has a certain state. So, the very big common event will check all possible states first for character A, then for B,C and D. Until the system finds out which of the characters has a state(used a book). And then, if character A is found to have the state "waterfall" - then there will be a message that he cannot learn such a spell. And if it were "fireball", then the system would ask if character A knows this spell and if not - if you want to learn it.
It's all a matter of using the system you suggested, but with hundreds of different states corresponding to the spells. And it seems to solve the problem, but I just want to know your opinion, would you do it that way, or is it too bulky and there are easier ways out?