[VXA](Solution) Making stun still somewhat useful for slow battlers -- debuff chance at stun

I made stun a lot more useful and prevalent in my game, but made it so that it only lasts for a single turn. However, I noticed that if the battler is slower, stun is pretty much useless. So to play into the Buff/Debuff system, I came up with this:

When the target becomes stunned, if their Def or Mdf is buffed, there will be a 50% chance that their buff level will be reduced by four. If those stats aren't buffed, then there is a 33% chance that their Def and Mdf will be debuffed by level 1 for 2 turns (including the current turn), flat, meaning that this debuff will not stack with other debuffs.

My formula is this, using the a custom/extended damage formula script and the script 

https://github.com/Hime-Works/Requests/issues/173

to make it so the skill Debuff Chance will occur if the state Stun is applied from the result.

Spoiler
number = 0;

number += rand(1000);

if b.buff_level(3) > 0; 

  then if number <= 500 then turns = 0; 

  turns += b.buff_turns(4); 

  b.add_debuff(3, turns);

  end;

elsif b.buff_level(3) == -1 and b.buff_turns(3) <= 2;

  then if number <= 333; b.add_debuff(3, 2);

  end; 

elsif b.buff_level(3) == 0;

  if number <= 333 then b.add_debuff(3, 2);

  end;

end;

if b.buff_level(4) > 0; 

  then if number then turns = 0; 

  turns += b.buff_turns(4); 

  b.add_debuff(4, turns);

  end;

elsif b.buff_level(4) == -1 and b.buff_turns(4) <= 2;

  then if number; b.add_debuff(4, 2);

  end; 

elsif b.buff_level(4) == 0;

  if number <= 333 then b.add_debuff(4, 2);

  end;

end
which in a single line looks like

Spoiler
number = 0; number += rand(1000); if b.buff_level(3) > 0; then if number <= 500; b.buffs[3] -= 1; end; elsif b.buff_level(3) == -1 and b.buff_turns(3) <= 1; then if number <= 333; b.erase_debuff(3); b.add_debuff(3, 2); end; elsif b.buff_level(3) == 0; if number <= 333 then b.add_debuff(3, 2); end; end; if b.buff_level(4) > 0; then if number <= 500; then b.buffs[4] -= 1; end; elsif b.buff_level(4) == -1 and b.buff_turns(4) <= 1; then if number <= 333; b.erase_debuff(4); b.add_debuff(4, 2); end; elsif b.buff_level(4) == 0; if number <= 333 then b.add_debuff(4, 2); end; end; 0
"turns" is just a temporary term used in the formula to store the amount of current buff turns. I use this instead of individual random number processes so that Def and Mdf will both be debuffed/ their buff level be decreased by 1 at the same time if they can be.

Original thread: https://forums.rpgmakerweb.com/threads/vxa-solution-making-stun-still-somewhat-useful-for-slow-battlers-debuff-chance-at-stun.29878/