MV Changing Escape formula to spend MP instead of agility.

Hi there. I wanted to ask if anybody could help me with something I'm wanting to implement for my random encounters. Instead just using the party's agility stat, (since I don't use it very much in game), I wanted to instead make it where the party leader has to spend MP points to escape. I am using Yanfly's Battle Engine core, and I tried this formula, but didn't seem to work.

1765850420104.png


I'm not sure if it's that my scripting is wrong or if it has to have something else there. If anyone could help me figure out the formula to work, I'd really appreciate it!
That parameter is for a formula to calculate the chance of success for the escape and has nothing to do with any sort of cost.

Escape is not a skill (Tho you could just make one) and it's not possible to assign a cost to the default escape command without a plugin.
That parameter is for a formula to calculate the chance of success for the escape and has nothing to do with any sort of cost.
Okay then. Would I have to get a specific plugin to do what I want then?
Not really. I've not heard of anyone requesting that at all. Most people usually skip the entire party command window because it's cumbersome to use. If so, you could just make an escape skill instead. Or use hime's actor battle commands to show the escape skill outside of any skill category alongside attack, guard and such.

Either way, I'm pretty sure one of our local js wizards could potentially help out with a plugin snippet for that.
Something like this might work (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc The party command "Escape" costs MP.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1540749/
 * @help Free to use and/or modify for any project.
 */
;void (function() {
"use strict";
  /** MP cost for party escape command. */
  const MP_COST = 75;

  /** If `true`, don't pay the escape cost on failed attempts. */
  const PAY_ONLY_ON_SUCCESS = false;

  /** @returns {boolean} `true` iff party escape cost can be paid. */
  const canPayEscapeCost = function() {
    return $gameParty.leader().mp >= MP_COST;
  };

  /** Applies party escape cost. */
  const payEscapeCost = function() {
    $gameParty.leader().gainMp(-MP_COST);
  };

  // Patch - pay cost for party escape when appropriate.
  void (function(alias) {
    BattleManager.processEscape = function() {
      const success = alias.apply(this, arguments);
      if (!PAY_ONLY_ON_SUCCESS || success)
        payEscapeCost();
      return success;
    };
  })(BattleManager.processEscape);

  // Patch - party escape is only available when you can pay the cost.
  void (function(alias) {
    BattleManager.canEscape = function() {
      return alias.apply(this, arguments) && canPayEscapeCost();
    };
  })(BattleManager.canEscape);

})();
Note that the chance to escape is still based on the relative party/troop agility scores.

[Edit: added return success; to the processEscape patch, oops. I don't think the core scripts use that return value, but it's possible that other plugins rely on it.]

Plaintext-to-plugin instructions:
  1. Copy + paste the code into a text editor (e.g. Notepad).
  2. File -> Save As:
    • File Type: All Files
    • Filename: whatever.js
    (This works because .js files are plaintext.)
  3. Import that file as a plugin.
  4. Save your project to apply Plugin Manager changes.
  5. Test!
Something like this might work (untested):
Spoiler: plugin code
JavaScript:
/*:
 * @target MV MZ
 * @plugindesc The party command "Escape" costs MP.
 * @author Caethyril
 * @url https://forums.rpgmakerweb.com/posts/1540749/
 * @help Free to use and/or modify for any project.
 */
;void (function() {
"use strict";
  /** MP cost for party escape command. */
  const MP_COST = 75;

  /** If `true`, don't pay the escape cost on failed attempts. */
  const PAY_ONLY_ON_SUCCESS = false;

  /** @returns {boolean} `true` iff party escape cost can be paid. */
  const canPayEscapeCost = function() {
    return $gameParty.leader().mp >= MP_COST;
  };

  /** Applies party escape cost. */
  const payEscapeCost = function() {
    $gameParty.leader().gainMp(-MP_COST);
  };

  // Patch - pay cost for party escape when appropriate.
  void (function(alias) {
    BattleManager.processEscape = function() {
      const success = alias.apply(this, arguments);
      if (!PAY_ONLY_ON_SUCCESS || success)
        payEscapeCost();
    };
  })(BattleManager.processEscape);

  // Patch - party escape is only available when you can pay the cost.
  void (function(alias) {
    BattleManager.canEscape = function() {
      return alias.apply(this, arguments) && canPayEscapeCost();
    };
  })(BattleManager.canEscape);

})();
Note that the chance to escape is still based on the relative party/troop agility scores.

Plaintext-to-plugin instructions:
  1. Copy + paste the code into a text editor (e.g. Notepad).
  2. File -> Save As:
    • File Type: All Files
    • Filename: whatever.js
    (This works because .js files are plaintext.)
  3. Import that file as a plugin.
  4. Save your project to apply Plugin Manager changes.
  5. Test!
Thank you so much! This seems to work just fine for what I was intending!

Original thread: https://forums.rpgmakerweb.com/threads/changing-escape-formula-to-spend-mp-instead-of-agility.181458/