Need help with a skill that adds a random state.

From my understanding, I should be able to achieve this with a simple damage formula?

b.add_state([21,22,23,26,27,28,29,30,33][rand(9)])

But it doesn't show the state/effects, so I don't think it's working.

Is this doable and I missed something, or do I need a plugin?
your code is wrong - the add state command should receive a single number and you gave it two different arrays of numbers without selecting anything of those numbers.

unfortunately you'll have to wait for someone with better javascript to tell you how random element selection is really spelled.
Hey,

You may have dug up code meant to be used with RPGMaker VXAce, which uses a different language. The MV/MZ equivalent would look pretty similar though:
Code:
b.addState([21,22,23,26,27,28,29,30,33][Math.randomInt(9)])

An array followed by an index in square brackets is not interpreted as a second array in this case, but returns the indexth element of the preceding array (starting at index 0; in this case the index is randomly chosen among the first 9).

---

Optionally, instead of using the damage formula you could use a plugin like Yanflys YEP Skill Core, which allows you to put effects like this in the note box. This is not neccessary for the code to work, but can have a few small advantages:
- Does not require the skill to have a damage formula
- Might look cleaner in the editor since you have more than a single line to work with
- Does not break the "Autobattle" trait and similar plugins that evaluate a skills damage without using it

A notebox equivalent using the plugin above might look like this:
Code:
<after eval>
if (b.result().isHit()) {
    b.addState([21,22,23,26,27,28,29,30,33][Math.randomInt(9)]);
}
</after eval>

---

If you are doing a skill and don't care about code size, you could consider using this instead of b.addState:
Code:
let effect = {
    code : Game_Action.EFFECT_ADD_STATE,
    dataId : [21,22,23,26,27,28,29,30,33][Math.randomInt(9)],
    value1 : 1.0,
    value2 : 0
};
this.applyItemEffect(b, effect);
This mimics the "add state" effect from your skills effect list, which will also consider your targets resistance before adding the state. The dataId is the state id here, value1 is the application chance (1.0 = 100%), value2 is normally unused for this type of effect and should be 0.

Edit: Misremembered a line of code.
It's doable AND you need a plugin. Using command stuff like that can affect Autobattle and monster behavior. Also, you don't have a way of assigning a rate for the states. You could built this as a Common Event, but there are plenty of existing plugins like Yanfly that allow this to be scripted quite easily.
It's doable AND you need a plugin. Using command stuff like that can affect Autobattle and monster behavior. Also, you don't have a way of assigning a rate for the states. You could built this as a Common Event, but there are plenty of existing plugins like Yanfly that allow this to be scripted quite easily.
I ended up going with this and it works! the damage formula interferes with Yanfly's Damage Core or whatever it's called.

But yea, it works great now, thanks!

<after eval>
if (b.result().isHit()) {
b.addState([21,22,23,26,27,28,29,30,33][Math.randomInt(9)]);
}
</after eval>

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-skill-that-adds-a-random-state.158824/