MV Is there anyway to set a % on 'add state x' action on YEPs action sequences?

I have 3 different IF... statements inside my notetags, i want to have a different chance of adding a certain status depending on which one of these conditions you meet

Code:
if $gameVariables.value(1) >= 11 && $gameVariables.value(1) < 21
animation 125: target
change variable 3 = 1
action effect
motion evade: target
else
>>>NO CHANCE OF ADDED STATUS

if $gameVariables.value(1) == 0
change variable 3 = 3
action effect
animation 122: target
>>>50% CHANCE OF ADDED STATUS

else
animation 126: target
change variable 3 = 2
action effect
motion evade: target
end
>>>10% CHANCE OF ADDED STATUS

wait for animation

</target action>


Is that even possible?
The basic JavaScript function Math.random() returns a value from 0-0.9. So for example:
Code:
if Math.random()<0.9
is a 90% chance.

Code:
if Math.random()<0.5
is a 40% chance.

If it's very important to you to get a more specific probability (say, 75%) you can do that by multiplying and junk, and you can simply Google "JavaScript Math.random" to view tutorials on it.

But that's an easy way to do something with a percentage chance of success.

The only trick for you is that this is already inside of if/else conditionals. By default, Action Sequences don't support nested conditionals, but there's a plugin someone wrote for it - again, you can find it with a quick Google, I think it might've been DreamX.

(you could also just do it outside of those blocks...
if $gameVariables.value(1) == 0 && Math.random()<.5
do the state

but that's kinda messy when a plugin makes it work fine)
Code:
if Math.random()<0.5
is a 40% chance.
<0.5 Woudn't it be 50% chance?

The only trick for you is that this is already inside of if/else conditionals. By default, Action Sequences don't support nested conditionals, but there's a plugin someone wrote for it - again, you can find it with a quick Google, I think it might've been DreamX.

Is it this plugin? It's not by DreamX's but the description sounds like it
<0.5 Woudn't it be 50% chance?
Yes, my finger hit the wrong key 😛 At least I typed it the right way in the example for you!
Is it this plugin? It's not by DreamX's but the description sounds like it
Yup!
Nice! I got it working, thanks!
Just to be sure, this is the proper way to write it , right?

Code:
if $gameVariables.value(1) >= 11 && $gameVariables.value(1) < 21
animation 125: target
change variable 3 = 1
action effect
motion evade: target
else

if $gameVariables.value(1) == 0
change variable 3 = 3
action effect
animation 122: target
Math.random()                  <---
if Math.random()<0.3
add state 12: target, show


else
animation 126: target
change variable 3 = 2
action effect
motion evade: target
Math.random()           <---
if Math.random()<0.1
add state 12: target, show
end

wait for animation

</target action>


I mean, its working right so far, just want to make sure it wont sundely bug out!


EDIT: Nope, it's not working properly, i spoke too soon. When the effect hits all goes well, but when it doesnt it plays out 2 damage rolls. I think it's something wrong with the nesting, that 'end' line but i'm not sure,not familiar with code.
1 thing to keep in mind is that these dont take into account any possibly resistances the enemy might have. it will have the same apply chance on an enemy with no resistance and an enemy with 90% resist rate.
1 - This is why it is standard procedure when writing code to indent when you're inside of if statements and other blocks. That way you can see where you are and what needs to be finished.

1a - A common beginning technique is to type out the beginning and end of blocks immediately, so you know you have all of it right. Then go and fill in the middle.

2 - Why do you have these lines randomly (forgive the pun) saying Math.random()? They don't do anything, since action sequences don't normally run JavaScript commands...and even if it did call the function, it still wouldn't do anything since just shouting "Random number!" doesn't do anything with it. 😉

I suggest you make your framework, then fill it in from there. I'm making a few guesses because you really have it very mixed up where your else and ends are (you're missing at least two ends)...but if this isn't what you meant to do, adjust it on your own before filling it in.
Code:
if $gameVariables.value(1) >= 11 && $gameVariables.value(1) < 21
else if $gameVariables.value(1) == 0
  if Math.random()<0.3
  end
else
  if Math.random()<0.1
  end
end

wait for animation
"Random number!" doesn't do anything with it
I see! I thought you should first ask it to roll a number then refer to that number, but as i see it's done in just one command

else if $gameVariables.value(1) == 0
Also i see that you can put the else if right next to each other in the same line, that helps a lot to read it



1 thing to keep in mind is that these dont take into account any possibly resistances the enemy might have. it will have the same apply chance on an enemy with no resistance and an enemy with 90% resist rate.
This is actually good advice, didnt think about that before, thanks



Thanks a lot for the tips!
Also i see that you can put the else if right next to each other in the same line, that helps a lot to read it
In fact, it wouldn't work otherwise. It's not just helping to read it, else and else if are two different commands. Before the plugin for nesting (default action sequences):
Code:
if (this condition is true)
  stuff
else (under any other circumstances)
  if (is inside an else block so it gets ignored)
    stuff (always happens inside this else)
else (will never happen because the first else will always happen)
  stuff (will never happen)
end

Now, with nesting, it still wouldn't do what you tried to do before:
Code:
if (this condition is true)
  stuff
else (under any other circumstances)
  if (nesting works, so this will happen)
    stuff
else (will still never happen because you covered all circumstances with the first else)
  stuff (will never happen)
end

So to do what you intended, you must use else if:
Code:
if (this condition is true)
  stuff
else if (the first condition failed but this one is true)
  stuff
else (under any other circumstance)
  stuff
end

Original thread: https://forums.rpgmakerweb.com/threads/is-there-anyway-to-set-a-on-add-state-x-action-on-yeps-action-sequences.142305/