Randomizing enemy stats

Ah perfect. If I may make one more request though, it's that I know how to start at 2 for attack. What if I wanted the HP range to be higher? var "i" would = 0, but where do I go from there?
you mean the possible to get hp change or the high number you add to enemies's hp ?
Ah perfect. If I may make one more request though, it's that I know how to start at 2 for attack. What if I wanted the HP range to be higher? var "i" would = 0, but where do I go from there?
Just explaining to you

for (var i = 0; i < $gameTroop.members().length; i++) {

This is a for loop that will go through all enemy units (apply the following to every enemy)

var val = Math.randomInt(X);

Spews out a random integer number between 0 and x - 1

var id = Math.randomInt(8);

Id for the parameter you want to change I believe. Change this to 0 if you want to change to MaxHP

$gameTroop.members().addParam(id, val);

 

This will actually change the enemy's parameter (add) with an id of 8 (in this example) to a random value of up to x

 

}

So if you want to change HP by say up to 20 then do this

 

for (var i = 0; i < $gameTroop.members().length; i++) {

var val = Math.randomInt(20);

var id = 0;

$gameTroop.members().addParam(id, val);

}
Just explaining to you

for (var i = 0; i < $gameTroop.members().length; i++) {

This is a for loop that will go through all enemy units (apply the following to every enemy)

var val = Math.randomInt(X);

Spews out a random integer number between 0 and x - 1

var id = Math.randomInt(8);

Id for the parameter you want to change I believe. Change this to 0 if you want to change to MaxHP

$gameTroop.members().addParam(id, val);

 

This will actually change the enemy's parameter (add) with an id of 8 (in this example) to a random value of up to x

 

}

So if you want to change HP by say up to 20 then do this

 

for (var i = 0; i < $gameTroop.members().length; i++) {

var val = Math.randomInt(20);

var id = 0;

$gameTroop.members().addParam(id, val);

}

 
Finally got it working! Thanks! I did the randomization for each stat separately.
Just as an extra tip, if you want to randomize all stats (excluding max hp / max mp) you could do this:

for (var i = 0; i < $gameTroop.members().length; i++) {

for (var j = 2; j <= 7; j++) {

var stat_total = $gameTroop.members().atk + $gameTroop.members().def + $gameTroop.members().mdf + $gameTroop.members().mat + $gameTroop.members().agi + $gameTroop.members().luk;

var stat_change = Math.round((Math.randomInt(stat_total/30)) - stat_total/60);

$gameTroop.members().addParam(j, stat_change);

}

}

 

This will loop through all enemies
Then loop from 2 to 7 (which correspond to parameters atk, def, mat, mdf, agi, luk for the addParam function)
Then calculate the stat total of the enemy (sum of atk, def, mat, mdf, agi, luk); I have done this because as far as I know as I am unaware of referencing a particular stat by a number (eg. I can't reference 4 and get the target's magical attack)
Then calculate a random value using stat total as a reference. Here I have divided stat total by 30 (assuming each stat is equal, that means that the variance is about 10%, if you want more variance then change the 30 to say 15 and change the 60 to 30)
Now apply this random change to each parameter


Also if you adjust max hp, make sure to add the following at the start of the battle so the enemy actually can take advantage of it's (potentially) increased max hp. Otherwise it might have a hp of 3203/3500 at the start of battle.

$gameTroop.members().gainHp($gameTroop.members().mhp);
This isn't working for me. I have put this:

for (var i = 0; i < $gameTroop.members().length; i++) {

var val = Math.randomInt(2000);

var id = 2;

$gameTroop.members().addParam(id, val);

}

And set it to turn 1 for battle. I'm just trying to test giving my bats extra attack, thus the 2000. But it's not working at all. I've tried both in the battle test and test play. Any advice on this?

Original thread: https://forums.rpgmakerweb.com/threads/randomizing-enemy-stats.52375/