Advertisement
ezmash

Battle Result Switches (MV)

Nov 5th, 2015
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Battle Result Switches
  3. // by Shaz
  4. // Last Updated: 2015.11.05
  5. //=============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Turns on switches when a battle ends according to battle results
  9.  * @author Shaz
  10.  *
  11.  * @param Battle Won Switch
  12.  * @desc Switch ID to turn on if battle is won
  13.  * @default 0
  14.  *
  15.  * @param Battle Lost Switch
  16.  * @desc Switch ID to turn on if battle is lost
  17.  * @default 0
  18.  *
  19.  * @param Battle Escaped Switch
  20.  * @desc Switch ID to turn on if player escapes from battle
  21.  * @default 0
  22.  *
  23.  * @param Battle Abort Switch
  24.  * @desc Switch ID to turn on if battle is aborted
  25.  * @default 0
  26.  *
  27.  * @help This plugin does not provide plugin commands.
  28.  *
  29.  * When calling a Battle from an event command, you can set up actions to
  30.  * happen after the battle is over, depending on whether the party won, lost
  31.  * or escaped.
  32.  *
  33.  * This can't be done by default with random encounters set up on a map,
  34.  * as there is no calling event.
  35.  *
  36.  * This plugin allows you to turn on a switch when a battle is won, lost,
  37.  * or escaped, which you can then use to control map events or common events.
  38.  *
  39.  * Use 0 as a parameter to indicate not to turn on a switch for that
  40.  * condition.  All of these switches will be turned off at the start
  41.  * of battle.
  42.  */
  43.  
  44. (function() {
  45.  
  46.   var parameters = PluginManager.parameters('BattleResultSwitches');
  47.   var winSwitch = Number(parameters['Battle Won Switch'] || 0);
  48.   var loseSwitch = Number(parameters['Battle Lost Switch'] || 0);
  49.   var escapeSwitch = Number(parameters['Battle Escaped Switch'] || 0);
  50.   var abortSwitch = Number(parameters['Battle Abort Switch'] || 0);
  51.  
  52.   var _BattleManager_setup = BattleManager.setup;
  53.   BattleManager.setup = function(troopId, canEscape, canLose) {
  54.     _BattleManager_setup.call(this, troopId, canEscape, canLose);
  55.     if (winSwitch !== 0) {
  56.       $gameSwitches.setValue(winSwitch, false);
  57.     }
  58.     if (loseSwitch !== 0) {
  59.       $gameSwitches.setValue(loseSwitch, false);
  60.     }
  61.     if (escapeSwitch !== 0) {
  62.       $gameSwitches.setValue(escapeSwitch, false);
  63.     }
  64.     if (abortSwitch !== 0) {
  65.       $gameSwitches.setValue(abortSwitch, false);
  66.     }
  67.   };
  68.  
  69.   var _BattleManager_processVictory = BattleManager.processVictory;
  70.   BattleManager.processVictory = function() {
  71.     _BattleManager_processVictory.call(this);
  72.     if (winSwitch !== 0) {
  73.       $gameSwitches.setValue(winSwitch, true);
  74.     }
  75.   };
  76.  
  77.   var _BattleManager_processEscape = BattleManager.processEscape;
  78.   BattleManager.processEscape = function() {
  79.     _BattleManager_processEscape.call(this);
  80.     if (escapeSwitch !== 0) {
  81.       $gameSwitches.setValue(escapeSwitch, true);
  82.     }
  83.   };
  84.  
  85.   var _BattleManager_processDefeat = BattleManager.processDefeat;
  86.   BattleManager.processDefeat = function() {
  87.     _BattleManager_processDefeat.call(this);
  88.     if (loseSwitch !== 0) {
  89.       $gameSwitches.setValue(loseSwitch, true);
  90.     }
  91.   };
  92.  
  93.   var _BattleManager_processAbort = BattleManager.processAbort;
  94.   BattleManager.processAbort = function() {
  95.     _BattleManager_processAbort.call(this);
  96.     // Only abort on an Abort Battle command, not when escaping
  97.     if (abortSwitch !== 0 && !this._escaped) {
  98.       $gameSwitches.setValue(abortSwitch, true);
  99.     }
  100.   }
  101.  
  102. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement