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.