Passive that gives buff when using elemental skills

Im working on a passive to apply a defence buff for 1 turn and increase evasion whenever you cast an earth skill.

Code:
<Custom Initiate Effect>
// Create empty pools for skills and skipp types.
var skills = [];
var skillTypes = [];
// Insert the skills this passive can be used with.
skills.push(106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129);
// Insert the skill types this passive can be used with.
// Check if the action is a skill, the skill pool contain the skill or if the skill type pool contains the skill's type
if (this.isSkill() && (skills.contains(this.item().id))) {
    user.addBuff(3,1);
    user.addState(54);
  }
</Custom Initiate Effect>

It doesnt seem to work, and if I use an attack that hits more than 1 enemy it applies def buffs equal to enemies hit :S
if you want that a state effect run only once over multiple targets, the best is to store a boolean in user.

JavaScript:
<Custom Initiate Effect>

if (!user._hasAlreadyTriggerStateXX){
    user._hasAlreadyTriggerStateXX = true

    // add what the state is supposed to do here, under the condition
};

</Custom Initiate Effect>

<Custom Conclude Effect>
user._hasAlreadyTriggerStateXX = false
</Custom Conclude Effect>

Otherwise, do you have more precision about what it doesn't work?
I don't know if initiate notetag is the most appropriate notetag to do such a thing btw...
For the earth condition, are you using YEP_ElementCore in your project ?
if you want that a state effect run only once over multiple targets, the best is to store a boolean in user.

JavaScript:
<Custom Initiate Effect>

if (!user._hasAlreadyTriggerStateXX){
    user._hasAlreadyTriggerStateXX = true

    // add what the state is supposed to do here, under the condition
};

</Custom Initiate Effect>

<Custom Conclude Effect>
user._hasAlreadyTriggerStateXX = false
</Custom Conclude Effect>

Otherwise, do you have more precision about what it doesn't work?
I don't know if initiate notetag is the most appropriate notetag to do such a thing btw...
For the earth condition, are you using YEP_ElementCore in your project ?

I have ElementCore in the project yes.

I have the same issue when I cast my earthquake spell that hits 2 or 3 enemies I get the defensive buff 3 times (175% increase), when I use a single target it runs just fine.

Code:
<Custom Initiate Effect>
if (!user._hasAlreadyTriggerStateXX){
    user._hasAlreadyTriggerStateXX = true
var skills = [];
skills.push(106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129);
if (this.isSkill() && (skills.contains(this.item().id))) {
    user.addBuff(3,1);
    user.addState(54);
  }  
};
</Custom Initiate Effect>

<Custom Conclude Effect>
user._hasAlreadyTriggerStateXX = false
</Custom Conclude Effect>
I basically want to combo if you use a skill from this list you gain a defensive buff and evasion for 1 round.
The only thing that doesn't work is the amount of time it triggers during a turn ?

I've made a notetag mistake previously. below the correct notetag to use.

Code:
<Custom Initiate Effect>
if (!user._hasAlreadyTriggerStateXX){
    user._hasAlreadyTriggerStateXX = true
    var skills = [];
    skills.push(106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129);
    if (this.isSkill() && (skills.contains(this.item().id))) {
        user.addBuff(3,1);
        user.addState(54);
  } 
};
</Custom Initiate Effect>

<Custom Action End Effect>
user._hasAlreadyTriggerStateXX = false
</Custom Action End Effect>
The only thing that doesn't work is the amount of time it triggers during a turn ?

I've made a notetag mistake previously. below the correct notetag to use.

Code:
<Custom Initiate Effect>
if (!user._hasAlreadyTriggerStateXX){
    user._hasAlreadyTriggerStateXX = true
    var skills = [];
    skills.push(106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129);
    if (this.isSkill() && (skills.contains(this.item().id))) {
        user.addBuff(3,1);
        user.addState(54);
  }
};
</Custom Initiate Effect>

<Custom Action End Effect>
user._hasAlreadyTriggerStateXX = false
</Custom Action End Effect>

Works now! Thanks what did you change I did not even notice a difference or know what it does? AlreadyTriggerState?
The variable _hasAlreadyTriggerStateXX doesn't exist. This script create and play with it actually.

the condition !user._hasAlreadyTriggerStateXX will be true only if the user._hasAlreadyTriggerStateXX can NOT be converted to true.

When you use the skill for the first time, user._hasAlreadyTriggerStateXX doesn't exist, so it can't be converted to true, so the condition is met and the code below will be executed.
The key is to directly set user._hasAlreadyTriggerStateXX to true when this code is executed.

When you use the skill twice or higher, per example with a multiple target scope, user._hasAlreadyTriggerStateXX is true because we set it to true for the first target. Since it now can be converted to true, the condition is not met and the code below will not run.

Don't forget to set user._hasAlreadyTriggerStateXX to false when the actor action is over, what is done by the Action End notetag. Otherwise, user._hasAlreadyTriggerStateXX will be convertible to true for the rest of the battle and the code below the condition will only run for the first time you use the skill over the whole battle.

To fit your game, it could be a good idea to change the name _hasAlreadyTriggerStateXX by a name that can't conflict with other state, in case you want to use those kind of code in multiple states. Per example, if this is for state 22 , you better have to rename it _hasAlreadyTriggerState22. just in prevision of variable conflict.
The variable _hasAlreadyTriggerStateXX doesn't exist. This script create and play with it actually.

the condition !user._hasAlreadyTriggerStateXX will be true only if the user._hasAlreadyTriggerStateXX can NOT be converted to true.

When you use the skill for the first time, user._hasAlreadyTriggerStateXX doesn't exist, so it can't be converted to true, so the condition is met and the code below will be executed.
The key is to directly set user._hasAlreadyTriggerStateXX to true when this code is executed.

When you use the skill twice or higher, per example with a multiple target scope, user._hasAlreadyTriggerStateXX is true because we set it to true for the first target. Since it now can be converted to true, the condition is not met and the code below will not run.

Don't forget to set user._hasAlreadyTriggerStateXX to false when the actor action is over, what is done by the Action End notetag. Otherwise, user._hasAlreadyTriggerStateXX will be convertible to true for the rest of the battle and the code below the condition will only run for the first time you use the skill over the whole battle.

To fit your game, it could be a good idea to change the name _hasAlreadyTriggerStateXX by a name that can't conflict with other state, in case you want to use those kind of code in multiple states. Per example, if this is for state 22 , you better have to rename it _hasAlreadyTriggerState22. just in prevision of variable conflict.

Thanks your great!

Original thread: https://forums.rpgmakerweb.com/threads/passive-that-gives-buff-when-using-elemental-skills.121695/