Tai-Iro

Can Lose (RMMV Plugin)

Aug 18th, 2016
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Can Lose
  3. // by Tairo
  4. // Last Updated: 2016.8.17
  5. //=============================================================================
  6.  
  7. /*:
  8.  * @plugindesc Allows player to lose all battles, including random battles, with no game over.
  9.  * @author Tairo
  10.  *
  11.  * @param Lose Common Event
  12.  * @desc The ID of the common event you want to run after each lost battle.
  13.  * @default 0
  14.  *
  15.  * @param Allow Game Over Switch
  16.  * @desc Switch ID to turn on and allow a game over (on = default RPG Maker behavior).
  17.  * @default 0
  18.  *
  19.  * @help
  20.  * ============================================================================
  21.  * How To Use
  22.  * ============================================================================
  23.  *
  24.  * This plugin causes all battles (random or event) to not cause a game over
  25.  * event after a loss, by default. No commands or parameters needed for the
  26.  * basic function, they're just for more control.
  27.  *
  28.  * The plugin is designed for those who wish to allow the player to lose a
  29.  * random encounter, just like an event battle.
  30.  *
  31.  * The first parameter also allows you to run a common event after a loss, or use
  32.  * a value of 0 to have no common event run.
  33.  *
  34.  * The second parameter is a switch for if you want to control the default
  35.  * behavior. Off for no game over default, on for normal RPG Maker behavior.
  36.  * Use 0 if you don't want to use a switch, so it always allow losses.
  37.  *
  38.  * The plugin commands are for when you want to change whether or not a game
  39.  * over will occur upon a loss in the middle of a battle, or to make certain
  40.  * troops/encounters (like bosses) cause a game over if lost to.
  41.  *
  42.  * Plugin Command:
  43.  *   CanLose false          # Makes it so a loss causes the game over event
  44.  *   CanLose true           # Makes it so a loss does not cause a game over
  45.  *   CanLose eventID 2      # Sets the event ID to 2, and prints in the console
  46.  *   CanLose checkSwitch    # Returns ID of the switch & prints it in the console
  47.  *
  48.  * ============================================================================
  49.  * Terms Of Use
  50.  * ============================================================================
  51.  * Free to use and modify for commercial and noncommercial games, with credit.
  52.  * ============================================================================
  53.  * Credits
  54.  * ============================================================================
  55.  * Tairo
  56.  */
  57.  
  58. (function() {
  59.    
  60.     var parameters = PluginManager.parameters('CanLose');
  61.     var loseEvent = Number(parameters['Lose Common Event'] || 0);
  62.     var allowSwitch = Number(parameters['Allow Game Over Switch'] || 0);
  63.    
  64.     var _BattleManager_setup = BattleManager.setup;
  65.     BattleManager.setup = function(troopId, canEscape, canLose) {
  66.         if(allowSwitch == 0 || $gameSwitches.value(allowSwitch) == false) {
  67.             _BattleManager_setup.call(this, troopId, canEscape, true);
  68.         }
  69.         else {
  70.             _BattleManager_setup.call(this, troopId, canEscape, canLose);
  71.         }
  72.         /*this.initMembers();
  73.         this._canEscape = canEscape;*/
  74.         //this._canLose = true;//canLose;
  75.         /*$gameTroop.setup(troopId);
  76.         $gameScreen.onBattleStart();
  77.         this.makeEscapeRatio();*/
  78.     };
  79.    
  80.     var _BattleManager_processDefeat = BattleManager.processDefeat;
  81.     BattleManager.processDefeat = function() {
  82.         _BattleManager_processDefeat.call(this);
  83.         if (loseEvent !== 0) {
  84.             $gameTemp.reserveCommonEvent(loseEvent);
  85.         }
  86.     };
  87.    
  88.     var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  89.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  90.         _Game_Interpreter_pluginCommand.call(this, command, args);
  91.         if (command === 'CanLose') {
  92.             switch (args[0]) {
  93.             case 'false':
  94.                 BattleManager._canLose = false;
  95.                 console.log("Current fight will cause game-over if lost.");
  96.                 break;
  97.             case 'true':
  98.                 BattleManager._canLose = true;
  99.                 console.log("Current fight will not cause a game-over if lost.");
  100.                 break;
  101.             case 'eventID':
  102.                 loseEvent = Number(args[1]);
  103.                 parameters['Lose Common Event'] = Number(args[1]);
  104.                 console.log("Event in Parameter: " + parameters['Lose Common Event'] + " & Event in code: " + loseEvent);
  105.                 break;
  106.             case 'checkSwitch':
  107.                 return allowSwitch;
  108.                 console.log("Switch " + allowSwitch + " is " + $gameSwitches.value(Number(parameters['Allow Game Over Switch'])) + " " + $gameSwitches.value(allowSwitch));
  109.                 break;
  110.             }
  111.         }
  112.     };
  113.    
  114.   /* This function can be found in rpg_managers.js
  115.  
  116.     BattleManager.setup = function(troopId, canEscape, canLose) {
  117.     this.initMembers();
  118.     this._canEscape = canEscape;
  119.     this._canLose = canLose;
  120.     $gameTroop.setup(troopId);
  121.     $gameScreen.onBattleStart();
  122.     this.makeEscapeRatio();
  123.     };
  124.  
  125.   */
  126.  
  127. })();
RAW Paste Data