MZ Creating the Static ability from Pokemon

I have VisuStella's Skills and States Core plugin, and I am having a little problem with making Pikachu's static ability its passive state, which has a 30% chance of paralyzing the attacker when it gets hit. I learned this code from Go_ Onizuka when he was making the Flame Body ability.

Code:
<JS On Add State>
if (target.states().includes($dataStates[72])) && math.random() < 0.3){
user.addState(12);}
</JS On Add State>
When I playtest it, I get the SyntaxError: Unexpected token '&&', which makes me think I am doing something wrong. Is the '&&' not supposed to be included in this code? Is there something that needs to be changed in this code? I'd be grateful for your help.
This thread was moved from RPG Maker MZ Feedback to JavaScript/Plugin Support.
Is there something that needs to be changed in this code?
3 issues i see

<JS On Add State>
unless im mistaken, that wouldnt ever run when the battler gets hit. the original state used yanfly's "react effect" notetag, which does. the "on add" notetag runs the code when the state is applied, which as far as i know would only be as the battle test/playtest file starts, not when any hits are exchanged. youd need to read the VS help section and see which state notetag you need

if (target.states().includes($dataStates[72])) && math.random() < 0.3){
Not explicitly an issue by itself, but if 72 is the id for this state and the effect of the state is supposed to take place when the battler with it is the target and is hit, it doesnt make any logical sense to include a check to see if its on the target. it wouldnt be able to run in the first place if it wasnt. adding extra unnecessary bits increases the chances of you making an error. thats important, because it leads into the actual issue

target.states().includes($dataStates[72])) && math.random() < 0.3
has an extra closing parentheses, which is what the error was supposed to lead you towards. after the state check, you added an extra one, which cuts the if off early and makes the && cause an error.


also just as a note. the way it is, your code would work on any skill that targets the battler and fulfils the conditions for the notetag you use. not just physical attacks (youd also need to designate skills somehow to be contact only) like static does but also magic, non-damaging skills, self targeting skills, any healing skill used would trigger it
has an extra closing parentheses, which is what the error was supposed to lead you towards. after the state check, you added an extra one, which cuts the if off early and makes the && cause an error.
The extra closing parentheses are the problem that causes the error. Thank you.
The extra closing parentheses are the problem that causes the error. Thank you.
Did you get these to work as intended? Any other changes to the notetag above you needed to make?
This was the code back then:
<JS On Add State>
if (target.states().includes($dataStates[72])) && math.random() < 0.3){
user.addState(12);}
</JS On Add State>

This is the code now:
<JS On Add State>
if (target.states().includes($dataStates[72]) && Math.random() < 0.3){
user.addState(12);}
</JS On Add State>


So what I did was delete the one extra parenthesis that is next to the &&.
Hmmm...I'm having trouble with implementation, but I'm trying to use this as a normal state, rather than a passive one. Game probably treats them differently. In my project, I'm aiming to create flame body as a defensive buff that a battler can give itself. I'll keep playing with it. Thanks for sharing!
Game probably treats them differently
They are handled differently, but the point of using target.states().includes($dataStates[x]) is because it works regardless of if its a passive or an active state.

However, i did note before:
unless im mistaken, that wouldnt ever run when the battler gets hit. the original state used yanfly's "react effect" notetag, which does. the "on add" notetag runs the code when the state is applied, which as far as i know would only be as the battle test/playtest file starts, not when any hits are exchanged
you might want to try <JS Post-Damage as Target> instead of <JS On Add State>

Original thread: https://forums.rpgmakerweb.com/threads/creating-the-static-ability-from-pokemon.172648/