Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
Hi all,

I’m looking for something pretty simple. I’m going to be using it along with some Yanfly Plugin functionality to have the battlers “roll initiative” like in D&D to set their action order at the beginning of each round in battle. I’m pretty sure I can make it happen once I have a few lines of script I can insert into an event (I shouldn't need a full plugin).

The script will run on "Turn 0" of a Battle Event, and then again each turn on "Turn End." The script should perform the following action on each battler, whether party member or enemy:

Set the value of their CRI (xparam[2]) to = Math.randomInt(20) + 1 + Math.floor((BATTLER.def-10)/2)

Each battler’s CRI should be set individually, so the random component will be different for each of them.

I've freed CRI from it's normal usage via plugins, and will be able to have a formula reference each battler's CRI as the value of "Action Speed" in this Yanfly Battle System STB plugin that I'm using.

I just need that bit of code to actually get the right values into each battler's CRI with a script in the Battle Events.

Can anyone help with that?
 

Fuchsilein

Devil Fox
Veteran
Joined
Aug 20, 2015
Messages
53
Reaction score
19
First Language
German
Primarily Uses
Hi there!
I'm not a javascript guru yet but could try to help you with this.
Since there isnt a setParamter function in MV we need to have a little bit of a workaround for this.

Let's start with the enemys here,
First we need to find out how many enemys are there, we'll do it with the length of the $gameTroop._enemies array
Code:
$gameTroop._enemies.length
will return the exact number of enemies in your current battle.
To set the parameter for each of them you'll need a loop, also since we can only add/substract the parameter and those can never go lower than 1 we'll need a workaround on this. This should change the lck stat (param[7]) equal to your wish for every enemy, sadly I cant test it myself at the moment.

Code:
 for (var i = $gameTroop._enemies.length; i > 0; i--) {
 var result = Math.randomInt(20) + 1 + Math.floor(( $gameTroop.members[i].param[3]-10)/2);
$gameTroop.members[i].addParam(7, -$gameTroop.members[i].param[7]+1);
 $gameTroop.members[i].addParam(7, result-1);
   }
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
Thanks! I'll give it a try soon and let you know how it works.
 

Sword of Spirit

Veteran
Veteran
Joined
Nov 3, 2017
Messages
114
Reaction score
14
First Language
English
Primarily Uses
RMMV
I couldn't get that to work; I couldn't get any Ex-Parameters, Sp-Parameters, or additional Base Parameters added by a mod to work (and I didn't have any of the default Base Parameters open for this purpose); but I finally figured out a method that works!

For anyone else who wants to do this, here is how I finally got it to work.

1) I set aside 14 variables for storing initiative results (6 party members plus 8 enemies).

2) In the Battle Event, I assigned a random result to each of those variables, based on the stats of a party member or enemy. You could use whatever formula you want in this. Examples:

This is exactly what I'm using:
Code:
Control Variable: #0011 Initiative - 1st Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[0].def-10)/2)
Control Variable: #0012 Initiative - 2nd Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[1].def-10)/2)
Control Variable: #0013 Initiative - 3rd Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[2].def-10)/2)
Control Variable: #0014 Initiative - 4th Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[3].def-10)/2)
Control Variable: #0015 Initiative - 5th Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[4].def-10)/2)
Control Variable: #0016 Initiative - 6th Character = Math.randomInt(20) + 1 + (($gameParty.battleMembers()[5].def-10)/2)
Control Variable: #0019 Initiative - Enemy 1 = Math.randomInt(20) + 1 + (($gameTroop.members()[0].def-10)/2)
Control Variable: #0020 Initiative - Enemy 2 = Math.randomInt(20) + 1 + (($gameTroop.members()[1].def-10)/2)
Control Variable: #0021 Initiative - Enemy 3 = Math.randomInt(20) + 1 + (($gameTroop.members()[2].def-10)/2)
Control Variable: #0022 Initiative - Enemy 4 = Math.randomInt(20) + 1 + (($gameTroop.members()[3].def-10)/2)
Control Variable: #0023 Initiative - Enemy 5 = Math.randomInt(20) + 1 + (($gameTroop.members()[4].def-10)/2)
Control Variable: #0024 Initiative - Enemy 6 = Math.randomInt(20) + 1 + (($gameTroop.members()[5].def-10)/2)
Control Variable: #0025 Initiative - Enemy 7 = Math.randomInt(20) + 1 + (($gameTroop.members()[6].def-10)/2)
Control Variable: #0026 Initiative - Enemy 8 = Math.randomInt(20) + 1 + (($gameTroop.members()[7].def-10)/2)


3) Then in the Action Speed formula Yanfly Battle System STB:
Code:
if (user === $gameParty.battleMembers()[0]) { $gameVariables.value(11); } else if (user === $gameParty.battleMembers()[1]) { $gameVariables.value(12); } else if (user === $gameParty.battleMembers()[2]) { $gameVariables.value(13); } else if (user === $gameParty.battleMembers()[3]) { $gameVariables.value(14); } else if (user === $gameParty.battleMembers()[4]) { $gameVariables.value(15); } else if (user === $gameParty.battleMembers()[5]) { $gameVariables.value(16); } else if (user === $gameTroop.members()[0]) { $gameVariables.value(19); } else if (user === $gameTroop.members()[1]) { $gameVariables.value(20); } else if (user === $gameTroop.members()[2]) { $gameVariables.value(21); } else if (user === $gameTroop.members()[3]) { $gameVariables.value(22); } else if (user === $gameTroop.members()[4]) { $gameVariables.value(23); } else if (user === $gameTroop.members()[5]) { $gameVariables.value(24); } else if (user === $gameTroop.members()[6]) { $gameVariables.value(25); } else if (user === $gameTroop.members()[7]) { $gameVariables.value(26); } else {10 + ((def-10)/2); }


4) Then set the Event Page to run on Turn 0 once per Battle. This will cause all combat participants to "roll initiative" at the beginning of the fight to set up their action order, which will then remain constant throughout the fight. To shake it up so that initiative gets rerolled for each combat turn, make a copy of that Event Page and set it to run on Turn End for each Turn.

This was a huge breakthrough for me. I've gotten all sorts of other things done on my project, but I've been putting this off because my previous attempts have all failed. Now I'm good to go on pretty much the hardest important part of my system I've run into.
 

Latest Threads

Latest Posts

Latest Profile Posts

I think after I get this game done, I'm going to take a long vacation from game development. It feels great to see the coding skills get better and it is fun - but god it is also so exhausting.
Just advertising that I released version 0.9 of my game yesterday, for feedback purposes. My first game or creative endeavor ever :D Would be cool if someone tries it out!
An overall view of my full set of sprites so far, this was really fun to work in this past year! :kaopride:
1653056206274.png

Even though the game is cancelled, I'm still doing art in my spare time and seeing how it'd look.

It's a lot of fun. Wish I could be an artist!

Forum statistics

Threads
121,973
Messages
1,145,580
Members
160,253
Latest member
cpy0716
Top