State that does double damage if hit by three elemental types

Hello all,

I'm looking for a way to make a corruption-type monster that doesn't have any elemental weaknesses, but if hit with three different elemental type attacks in battle, the third one will deal double damage.

So essentially, in a scenario where the player has a party of 5 against a corrupt-type boss:

Action 1 - Takes fire damage
Action 2 - Takes water damage
Action 3 - Takes fire damage (again)
Action 4 - Corrupt monster attacks
Action 5 - Takes electric damage
Action 6 - Takes water damage

It will take double damage on action 5 and the counter resets, then on action 6 the counter starts again and goes up 1 and carries over to the next turn.

I'm using the Visustella Battlecore and all the other core plugins so there may be some notetags I could use on a state for all monsters and bosses that are the corruption-type.
JavaScript:
<JS Pre-Damage As Target>
  target._elementsHit ??= [];
  if (!target._elementsHit.contains(this.damage.elementId)) target._elementsHit.push(this.damage.elementId);
  if (target._elementsHit.length >= 3) {
    value *= 2;
    delete target._elementsHit;
  }
</JS Pre-Damage As Target>

Untested as I don't have my VS sandbox project open, but this should do what you're asking.
Thanks so much!

I don't know that it's working though, but I may be setting up something wrong. I did three very simplistic skills of three different elemental types that each do 25 damage and then pasted that code into a "Corrupted Monster" state. Ran a battle test where I assigned one of those elemental skills to three of my party members and at the start of the troop event added enemy state "Corrupted Monster" to both enemies, hit them with all three elemental attacks and they all did 25 damage. Even did another test where I threw in a fourth elemental skill and tried hitting a fourth different element but still just did 25 instead of the expected 50. Made sure the monster didn't guard either by removing guard from their skill bank. I'll attach images of my state in the database and one of the skills (the other skills are exactly the same as I copied and pasted it and just changed the element).
Thanks so much!

I don't know that it's working though, but I may be setting up something wrong. I did three very simplistic skills of three different elemental types that each do 25 damage and then pasted that code into a "Corrupted Monster" state. Ran a battle test where I assigned one of those elemental skills to three of my party members and at the start of the troop event added enemy state "Corrupted Monster" to both enemies, hit them with all three elemental attacks and they all did 25 damage. Even did another test where I threw in a fourth elemental skill and tried hitting a fourth different element but still just did 25 instead of the expected 50. Made sure the monster didn't guard either by removing guard from their skill bank. I'll attach images of my state in the database and one of the skills (the other skills are exactly the same as I copied and pasted it and just changed the element).
I may have gotten the code wrong for getting the element, especially if you're using Element Core (which overwrites some stuff there)
I threw the code into ChatGPT to see if it could figure out the necessary tweaks to make. They had me add some console.log lines to see what was happening when it ran and it kept giving me a "Cannot read property 'elementId' of undefined" message every time a player's party member attacks. So after a few iterations, ChatGPT came up with this code that seems to work as intended:

<JS Pre-Damage As Target>
// Ensure the _elementsHit array is initialized
target._elementsHit ||= [];

// Attempt to safely get the element ID
let elementId = this.item()?.damage?.elementId;

// Debugging: Log current element and existing hits
console.log('Current Element ID:', elementId);
console.log('Elements Hit Before:', target._elementsHit);

// Add the current element to the array if it's not already included and elementId is valid
if (elementId && !target._elementsHit.includes(elementId)) {
target._elementsHit.push(elementId);
}

// Debugging: Log updated array of elements hit
console.log('Updated Elements Hit:', target._elementsHit);

// Check if three different elements have hit the target
if (target._elementsHit.length >= 3) {
value *= 2; // Double the damage
console.log('Damage doubled!');
target._elementsHit = []; // Reset the array
}
</JS Pre-Damage As Target>

Don't know if there are any issues with this code as I know AI can sometimes be a little wacky with what they come up with and I'm not as familiar with javascript as I'd like to be to really check it, but it seems to function how I want it to.
I threw the code into ChatGPT to see if it could figure out the necessary tweaks to make. They had me add some console.log lines to see what was happening when it ran and it kept giving me a "Cannot read property 'elementId' of undefined" message every time a player's party member attacks. So after a few iterations, ChatGPT came up with this code that seems to work as intended:

<JS Pre-Damage As Target>
// Ensure the _elementsHit array is initialized
target._elementsHit ||= [];

// Attempt to safely get the element ID
let elementId = this.item()?.damage?.elementId;

// Debugging: Log current element and existing hits
console.log('Current Element ID:', elementId);
console.log('Elements Hit Before:', target._elementsHit);

// Add the current element to the array if it's not already included and elementId is valid
if (elementId && !target._elementsHit.includes(elementId)) {
target._elementsHit.push(elementId);
}

// Debugging: Log updated array of elements hit
console.log('Updated Elements Hit:', target._elementsHit);

// Check if three different elements have hit the target
if (target._elementsHit.length >= 3) {
value *= 2; // Double the damage
console.log('Damage doubled!');
target._elementsHit = []; // Reset the array
}
</JS Pre-Damage As Target>

Don't know if there are any issues with this code as I know AI can sometimes be a little wacky with what they come up with and I'm not as familiar with javascript as I'd like to be to really check it, but it seems to function how I want it to.
...you couldn't wait 25 minutes for me to have a look at it? 😛

Ah well, glad ChatGPT gave you what you wanted.
Haha sorry! ChatGPT would not have been able to figure it out without your initial input though, that's for sure. I know because that was my first step before coming here and it flubbed it tremendously. :LZSlol:

Original thread: https://forums.rpgmakerweb.com/threads/state-that-does-double-damage-if-hit-by-three-elemental-types.168607/