Shock State

Hello, I have a bit of a problem.
I'm creating a state called Shocked in which, at the beginning of each turn, you have a 25% chance (reduced by the state-holders LUK) to be Stunned. I know Javascript basics, but I'm not entirely sure if this script would accomplish what I want. I'm running a multitude of Yanfly's plugins. Anyway, here's what I have currently.

<Custom Turn Start Effect>
if (a.isStateAffected(17)) {
var chanceHit = (Math.ceil(Math.random() * 100)) + (a.Hp / a.maxHp) * 10 - (a.luk / 5);
if (chanceHit >= 75) {
a.addState(14);
end;
}
else {
end;
}
else {
end;
}
}
</Custom Turn Start Effect>

State 17 being Shock
State 14 being Stunned
'a' is supposed to be the enemy that the Shock state is currently on.
The chance at which they'll be stunned is a random number + 25% of their missing hp - 20% of their LUK, then it checks if that value is 75 or more, giving a fundamental 25% chance.
Any recommendations?
i have a numb state that kinda does that but i dont remember where i got it
Hello, I have a bit of a problem.

What do you mean by a problem --> Are you receiving an error? Is the state simply not working in battle? Or are you just wondering if you are on the correct approach?

Something I noticed, I believe that your brackets are off. The outside "else" should be related to the outside "if" but instead it is related to the inside "if". See example below of a nested-if statement with an else statement for each "if".

Code:
var first = true;
var second = false;
if (first) {
    console.log("first is true");
    if (second) {
        console.log("first and second are true");
    } 
    else {
        console.log("first is true and second is false");
    }
} 
else {
    console.log("first is not true");
};
What do you mean by a problem --> Are you receiving an error? Is the state simply not working in battle? Or are you just wondering if you are on the correct approach?

Something I noticed, I believe that your brackets are off. The outside "else" should be related to the outside "if" but instead it is related to the inside "if". See example below of a nested-if statement with an else statement for each "if".

Code:
var first = true;
var second = false;
if (first) {
    console.log("first is true");
    if (second) {
        console.log("first and second are true");
    }
    else {
        console.log("first is true and second is false");
    }
}
else {
    console.log("first is not true");
};

The script just doesn't work. The enemy will receive the Shock debuff, but they'll never be stunned. I also edited the script, thanks for pointing that out!

Code:
<Custom Turn Start Effect>
if (a.isStateAffected(17)) {
    chanceHit = (Math.ceil(Math.random() * 100)) + (a.hp / a.maxHp) * 10 - (a.luk / 5);
    if (chanceHit >= 75) {
        a.addState(14);
        end; }
    else {end;
    }
} else {
    end;}
}
</Custom Turn Start Effect>
What about this code? units affected by this will have a 25% chance of being stunned at the start of the turn, if the shock succeeds then it will play an animation on the unit.
Code:
<Custom Turn Start Effect>
var stunRate = 0.25;
if (user.isStateAffected(17)) {
  if (Math.random() < stunRate) {
    user.addState(14);
    user.startAnimation(64);
    if (user.currentAction()) {
      user.useItem(user.currentAction().item());
    }
    user.clearActions();
    BattleManager.actionWaitForAnimation();
  }
}
</Custom Turn Start Effect>

I recommend changing the 0.25 for a 1 for testing purposes btw. The whole HP and LUK reducing the chances needs to be adapted to the size of the numbers in your game, so it's up to you.
Code:
<Custom Turn Start Effect>
if (a.isStateAffected(17)) {
    chanceHit = (Math.ceil(Math.random() * 100)) + (a.hp / a.maxHp) * 10 - (a.luk / 5);
    if (chanceHit >= 75) {
        a.addState(14);
        end; }
    else {end;
    }
} else {
    end;}
}
</Custom Turn Start Effect>

Not quite, now you have 4 "{" brackets and 5 "}" brackets. You are getting close, take a look at my example very carefully.

Can you also open the Console during your test (press F8) and note if any errors are shown? Keep it open on the side during your battle test and monitor for any errors. I don't use Yanfly scripts at the moment but I'm fairly certain that he/she would have set it up so syntax errors are logged to the Console rather than crash your game.
Not quite, now you have 4 "{" brackets and 5 "}" brackets. You are getting close, take a look at my example very carefully.

Can you also open the Console during your test (press F8) and note if any errors are shown? Keep it open on the side during your battle test and monitor for any errors. I don't use Yanfly scripts at the moment but I'm fairly certain that he/she would have set it up so syntax errors are logged to the Console rather than crash your game.

Opening Console during testing yielded no results, even after removing all modifiers such as LUK and HP. There was no feedback from the console.

What about this code? units affected by this will have a 25% chance of being stunned at the start of the turn, if the shock succeeds then it will play an animation on the unit.
Code:
<Custom Turn Start Effect>
var stunRate = 0.25;
if (user.isStateAffected(17)) {
  if (Math.random() < stunRate) {
    user.addState(14);
    user.startAnimation(64);
    if (user.currentAction()) {
      user.useItem(user.currentAction().item());
    }
    user.clearActions();
    BattleManager.actionWaitForAnimation();
  }
}
</Custom Turn Start Effect>

I recommend changing the 0.25 for a 1 for testing purposes btw. The whole HP and LUK reducing the chances needs to be adapted to the size of the numbers in your game, so it's up to you.

For the sake of testing, I set
Code:
 var stunRate = 1;
. Still no dice, enemies would not be stunned at all.
@SilentSword
It works perfectly for me. Did you paste it on the shock state notebox? or did you got the state IDs right? Or that Yanfly buff & states core plugin is working?
Because SOMETHING must happen at the start of the turn when a unit is afected by the shock state.
Can you post some screenshots of the states please?

*EDIT*
You know, you don't even need to check if the user is affected by the shock state, since in order for the code to activate, the unit NEEDS to be affected by it. So the code would be like this:
Code:
<Custom Turn Start Effect>
var stunRate = 1;
if (Math.random() < stunRate) {
  user.addState(x);
  user.startAnimation(64);
  if (user.currentAction()) {
    user.useItem(user.currentAction().item());
  }
  user.clearActions(); 
  BattleManager.actionWaitForAnimation();
}
</Custom Turn Start Effect>

Where x is the Stun state ID.
@Blue Symphony
kA0QBIJ.png

GCZjOzp.png
It looks fine. My guess is this is a plugin not working correctly. Maybe your should check your Yanfly plugins configuration?.
Can you try this code and tell me what happens in battle? Paste it in your shock state notebox:
Code:
<Custom Turn Start Effect>
user.startAnimation(80);
  if (user.currentAction()) {
    user.useItem(user.currentAction().item());
  }
user.clearActions();
var logWindow = SceneManager._scene._logWindow;
var msg = 'The plugin is working correctly.';
logWindow.addText(msg);
BattleManager.actionWaitForAnimation();
logWindow.push('clear');

</Custom Turn Start Effect>

Remember that this effect will run at the start of each of the units actions the turn after it is affected by the state. The code will process before the unit tries to use a skill/item.
It looks fine. My guess this is a plugin not working correctly. Maybe your should check you Yanfly plugins configuration?.
Can you try this code and tell me what happens in battle? Paste it in your shock state notebox:
Code:
<Custom Turn Start Effect>
user.startAnimation(80);
  if (user.currentAction()) {
    user.useItem(user.currentAction().item());
  }
user.clearActions();
var logWindow = SceneManager._scene._logWindow;
var msg = 'The plugin is working correctly.';
logWindow.addText(msg);
BattleManager.actionWaitForAnimation();
logWindow.push('clear');

</Custom Turn Start Effect>

Remember that this effect will run at the start of each of the units actions the turn after it is affected by the state. The code will process before the unit tries to use a skill/item.

Did this, nothing happened, nothing was returned to the console either.

I've moved this thread to Plug-In Support. Thank you.

I found a fix.
Something must be wrong with my <Custom Start Turn Effect> because everything else works just fine.
Made it a <Custom End Turn Effect> so that it would essentially have the same effect as stunning them for 1 turn.

Thank you for the help @Blue Symphony ^^

Original thread: https://forums.rpgmakerweb.com/threads/shock-state.88292/