Magical weakness affinity triggering common event

Hey all,

I am struggling with sth supposedly simple. I would like to trigger somethig if an opponent is hit by a magic they're weak to. E.g. weak to water - run common event weak to water.

I can set the increased damage the magic does on my enemy, however I would like the weakness to trigger a certain common event. For this I have set up a state "weak" when the enemy is hit by a weakness attribute and which will be invisible and auto-remove itself in the common event after it has run. Now I am struggling though on how to trigger this state on the enemy, I seem unable to target the enemy type in common events or to add this to the enemy directly (like if hit by water set state weak). Has anyone done something of the like before?

Any other way around this, or will I need to get to scripting for this?

PS: I want to avoid visustella for the sake of staying flexible.

Thanks a lot!

Thanks!
You could finagle it without a plugin, but it would still require scripting inside the event that gets attached to every skill.

It would be easier to use a plugin - if you want to avoid VisuStella, my signature links to an Eval Tags plugin that provides equivalencies for most VS notetags.

Using that plugin, you could give an actor this notetag:
Code:
<Action Damaged Eval>
if (this.isDamage() && this.item().damage.elementId == X)
    $gameTemp.reserveCommonEvent(Y);
</Action Damaged Eval>

where X is the element ID from your database and Y is the ID of the common event (no leading zeros).
Oh that sounds great, I shall have a look at this, thanks so much! Could I also target the enemy directly with this script call?
Like this.enemy or sth of the like to add a state directly to the hit enemy with these tags?
Read the documentation for the plugin - there is a provided target variable to reference the target the skill is hitting.
Hey, thanks a lot. I am trying, but I am struggling to get the code right, I am not an experienced scripter at all, usually I can get away with altering scripts, but that is about it.

I have added the following to the actor as an example, because I want to apply State 4 if the element rate of element 2 is > 100%, but it doesn't seem to work 100%.

As I am trying to evaluate the weakness I tried the elementRate function provided by RMMZ.

If I do this and attack a troop -> any attack of my actor will apply state on any attack, and I cannot add it to the skill itself if I read this correctly, so this bit of code is incomplete in that case:

JavaScript:
<Action Damaged Eval>
if (target.elementRate(2) > 1) {
    target.addState(4);
}
</Action Damaged Eval>

Then I tried to combine your code with it, but it seems to not do anything like this, even if I apply the right skill in that case:

JavaScript:
<Action Damaged Eval>
if (this.isDamage() && this.item().damage.elementId == 2){
 if (target.elementRate(2) > 1) {
    target.addState(4);
 }
}
<Action Damaged Eval>

Any idea what I'm doing wrong?

Edit: Also tried combining the conditions:

JavaScript:
<Action Damaged Eval>
if (this.isDamage() && this.item().damage.elementId == 2 && target.elementRate(2) > 1){
    target.addState(4);
}
</Action Damaged Eval>
I'm confused, because you appear to be asking about a few different things at the same time.

I have added the following to the actor as an example, because I want to apply State 4 if the element rate of element 2 is > 100%, but it doesn't seem to work 100%.
How does it not work 100%? You proceed to say
If I do this and attack a troop -> any attack of my actor will apply state on any attack
which indicates it is working. So please clarify whether something about the notetag is not working, or you just need help with the right code.

I cannot add it to the skill itself if I read this correctly
That's true, although adding some notetags to be evaluated during skill phases is a good idea. Nonetheless, you can check whatever properties of the current action you want.

Then I tried to combine your code with it, but it seems to not do anything like this
Yup, because I haven't done anything with it in so long that I forgot how to use my own plugin 🤣 this is a battler, not an action.

You can do this:
Code:
<Action Damaged Eval>
let action = BattleManager._action;

if (action.isSkill() && action.isDamage() && action.item().damage.elementId == 2 && target.elementRate(2) > 1)
   target.addState(4);
</Action Damaged Eval>

That will cause all damaging skills of element 2 to place state 4 if the target is vulnerable to element 2.

Edit: You could also use the Action Apply Eval in a skill, in which case my original code including use of this would work as expected. I just mixed up my notetags.
Amazing, this works exactly as expected, thanks so much!

Original thread: https://forums.rpgmakerweb.com/threads/magical-weakness-affinity-triggering-common-event.166079/