Well, I managed to solve this issue on my own. For anyone else who might be having the same issue, here's what I did to resolve it.
As far as I can tell, the code attacker.attackElements().contains(-insertelementIDhere-) does check for whether a normal attack contains an element. It just doesn't check to see whether or not if that attack's actually being used. So if an actor's/enemy's normal attack is of the element it's checking, it meets the conditions regardless of if the actor's actually using that normal attack.
What I eventually stumbled upon was adding Yanfly's Element Core and using this code instead, derived from a combination of Yanfly's Freeze and Greater Undead states:
This version works perfectly fine. It can detect elements in normal attacks and won't be removed by anything other than a Physical element attack, regardless of what it is.
So this issue's been resolved. What follows is the original post.
For a boss fight with a Barrier Shift move (that is, the boss is weak to one element and resists/is immune to the rest; hitting the weakness makes the boss change it), I've made a set of four states adapted from Yanfly's Freeze status effect.
There's four elements involved in the move: Fire (Element 2 in the database), Ice (Element 3 in the database), Lightning (Element 4 in the database), and Physical (Element 1 in the database). If the boss rolls the Fire barrier, Ice is the weakness and vice-versa. If the Lightning barrier is rolled, Physical is the weakness and vice-versa.
At least, that's what's supposed to happen. The Fire, Ice, and Physical Barrier states all work perfectly as far as I can tell. Their code:
The Lightning Barrier, however, is giving me massive headaches. Its code looks identical to the other states to me:
And yet, EVERYTHING seems to pass the conditions for it, Physical element or not. This includes the Lightning element itself, which this state is supposed to provide complete immunity to.
I started with this altered code, which doesn't break to everything:
Except this one doesn't acknowledge normal attacks at all, regardless if they're of the Physical element or not. Considering the best source of Physical-element damage in the game in its current state is through normal attacks, this is an issue.
I managed to recreate the issue in a brand new project, so as far as I can tell it's an issue with my code.
Can anyone tell me just what I'm doing wrong here?
As far as I can tell, the code attacker.attackElements().contains(-insertelementIDhere-) does check for whether a normal attack contains an element. It just doesn't check to see whether or not if that attack's actually being used. So if an actor's/enemy's normal attack is of the element it's checking, it meets the conditions regardless of if the actor's actually using that normal attack.
What I eventually stumbled upon was adding Yanfly's Element Core and using this code instead, derived from a combination of Yanfly's Freeze and Greater Undead states:
<Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Get the element(s) of this action
var elements = this.getItemElements();
// Check if physical damage is dealt.
if (elements.contains(physical)) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Get the element(s) of this action
var elements = this.getItemElements();
// Check if physical damage is dealt.
if (elements.contains(physical)) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
This version works perfectly fine. It can detect elements in normal attacks and won't be removed by anything other than a Physical element attack, regardless of what it is.
So this issue's been resolved. What follows is the original post.
For a boss fight with a Barrier Shift move (that is, the boss is weak to one element and resists/is immune to the rest; hitting the weakness makes the boss change it), I've made a set of four states adapted from Yanfly's Freeze status effect.
There's four elements involved in the move: Fire (Element 2 in the database), Ice (Element 3 in the database), Lightning (Element 4 in the database), and Physical (Element 1 in the database). If the boss rolls the Fire barrier, Ice is the weakness and vice-versa. If the Lightning barrier is rolled, Physical is the weakness and vice-versa.
At least, that's what's supposed to happen. The Fire, Ice, and Physical Barrier states all work perfectly as far as I can tell. Their code:
Fire Barrier:
<Custom Respond Effect>
// Get the ice element ID.
var ice = 3;
// Check if ice damage is dealt.
if (attacker.attackElements().contains(ice) || this.item().damage.elementId === ice) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 11;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
Ice Barrier:
<Custom Respond Effect>
// Get the fire element ID.
var fire = 2;
// Check if fire damage is dealt.
if (attacker.attackElements().contains(fire) || this.item().damage.elementId === fire) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 13;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
Physical Barrier:
<Custom Respond Effect>
// Get the lightning element ID.
var lightning = 4;
// Check if lightning damage is dealt.
if (attacker.attackElements().contains(lightning) || this.item().damage.elementId === lightning) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 14;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
<Custom Respond Effect>
// Get the ice element ID.
var ice = 3;
// Check if ice damage is dealt.
if (attacker.attackElements().contains(ice) || this.item().damage.elementId === ice) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 11;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
Ice Barrier:
<Custom Respond Effect>
// Get the fire element ID.
var fire = 2;
// Check if fire damage is dealt.
if (attacker.attackElements().contains(fire) || this.item().damage.elementId === fire) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 13;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
Physical Barrier:
<Custom Respond Effect>
// Get the lightning element ID.
var lightning = 4;
// Check if lightning damage is dealt.
if (attacker.attackElements().contains(lightning) || this.item().damage.elementId === lightning) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 14;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
The Lightning Barrier, however, is giving me massive headaches. Its code looks identical to the other states to me:
<Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Check if physical damage is dealt.
if (attacker.attackElements().contains(physical) || this.item().damage.elementId === physical) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Check if physical damage is dealt.
if (attacker.attackElements().contains(physical) || this.item().damage.elementId === physical) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
And yet, EVERYTHING seems to pass the conditions for it, Physical element or not. This includes the Lightning element itself, which this state is supposed to provide complete immunity to.
I started with this altered code, which doesn't break to everything:
<Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Check if physical damage is dealt.
if (this.item().damage.elementId === physical) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
// Get the physical element ID.
var physical = 1;
// Check if physical damage is dealt.
if (this.item().damage.elementId === physical) {
// Play animation
target.startAnimation(56);
// Get the status effect ID.
var stateId = 12;
// Remove the status effect from target.
target.removeState(stateId);
}
</Custom Respond Effect>
Except this one doesn't acknowledge normal attacks at all, regardless if they're of the Physical element or not. Considering the best source of Physical-element damage in the game in its current state is through normal attacks, this is an issue.
I managed to recreate the issue in a brand new project, so as far as I can tell it's an issue with my code.
Can anyone tell me just what I'm doing wrong here?