Random proc chances with Yanfly Skill Rewards

Hi.
In my game I want to make it so that the player as well as enemies receive a certain state whenever they successfully land a crit or target an opponent's weakness. I'm using Yanfly's Skill Rewards plugin to do this. However, since the state in question is quite powerful, I want it to have a fairly low chance of applying. This is something that Yanfly's plugin can't do out of the box.

Code:
} else if (data.match(/ADD STATE[ ](\d+)/i)) {
  if (Math.random() < 0.3);
  user.addState(stateId);
  animation = animation || addStateAnimation;

I'm using this code but it doesn't seem to be working. I know basically nothing about Javascript. Is there an error somewhere?
Code:
if (Math.random() < 0.3);
Unfortunately, this code says "if (30% chance) do nothing". The semicolon ends the line and the if statement right there. 😅

Try this instead~
Code:
  if (Math.random() < 0.3) {
    user.addState(stateId);
    animation = animation || addStateAnimation;
  }
The {curly brackets} form a block: if the condition (30% chance) does not pass, then the entire block gets skipped. 🙂
Hi and thanks for your reply but it doesn't seem to be working. Even when I set it to 100% chance the state still isn't applied. I tested it out in a new project and it also didn't work there so it doesn't seem to be a plugin conflict.
Oh, oops, thought you meant the % chance wasn't working, rather than the whole thing. 😴

I just tested with a 50% chance and a <Hit Reward: Add State 10> tag on the Attack skill, seemed to work OK for me:
Code:
  if (Math.random() < 0.5) {
    var stateId = parseInt(RegExp.$1);
    user.addState(stateId);
    animation = animation || addStateAnimation;
  }
Did you remember to put the reward notetag on your skill? If you want this for all skills, you'd either need to put the appropriate notetag on all your skills, or find an alternative approach. 😅

Edit @Mitty: just noticed your code didn't have the var stateId line from the default example, maybe that was the problem?
Edit @Mitty: just noticed your code didn't have the var stateId line from the default example, maybe that was the problem?
Yes that was it. Thanks so much for your help. It's working now.

This thread can be closed.

Original thread: https://forums.rpgmakerweb.com/threads/random-proc-chances-with-yanfly-skill-rewards.114288/