MV How to make escape rate adjust based on number of enemies on field?

Hello, I'm new to RPGMaker. I would like to know if there is a plugin or work around to make the escape rate increase or decrease based on the number of enemies/actors, so killing an enemy with high AGI would result to better chances of escape. I've already search some thread and already confirm that the escape rate seems to only read the initial values at the start of the fight, rendering AGI State boosting useless to compute escape rate.

I'm also using Yanfly's STB and BattleEngine.Core.

EDIT added link: https://forums.rpgmakerweb.com/index.php?threads/escape-chance.133738/&fbclid=IwAR0Ni9KQBadj0EEOuGklzzWYS-CO8z5ZOn1NlGsV5WYVjno8BhPd6-oBWv8#:~:text=the escape chance is based,by each failed escape attempt

From Aesica
Edit: Also worth noting is the fact that buffing your party members to escape during battle doesn't help because the ratio is a snapshot taken at the start of the battle. So if you cast Haste to increase your party's speed and Slow to debuff the enemies' speed, it won't do anything even if the values for both effects are insanely large. Which is kind of dumb.
can you share the threads? the link is broken and just leads to the main page for the forum. the escape rate formula both is a parameter you can change in the config for the battle engine core and is calculated by BattleManager.makeEscapeRatio().

confirm that the escape rate seems to only read the initial values at the start of the fight, rendering AGI State boosting useless to compute escape rate.
where did you see that? Game_Unit.agility() is called once for each side every time you attempt to escape by default. it goes through every member of the unit calling it and takes the average of their agi stats at the time (including the dead). AGI states, buffs, and debuffs are counted in this.

With that in mind, if it doesnt mess up the way you want your combat to work, you can include a parameter trait into your death state to make it reduce the dead's agility to 0%. thatll effectively negate their contributions to their unit's agility and weigh their side down without having to change how the calculation is done

EDIT 1: noticed that makeEscapeRatio is only called once on battle startup actually. my bad. hold on

EDIT 2: save this as a js file, place it below the battle engine, and lmk if theres any issues
Spoiler
Code:
BattleManager.setup = function(troopId, canEscape, canLose) {
    this.initMembers();
    this._canEscape = canEscape;
    this._canLose = canLose;
    $gameTroop.setup(troopId);
    $gameScreen.onBattleStart();
    this._failCount = 0;
};
BattleManager.processEscape = function() {
    $gameParty.performEscape();
    SoundManager.playEscape();
    this.makeEscapeRatio();
    var success = this._preemptive ? true : (Math.random() < this._escapeRatio + (this._failCount * this._escapeFailBoost));
    if ($gamePlayer.isDebugThrough()) success = true;
    if (success) {
        $gameParty.performEscapeSuccess();
        this.displayEscapeSuccessMessage();
        this._escaped = true;
        this.processAbort();
    } else {
        this.displayEscapeFailureMessage();
        $gameParty.clearActions();
        this._failCount++;
        this.startTurn();
    }
    return success;
};
Thank you for the reply!
However, I might be an idiot for this but it isn't working or atleast not what I intended it to be.
I converted it to a js file though again, I'm a noob so I might've mess something as simple as that. I'm attaching it below.

As for the installation, I placed it below the battle engine plugin, added debuff to 'Dead' state just to be sure, and disabled 0.10 increase on fail attempt on the Battle Engine.

Now, as for testing, I set up three enemies, two of them have about 5 AGI each and the other 999 AGI. While the player party of two actors has 45 and 5. If I'm not mistaken, killing the enemy with 999 AGI should've guaranteed escape the next turn, right? After quite sometime about 4-6 turn passed, I managed to escape; I did double tries with and without 999 AGI enemy and ended with more or less the same result.

0.00 increase on fail attempt should've blocked me from running away at all or am I missing something?
debuff rate is a separate trait entirely. you want the parameter one
1709218051185.png
Oops, my mistake.
I switched to the parameters, it seems to be working wonderfully! Killing 999 AGI enemy guarantees escape.
Thank you again for the fast response, I'm starting to like this forums!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-escape-rate-adjust-based-on-number-of-enemies-on-field.166300/