Limiting damage types against types of enemies to certain classes

The game I'm currently working on, I had an interesting idea for a type of enemy I want to introduce in the next dungeon(Which is the first major dungeon of the game), this enemy type are ghosts. I want them to me "immune" to physical damage. But by "immune", I mean I want the Knight and Thief to automatically miss if they use a physical attack(They have access to magic, if you purchase it). But the Mage and Priest being magic based classes can hit them with physical attacks and the Monk, taking a page out of Dungeons and Dragons, could also hit the ghost type of enemy because she channels Chi.

Is there any way that I could do this? I don't mind if I would require another plug-in, but it's kind of a logical and neat idea for my game.
there was a similar question asked earlier today that has relevant answers you could make work with a little tweaking

You dont "need" passives to get this working, but it makes it a bit easier to do and lets you attach traits for other effects.
if you have a limited number of physical skills then you could use victor's hit formula plugin to have the skill always miss if the target is a ghost (i.e. has the ghost passive). if theres a possibility for casters and monks to also get these skills then youll have to also add a check for if the user isnt one of those classes
if you have many skills, then an adaptation of the solution OP found there can work for you.
otherwise, yanfly's hit accuracy plugin as mentioned can do it, but that formula will get longer the more rules you try to add
Hi, I don't know how to make it miss but I can set the damage to 0.
If you wanted to use plugins, yanfly starter bundle is free and there are this two plugins: AutoPassiveState & BuffStatesCore.

For example, put <Passive State: 19> (change 19 to what state id your actor will have) to actor class and <Passive State: 20> (likewise, change 20 to state id you will actually use) to desired enemy in database notetag. You can just name both states and left it blank for now.

Then in State 20 you input this code in the notetag:

JSON:
<Custom React Effect>
if (user.isActor() && user.isStateAffected(19)) {
    var physicalElementId = 1;
    if (this.item().damage.elementId === physicalElementId) {
        value = 0;
    }
}
</Custom React Effect>


There's a lot of better solution out there but just putting this out there.
For example, put <Passive State: 19> (change 19 to what state id your actor will have) to actor class and <Passive State: 20> (likewise, change 20 to state id you will actually use) to desired enemy in database notetag. You can just name both states and left it blank for now.
you dont really need the actor passive state for that. in the first line you ensured that the user is an actor, so you can just use the user's class. then from there, you could check the class's id or use a notetag.
Also you gave a way to check if the skill uses a particular element, but it sounded like OP wanted the consideration to be the skill's hit type (certain vs physical vs magical)

Code:
<Custom React Effect>
if (user.isActor() && [1,3,5.9].some(cid => user.currentClass().id === cid)) { //if the user is an actor and their class is within a set of "physical" classes
    if (this.isPhysical()) { //if the current action is a physical skill/item
        value = 0;
    }
}
</Custom React Effect>
--------------
alternatively
if (user.isActor() && user.currentClass().meta.Physical) //if the user is an actor and their class has the <Physical> notetag

But as you mentioned, this sets the damage to 0 instead of making it miss. So any skill effects like add state, remove buff and whatnot will still get ran if the skill connects.

Original thread: https://forums.rpgmakerweb.com/threads/limiting-damage-types-against-types-of-enemies-to-certain-classes.175040/