Skill that gives a random state.

So, hello again (in case you saw me before).

Hi, could you help me ??

I need a spell that gives a random state. So I added all the "add state" for the states that I want this spell to give, but I don't want it to give more than I state at the same time to the target, I don't want it to get poison, sleep, confusion all together, I want one and only one per use of the spell. How can I do this ??
Link Common Event to skill. Make a variable that sets a random number between 1 and the number of possible outcomes. Then makes branches that inflict a different condition on an enemy, depending on the outcome of the variable.
The use of plugin
You should have YEP_skillCore
<Pre-Damage Eval>
var rr = Math.floor(Math.random() * 3);//Get a random number
if(rr==0){
target.addState(4);//state ID
}
if(rr==1){
target.addState(5);
}
if(rr==2){
target.addState(6);
}
</Pre-Damage Eval>
The use of plugin
You should have YEP_skillCore
<Pre-Damage Eval>
var rr = Math.floor(Math.random() * 3);//Get a random number
if(rr==0){
target.addState(4);//state ID
}
if(rr==1){
target.addState(5);
}
if(rr==2){
target.addState(6);
}
</Pre-Damage Eval>

I`m a noob, and this sounds complicated for me right now. Maybe later.

Link Common Event to skill. Make a variable that sets a random number between 1 and the number of possible outcomes. Then makes branches that inflict a different condition on an enemy, depending on the outcome of the variable.

Could you explain how I do this variable, please
Could you explain how I do this variable, please

In the common event, you open the event commands and pick "Control Variables..." (on the 1st page).
Variable - Single, you create a variable entry (any number in the list, and make sure to name it after the function you give it so you can easily keep track of it later).
Operation - Set.
Operand - Random, then the range of numbers it should take from. For example, if there are 3 possible different conditions the skill can inflict, set the numbers between 1 ~ 3.
Now, each time the event is called (by using the skill, once it's linked), it'll generate a random number between the range you've set and stores it into the variable.

Next, open the event commands again, and pick "Conditional Branch..." (also on the 1st page). Set it to Variable, and pick the variable you chose to store the random number in.
Set it to equal (=), and then the number it should be equal to - if 1 is the lowest possible number generated by the variable, go with that first. From there on, you can decide what should happen when that number is decided on by the variable. Repeat that process of creating conditional branches for all possible number outcomes.
In the creating the Variable part I set the number 3 ~ 13, because the state id number are 3 ~13, I don't want the spell to cause death for example. Is this ok, did I do it right ? Or should I use 1 ~11 because are 11 options ?


Set it to equal (=), and then the number it should be equal to - if 1

Here you lost me. I'm starting to think I did the 1st part wrong.

In variable part I choose the variable that I created in the 1st part. Then I choose = because I want the number to be equal the number that was selected by the variable, not < or >. Ok this part I got.

what do I do next ?
How I link this info to a State id ?
How does this add the apply state to a foe ?

Thanks for the help @Milennin , you are a life saver.
@cybarxz the number range is only numbers, not the values of the conditions, so you can use whatever you find easiest. And yes, set to 1 ~ 11 if you want 11 different possible outcomes.

After creating the branch, you put in whatever you want to happen. Hmm, I think for wanting the skill to be single target, you're going to have to create 11 different versions of the skill with the same name, and at the end of each turn, remove every version of the skill, roll the random variable, and then teach the character one version of the skill, dependant on the outcome of the variable. This can be done in a common event, so it should be easy...
If the skill hits all enemies, then just select the inflict conditions on enemies command, and fill in a different condition for each conditional branch.

I would first experiment with just 2 or 3 different conditions, and if you see that it works, add more different outcomes. Anyway, tell me if it's clear, lol.
@Milennin its working but it is not giving the state to the target. It adds the state to foe #1 #2.... or all foes. not the target one
@Milennin its working but it is not giving the state to the target. It adds the state to foe #1 #2.... or all foes. not the target one
Yeah, read my previous post again. You're going to have to have to create separate skills with the same name, and give a random one to the player character each turn using the variable and conditional branches.
Well, the change that the damage formula needs for this effect is really small...

You only write:
Code:
b.addState(Math.floor(Math.random() * 8) + 4); a.atk * 4 - b.def * 2

On your damage formula box and the skill will give a random state from range 4 to 12.
Lets say, if your poison state ID is 4, and your last state (let's say fear) is 12, then the target will always get affected by one and only one state ranged from 4(the minimum) to 12(the maximum). The 8 is there because you must subtract the minimum to the maximum in order to make the function work.
@Blue Symphony Minor correction: this will only make the range from 4 to 11.
Math.random() * 8 will give you a number from 0 up to but not including 8. Math.floor makes it an integer from 0 to 7. Then add 4 and it becomes an integer from 4 to 11.
@cybarxz since you want a random state from 3 to 13, you can use Blue Symphony's formula but adjust it to:
Code:
b.addState(Math.floor(Math.random() * 11) + 3); a.atk * 4 - b.def * 2

Edit: Darn, hit the post button by mistake. Code inserted above as intended.
I used @Milennin tips to do the effect for all enemies.

For a single enemy I will do try this Match floor/random thing. But I really don`t got it yet. could you explain the formula for me ?

Hoe exactly math floor and math random works ?

Thanks 4 the help @Llareian @Blue Symphony
@cybarxz
Math.random() gets a random decimal number between 0 and 1. It can be exactly 0 but it can't be exactly 1.
Math.floor(number) takes a number and truncates it -- in other words, it removes all the decimals, making it the nearest integer equal to or less than the original number.

The two most common ways you'll see Math.floor() and Math.random() used to get integers are:
Code:
//returns an integer between 0 and n
Math.floor(Math.random() * (n + 1));

//returns an integer between 1 and n
Math.floor(Math.random() * n) + 1;
Thanks @Llareian it worked. But there's still a but.

For many many times no state was added. Why this ?
@cybarxz Hmmm....are the states that are added only the ones that do not get removed by taking damage?
@Llareian the states are now removed by taking damage, only sleep is removed by dmg
Could you show a screenshot of your states page please?
Could you show a screenshot of your states page please?
sry.png
I'm not running into the problem of states not being applied on testing in a clean project; the only problems I've run into is that it LOOKED like no state was added when it added a state without an inflict message, and that it will apply the sleep state and then immediately remove it because of the damage applied. The sleep add/remove is a quirk of the order of operations inside the core scripts (as written, nothing that deals damage can also apply a "Remove by damage 100%" state); you'd have to use a plugin to get around it.

So check that you have inflict messages and icons for all of your states, because it may be that the state is applied but it just looks like it isn't. If it randomly selects sleep it should at least tell you they fall asleep and then they wake up.

Otherwise I'm out of ideas, because as I said, I can't recreate the problem.
Sorry @Llareian , I miss typed in the last reply.

@cybarxz Hmmm....are the states that are added only the ones that do not get removed by taking damage?

@Llareian the states are now removed by taking damage, only sleep is removed by dmg
*the states are not removed by taking damage, only sleep is removed by dmg

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-gives-a-random-state.89796/