Edit run away formula?

So I want to try and edit my gave to use my actors/enemies defense stats instead of their agility stats.

I'm not sure if this is something i can do in rpg maker, or if I need coding experience. Or if there's a plugin for that, I'm not aware of its existence
Save the following code as a plugin:
JavaScript:
// Plugin by Toby Yasha. No credits required, but appreciated.

Game_Unit.prototype.defense = function() {
    const members = this.members();
    const sum = members.reduce((r, member) => r + member.def, 0);
    return Math.max(1, sum / Math.max(1, members.length));
};

BattleManager.makeEscapeRatio = function() {
    this._escapeRatio = (0.5 * $gameParty.defense()) / $gameTroop.defense();
};
I'm not sure if it worked or not. Does it matter if I am using Visustella Plugins like the Battle Core?
Yes it does matter. Now i don't know if their code also affects the escape rate, but if you want to ensure compatibility with their plugins, you should place the plugin i made anywhere below Visustella's battle plugins.

If you want to test if the plugin works or not you could set the escape rate to 1 and test it by escaping from 2-3 battles.
Here's how you would do it:
JavaScript:
BattleManager.makeEscapeRatio = function() {
    this._escapeRatio = 1;
};

After you are done with the test make sure to revert the formula back to the one i posted before.
Yeah they have a spot in the BattleCore mechanics settings where you can adjust the escape ratio with code. So you could also just use that part that calculates the total defences of the troops and then change the 'agility()' in the plugin settings to 'defense()'.
So I did try this out. again They actors are always able to run away.

I even made it so the actors had 1 defense each, while their opponents have 100 defense each

So the Total should be
(0.5*2)/200
which should be 1/200 for the ratio, making it a very slim chance if there are 2 actors and 2 enemy troops.

Yet the actors keep being able to run away.
Hmmm, is your VisuStella Core Engine settings set to: Quality of Life Settings - Escape Always true?
Hmmm, is your VisuStella Core Engine settings set to: Quality of Life Settings - Escape Always true?
I didn't realize that was an option.
I have turned it off and it works now
Cool.

VS BattleCore also makes the escape chance rise after failure by default. The code to modify that is under the escape ratio part in the settings.
Yeah, but it looks like it raises it based on the number of alive members you have if I am reading the default code correctly in BattleCore.

Spoiler: code used in VS BC
Code:
// Calculate Escape Ratio

let value = 0.1;

value += $gameParty.aliveMembers().length;



// Return Value

return value;

Original thread: https://forums.rpgmakerweb.com/threads/edit-run-away-formula.174585/