Yanfly STB: Help with Agi and Turn Order

Link to plugin: http://yanfly.moe/2017/03/24/yep-130-battle-system-standard-turn-battle-rpg-maker-mv/

This plugin lets turn order be determined by a battler's agility. However, I want the battler's agility to matter at the start of battle and the turn order to be randomized. I want the turn order to be static after the start of battle.

For the randomized start, I want each battler's agility to be calculated by: Math.randomInt(20) + Math.floor((agi-10)/2)

Right now, my only options are to have turn order randomized after every action by putting my formula in the Action Speed parameter of Yanfly's STB plugin settings, or to have turn order based on a static value (e.g. battler agility).

Call for help

Please, please help. I have tried things like storing each battlers' random speed value into a variable on turn order 1, and then having subsequent turns reference this number. In theory, I think this is kind of the solution that would work, but I keep getting errors because I don't know what variables/script calls to use.

I've tried searching through the rpg_objects.js file, and the plugin files, but anything I copy and paste seems to throw an error. I don't really know enough about javascript to figure this out on my own, although I have been trying to educate myself.

I could even be on the totally wrong track and there could be some simple solution that I've overlooked, I really don't know. So I am turning to you all to please help if you know how I can make this work for my game. Without this element, I lose a lot of the type of strategy I was hoping to have for my battle system. If you know that what I want is actually not possible, please let me know as well because then I can start thinking of some alternative instead 🙁
So...I'm not an expert or anything and I don't know your level of experience with JS. But I might be able to help.

I'm posting two possible solutions, the first one with and without script calls and the second one just a scriptcall solution (but I don't know the actual script call).

I think you could do this with an event at the start of the battle. This gist of what you want is to apply a random agility buff to each battler?

So first, you'd need a couple of states that will:
1. add flat boosts to the character's agility
2. not be cleared with a recover all (see Yanfly's State Categories for the Buffs and States Core)
3. not be removed on death
4. not expire during battle (no turns, no actions)
5. expire at battle end

From your formula, the modified agility will be: Math.randomInt(20) + Math.floor((agi-10)/2)
Which is basically a random number from 0 to 20 added to a modified agility score (I must ask...why not just use the actual agility?)

Control Variables: [Random number] = Random 0 to 20
If [Random number] = 0
If [Random number] = 1
(apply agility buff state 1 to actor)
If [Random number] = 2
(apply agility buff state 2 to actor)
...

Once you've filled that out for all 20 agility states, you'd want to copy/paste the code for all of PCs and battle enemies.
And that's the long (aka no-programming-needed) way to do it.

You can simplify the process with a single script call for each actorID though.
$gameActors.actor(actorID).addState($gameVariables.value(x);
where x is a random number that will indicate which of the agility modifier status effects to apply.
(link is to a JS tutorial on Math.random() and how to make it generate the numbers you want).

and then do the same for the each enemyIndex:
$gameTroop.members()[enemyIndex].addState(x);

Admittedly, this is a generic solution for a fixed party and a fixed number of enemies. It can be optimized, but that would require a little more coding and I'm not at a computer that I have MV on.

ALTERNATIVELY
This one doesn't require setting up the extra states...but I'm not quite sure of the syntax for the scriptcall (as noted by the red text).

Pre-battle common event:
Set each battler's current agility to a specific variable.
Run scriptcalls to boost the agi by a random number: $gameActors.actor(actorId).setParam[6]($gameActors.actor(actorId).param[6] + x);

Post-battle common event:
Set each actor agility back to what it was pre-battle: $gameActors.actor(actorId).setParam[6]($gameVariables.value(id));

The problem with this solution is that it makes a permanent modification to the actor stats, which could be a problem if somehow the post-battle common event doesn't run.
@Kevin Moluf I know you want to highlight as significant the part of the scriptcalls that you are unsure of, but red and blue text is reserved for mod use only. Could you please edit your post and pick a different color or maybe turn it bold, or underlined or something.
Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-stb-help-with-agi-and-turn-order.84089/