MV Add/Remove State on elemental damage

Heyho!

I'd like to create some kind of burning enemy, that when it gets hit by wind or water stops burning and loses some of it's powers, but gains this state again, when it gets hit by fire. Also I'd like to play an animation upon adding/removing this states and change the battler image.

I figured to use Yanfly's Buffs & States Core & AutoPassive States.

Here's what I came up with so far:

Burning State
This is the enemies Passive State.
When it get's hit by wind or water, while in this state it will be removed, the "Not Burning" state will be added, an animation will play and the enemy will change it's appearance.

Not Burning State
When the enemy get's hit by fire while in this state, this state will be removed, the "Burning" State will be added again, an animation will play and the enemy will change it's appearance.

I started with this code for the Burning State notetag, just to try out if I can remove the state, but it doesn't even work and I couldn't figure out why yet.

<Custom Respond Effect> var wind = 6; if (this.item().damage.elementId === wind) { var stateId = 55; target.removeState(stateId); } </Custom Respond Effect>

Burning State ID: 55
Not Burning State ID: 56
Wind Element ID: 6
Water Element ID: 4

Since I failed this early in the process I decided to ask for help rather than spending days trying to make all the other things work, that are still to be done to complete these states.

Thanks ~
YEP Auto Passive States do not get added or removed. Instead you have to turn them on/off with a passive condition.

Maybe something like this would work?
Spoiler: Burning passive state
<Custom Respond Effect> var water = 4, wind = 6; var element = this.item().damage.elementId; if (element < 0) { element = this.elementsMaxRate(defender, attacker.attackElements()); } if (element === wind || element === water) { defender._doused = true; } </Custom Respond Effect> <Custom Passive Condition> condition = !user._doused; </Custom Passive Condition>
Spoiler: Not burning passive state
<Custom Respond Effect> var fire = 5; var element = this.item().damage.elementId; if (element < 0) { element = this.elementsMaxRate(defender, attacker.attackElements()); } if (element === fire) { defender._doused = false; } </Custom Respond Effect> <Custom Passive Condition> condition = !!user._doused; </Custom Passive Condition>
The extra element stuff is just to account for skills using the Normal Attack element. If you are using YEP Element Core, you can try swapping these lines:

var element = this.item().damage.elementId; if (element < 0) { element = this.elementsMaxRate(defender, attacker.attackElements()); } if (element === wind || element === water) {
...for this:

var elements = this.getItemElements(); if (elements.some(function(e) { return e === water || e === wind; })) {
Thank you! Yeah you rightly asumed that I am using Element Core too : D

Worked perfectly : )

I managed to pull off the whole thing now, but since I am not really familiar with javascript, I am sure there is a more efficient way to accomplish, than was I did in the end. Still I'll post what I did, if anyone wants to achieve something similar. So if anything seems strange for you, or may not work as I think, feel free to correct me.

Here is my solution:

Burning State 55

JavaScript:
<Custom Respond Effect>
var water = 4, wind = 6;
var element = this.item().damage.elementId;
if (element < 0) {
  element = this.elementsMaxRate(target, attacker.attackElements());
}
if (element === wind || element === water) {
  defender._doused = true;
}
if (element === wind || element === water) {
target.startAnimation(305);
target.addState(56);
target.removeState(57);
}
</Custom Respond Effect>

<Custom Passive Condition>
condition = !user._doused;
</Custom Passive Condition>

Not Burning State 56


JavaScript:
<Custom Respond Effect>
var fire = 3
var element = this.item().damage.elementId;
if (element < 0) {
  element = this.elementsMaxRate(target, attacker.attackElements());
}
if (element === fire) {
  defender._doused = false;
}
if (element === fire) {
target.removeState(56);
target.addState(57);
target.startAnimation(306);
}
</Custom Respond Effect>

<Custom Apply Effect>
user._prevEnemyId = user._enemyId;
var transformEnemyId = 32;
user.transform(transformEnemyId);
</Custom Apply Effect>

Transformed State 57

JavaScript:
<Custom Apply Effect>
user._prevEnemyId = user._enemyId;
var transformEnemyId = 31;
user.transform(transformEnemyId);
</Custom Apply Effect>

I also created two enemies 31 & 32, with Burning State 55 as a passive state, to make it look and behave differently, when transformed.

I also feel like it should be possible to accomplish this using just two states, but it didn't work out yet^^


Anyway thank you again @caethyril : )
You really helped me out.
I notice you haven't swapped out the "element" section of code to use Element Core's getItemElements method. This means any Element Core features will be ignored, e.g. extra elements added by notetags. If that doesn't matter for your situation, then no worries! Otherwise, you could try these:
Spoiler: Custom Respond Effect (+ Element Core)
Burning state:
JavaScript:
<Custom Respond Effect>
var water = 4, wind = 6;
var elements = this.getItemElements();
if (elements.some(function(e) {
  return e === water || e === wind;
})) {
  defender._doused = true;
  target.startAnimation(305);
  target.addState(56);
  target.removeState(57);
}
</Custom Respond Effect>
Not Burning state:
JavaScript:
<Custom Respond Effect>
var fire = 3
var elements = this.getItemElements();
if (elements.some(function(e) {
  return e === fire;
})) {
  defender._doused = false;
  target.removeState(56);
  target.addState(57);
  target.startAnimation(306);
}
</Custom Respond Effect>
I haven't tested these, but I think they'll work. The if condition looks different because getItemElements returns an array/list of elements, so I've used the some method to loop through and check if "some" value in the list (i.e. at least 1) matches the criteria.

Everything else looks OK! Happy RPG Making~ 😂
Haha, I totally thought I did swap them, even thought, hey cool they considered Elements Core too. Seems like my brain tricked me somehow xD
Thanks again : D

Original thread: https://forums.rpgmakerweb.com/threads/add-remove-state-on-elemental-damage.139524/