Element-specific triggers

I want to make a state that can be placed on a character that makes it so that whenever that character uses a skill of a specific element, a special status is also applied to the target of that skill. Stuff like 'all fire spells you use now inflict the Burn status' or 'all heal spells you use now inflict the Blessed status' etc.
I know that with the Yanfly plugins (which I am using), this is totally possible. But the actual coding for it is eluding me right now. If anyone could help me with this it'd be much appreciated, thanks.
So that would be something like

<Custom Establish Effect>
if (value > 0 && this.damage.element === [id here]) {
target.addState(whatever);
}
</Custom Establish Effect>
It's a little tedious, but I was able to do this just now without using any plugins 🙂

To do it the way I just did, you'd have to make a common event for each different type of elemental effect you want to be applied to the target upon spell hit when the caster has the "special state", and then go into each skill of that element within the database and just add that common event to its list of effects. It's easy but slightly more work than what Trihan proposed, so just let me know if that doesn't work for whatever reason, and I can come back with an explanation & screenshots of what I did as a Plan B.
So that would be something like

<Custom Establish Effect>
if (value > 0 && this.damage.element === [id here]) {
target.addState(whatever);
}
</Custom Establish Effect>

This doesn't seem to function, I'm afraid. I'm not sure why. As far as I can tell, I reproduced it pretty much as it should be:

<Custom Establish Effect>
if (value > 0 && this.damage.element === [02]) {
target.addState(286);
}
</Custom Establish Effect>

but to no effect in-game.

It's a little tedious, but I was able to do this just now without using any plugins 🙂

To do it the way I just did, you'd have to make a common event for each different type of elemental effect you want to be applied to the target upon spell hit when the caster has the "special state", and then go into each skill of that element within the database and just add that common event to its list of effects. It's easy but slightly more work than what Trihan proposed, so just let me know if that doesn't work for whatever reason, and I can come back with an explanation & screenshots of what I did as a Plan B.

I'm no stranger to a little tedium. What did you have in mind?
<Custom Establish Effect>
if (value > 0 && this.damage.element === [02]) {
target.addState(286);
}
</Custom Establish Effect>
You don't need the brackets or the leading 0 on the element ID.
As far as I can tell, I reproduced it pretty much as it should be:
no, but it because you didn't know programming convention.
this.damage.element === [02])
the correct line would be
this.damage.element === 2)

ninja'd
Oh, I'm a doofus! I always forget to remove the brackets in these cases. Thanks!
What did you have in mind?

So I basically just used some creative eventing with minimal scripting 🙂

I set up the test character state, and a test "on fire" state for the enemy:

Spoiler
states1.png

states2.png

Then I set up the common event to call from all "fire" element spells:

Spoiler
states3.png

And finally just manually plop the "common event" command into the fire spell's list of effects (I would do this with every fire spell, but I only made one to test):

Spoiler
states4.png

For other elements you would just make a separate common event for that element and call it, instead of the fire one, from each spell of that element.

In my playtest I gave my character the "character state", then entered battle, then used the "Firebolt" spell on the left enemy - you can see it worked and applied the "on fire" state to that enemy 🙂 :

Spoiler
states5.png

The scripts from the conditional branch so you can just copy & paste:

Code:
BattleManager._subject.isStateAffected(<characterstateID>)
$gameTroop.members()[BattleManager._action._targetIndex].addState(<enemystateID>);

It may be a little convoluted 😅 But it's how my brain was working earlier hahaa
Oh, I'm a doofus! I always forget to remove the brackets in these cases. Thanks!

Oh, does that work now though?
Oh, does that work now though?
No, actually. Even after fixing my doofy mistake with the square brackets, that Custom Establish Effect code doesn't seem to do anything. It doesn't crash the game or anything, it just doesn't make anything happen.
I tried your way instead, with the common events and that did crash the game.

Anyway, after some tinkering around with the Custom Establish code that Trihan posted, me and my pal (mostly my pal tbh) ended up with this variant:


<Custom Establish Effect>
if (this.item().damage.elementId === [elementIDhere]) {
target.addState(statenumber);
}
</Custom Establish Effect>

This one does the job! Thanks everyone for helping.
I tried your way instead, with the common events and that did crash the game.

Oh, for real?? I wonder why??? I had no problem at all, and can't imagine what part of it would cause a crash like that, unless the script calls are interfering with a plugin or something?

This one does the job! Thanks everyone for helping.

But I'm glad you figured it out! That way seems far less tedious anyway :LZSproud:
Oh, for real?? I wonder why??? I had no problem at all, and can't imagine what part of it would cause a crash like that, unless the script calls are interfering with a plugin or something?



But I'm glad you figured it out! That way seems far less tedious anyway :LZSproud:
It was probably just screwing with a plugin.
No, actually. Even after fixing my doofy mistake with the square brackets, that Custom Establish Effect code doesn't seem to do anything. It doesn't crash the game or anything, it just doesn't make anything happen.
I tried your way instead, with the common events and that did crash the game.

Anyway, after some tinkering around with the Custom Establish code that Trihan posted, me and my pal (mostly my pal tbh) ended up with this variant:


<Custom Establish Effect>
if (this.item().damage.elementId === [elementIDhere]) {
target.addState(statenumber);
}
</Custom Establish Effect>

This one does the job! Thanks everyone for helping.
Ah yeah, sorry, I forgot to go into item() before the damage property. My bad!

Original thread: https://forums.rpgmakerweb.com/threads/element-specific-triggers.145501/