Advertisement
McKathlin

McKathlin Custom Game Over plugin

Feb 7th, 2021
3,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Custom Game Over, version 1.3
  3. // by McKathlin
  4. // Kath_GameOver.js
  5. // Last Update: 2016.08.18
  6. //=============================================================================
  7.  
  8. /*:
  9.  * @plugindesc Change what happens when the party dies or Game Over is called.
  10.  *
  11.  * @param Party Death Common Event ID
  12.  * @desc The ID of the common event to run as soon as the party dies.
  13.  * Leave blank to fade immediately to Game Over.
  14.  * @default
  15.  *
  16.  * @param Show Game Over Scene
  17.  * @desc Whether to show Scene_Gameover. If false, only a brief fade to black is seen.
  18.  * @default true
  19.  *
  20.  * @param Reload Last Save
  21.  * @desc If true, reload from last save instead of title screen,
  22.  * or before common event, if any.
  23.  * @default false
  24.  *
  25.  * @param After Game Over Common Event ID
  26.  * @desc The ID of the common event to run AFTER the Game Over scene (or fadeout).
  27.  * Leave blank to go to title.
  28.  * @default
  29.  *
  30.  * @help This plugin is designed to play well by itself and with other plugins.
  31.  * There are no known conflicts, but conflict is possible with other plugins
  32.  * that directly alter Game Over behavior.
  33.  *
  34.  * ================================
  35.  * = Party Death Common Event ID  =
  36.  * ================================
  37.  * Assigning a Party Death Common Event replaces the usual Game Over scene
  38.  * call with a common event call. This lets you (the game designer) make
  39.  * something happen instead of (or before) the standard Game Over screen.
  40.  * Open the database to Common Events to find the ID of the common event
  41.  * to call on party death, and enter this ID number as the parameter.
  42.  * Here are some pointers:
  43.  * * The Party Death common event will run in the same scene where the party
  44.  *   was just defeated. If the party died in battle, the common event will run
  45.  *   in battle, right after the party-is-defeated message and music effect.
  46.  *   So if you want to make something happen after a slow fadeout
  47.  *   and return to the map, I recommend using the After Game Over Common Event
  48.  *   instead.
  49.  * * If you would like the Game Over screen (or a fadeout and cut to the map
  50.  *   if "Show Game Over Scene" is false) to show at the end of your common
  51.  *   event, remember to use the Game Over command in your common event.
  52.  *   Avoiding the Game Over screen is easy: avoid calling the Game Over command.
  53.  * * Directly calling the Game Over command from any event will still show
  54.  *   the Game Over screen normally (unless you've set Show Game Over Scene to
  55.  *   false). To force your custom party death behavior, use a command that
  56.  *   calls your party death common event instead.
  57.  *
  58.  * =========================
  59.  * = Show Game Over Scene  =
  60.  * =========================)
  61.  * RPG Maker's default behavior takes the player to Scene_GameOver on
  62.  * party death or on a scene processing call to Scene_GameOver.
  63.  * This processing shows a Game Over screen.
  64.  * After the player sees the screen and presses any key,
  65.  * the game exits to the title screen.
  66.  *
  67.  * If Show Game Over Scene is set to false, player will see a fade to black
  68.  * before going to the next scene. This will be the case regardless of whether
  69.  * Game Over state is reached by party death or by a direct command in an event.
  70.  *
  71.  * Whether or not the Game Over screen shows, which scene is next depends on
  72.  * whether the After Game Over Common Event is set, and what it is set to.
  73.  *
  74.  * ====================
  75.  * = Reload Last Save =
  76.  * ====================
  77.  * Set Reload Last Save to true to make the game automatically reload from its
  78.  * most recent save on game over. If a Game Over Common Event is specified,
  79.  * the reload occurs before the common event is reserved. If no common event
  80.  * is given, then the reload happens instead of going to the title screen.
  81.  *
  82.  * If Reload Last Save is true but the player has not yet saved,
  83.  * then the player is returned to the Title Screen.
  84.  *
  85.  * ====================================
  86.  * = After Game Over Common Event ID  =
  87.  * ====================================
  88.  * Assigning a After Game Over common event makes gameplay continue after
  89.  * the party loses, instead of RPG Maker's default behavior of returning the
  90.  * party to the title screen. Open the database to Common Events to find the
  91.  * ID of the common event to call on game over, and enter this ID number as
  92.  * the parameter.
  93.  *
  94.  * In the content of the common event, the game designer can customize what
  95.  * happens when the party dies or reaches an event-dictated Game Over state.
  96.  * The After Game Over common event might do some of the following things:
  97.  * * Take away gold and/or items
  98.  * * Return the player to a safe place
  99.  * * Restore HP to one or more party members
  100.  * * Have the party's rescuer say something
  101.  * * ...anything that suits this game!
  102.  *
  103.  * IMPORTANT: When control flows to the Game Over common event,
  104.  * the screen will start blacked out. This gives the event time to handle
  105.  * transfers and other processing before showing the player the screen.
  106.  * Once those things are ready, remember to fade in!
  107.  *
  108.  * The After Game Over Common Event (AGOCE) differs from the Party Death Common
  109.  * Event (PDCE) in the following ways:
  110.  * * The PDCE runs instead of or before the Game Over screen or fadeout;
  111.  *   the AGOCE runs after the Game Over scene or fadeout completes.
  112.  * * The PDCE only automatically replaces Game Overs caused by party death.
  113.  *   The AGOCE autoruns after all Game Overs, regardless of their cause.
  114.  * * The PDCE runs in the same scene where party death occurred.
  115.  *   The AGOCE runs in a newly started map scene, with the screen faded to
  116.  *   black, and the party leader revived to 1 HP.
  117.  */
  118.  
  119. var Imported = Imported || {};
  120. Imported.Kath_GameOver = true;
  121.  
  122. //=============================================================================
  123. // Helper method: parseBoolean
  124. //=============================================================================
  125. var Kath = Kath || {};
  126. Kath.Core = Kath.Core || {};
  127.  
  128. // Convert a user-entered string into a Boolean true or false value.
  129. Kath.Core.parseBoolean = function(parameter, defaultValue) {
  130.     switch (String(parameter).trim().toLowerCase()) {
  131.         case 'true':
  132.         case 't':
  133.         case 'yes':
  134.         case 'y':
  135.         case 'on':
  136.         case '1':
  137.             return true;
  138.         case 'false':
  139.         case 'f':
  140.         case 'no':
  141.         case 'n':
  142.         case 'off':
  143.         case '0':
  144.             return false;
  145.         default:
  146.             return defaultValue;
  147.     } // end switch
  148. };
  149.  
  150. //=============================================================================
  151. // Parameters and Constants
  152. //=============================================================================
  153.  
  154. Kath.Parameters = PluginManager.parameters('Kath_GameOver');
  155. Kath.Param = Kath.Param || {};
  156.  
  157. Kath.Param.PartyDeathCommonEventID =
  158.     Number.parseInt(Kath.Parameters['Party Death Common Event ID']);
  159. Kath.Param.ShowGameOverScene =
  160.     Kath.Core.parseBoolean(Kath.Parameters['Show Game Over Scene'], true);
  161. Kath.Param.ReloadLastSave =
  162.     Kath.Core.parseBoolean(Kath.Parameters['Reload Last Save'], false);
  163. Kath.Param.AfterGameOverCommonEventID =
  164.     Number.parseInt(Kath.Parameters['After Game Over Common Event ID']);
  165.  
  166. Kath.GameOver = {};
  167. Kath.GameOver.RELOAD_FADE_DELAY = 60;
  168.  
  169. //=============================================================================
  170. // Party death common event
  171. //=============================================================================
  172.  
  173. // Replacement method
  174. // Like original, but with handling added for Party Death Common Event case.
  175. BattleManager.processDefeat = function() {
  176.     this.displayDefeatMessage();
  177.     this.playDefeatMe();
  178.     if (this._canLose) {
  179.         this.replayBgmAndBgs();
  180.         this.endBattle(2);
  181.     } else {
  182.         AudioManager.stopBgm();
  183.         if (Kath.Param.PartyDeathCommonEventID) {
  184.             $gameParty.reviveLeader();
  185.             $gameTemp.reserveCommonEvent(Kath.Param.PartyDeathCommonEventID);
  186.             $gameTroop.setupBattleEvent(); // Run the reserved common event.
  187.             // the battle doesn't end here in this case,
  188.             // unless a scene control command ends it in the common event.
  189.         } else {
  190.             this.endBattle(2);
  191.         }
  192.     }
  193. };
  194.  
  195. // replacement method
  196. Scene_Base.prototype.checkGameover = function() {
  197.     if ($gameParty.isAllDead()) {
  198.         if (Kath.Param.PartyDeathCommonEventID) {
  199.             $gameParty.reviveLeader();
  200.             $gameTemp.reserveCommonEvent(Kath.Param.PartyDeathCommonEventID);
  201.         } else {
  202.             SceneManager.goto(Scene_Gameover);
  203.         }
  204.     }
  205. };
  206.  
  207. Game_Party.prototype.reviveLeader = function() {
  208.     if ($gameParty.isAllDead()) {
  209.         $gameParty.leader().setHp(1);
  210.         $gameParty.leader().clearStates();
  211.     }
  212. };
  213.  
  214. //=============================================================================
  215. // Skip Game Over Scene
  216. // Redefine several methods of Scene_GameOver
  217. // so that it skips straight to the next scene.
  218. //=============================================================================
  219.  
  220. if (!Kath.Param.ShowGameOverScene) {
  221.     Scene_Gameover.prototype.create = function() {
  222.         Scene_Base.prototype.create.call(this);
  223.         //this.playGameoverMusic(); // No music.
  224.         this.createBackground();
  225.     };
  226.  
  227.     Scene_Gameover.prototype.start = function() {
  228.         Scene_Base.prototype.start.call(this);
  229.         //this.startFadeIn(this.slowFadeSpeed(), false); // No fadein.
  230.     };
  231.  
  232.     Scene_Gameover.prototype.update = function() {
  233.         // Do not require a trigger.
  234.         if (this.isActive() && !this.isBusy()) {
  235.             this.gotoTitle();
  236.         }
  237.         Scene_Base.prototype.update.call(this);
  238.     };
  239.  
  240.     Scene_Gameover.prototype.createBackground = function() {
  241.         // Load image to avoid potential conflicts.
  242.         this._backSprite = new Sprite();
  243.         this._backSprite.bitmap = ImageManager.loadSystem('GameOver');
  244.         //this.addChild(this._backSprite); // But don't show it!
  245.     };
  246. }
  247.  
  248. // new method
  249. Kath.GameOver.findPostGameOverSceneClass = function() {
  250.     if (Kath.Param.ReloadLastSave) {
  251.         if (DataManager.isThisGameFile(DataManager.lastAccessedSavefileId())) {
  252.             return Scene_Map;
  253.         } else {
  254.             return Scene_Title;
  255.         }
  256.     } else if (Kath.Param.AfterGameOverCommonEventID) {
  257.         return Scene_Map;
  258.     } else {
  259.         return Scene_Title;
  260.     }
  261. };
  262.  
  263. //=============================================================================
  264. // After-Game-Over behavior. This includes reload last save, if called for.
  265. //=============================================================================
  266.  
  267. if (Kath.Param.ReloadLastSave) {
  268.     // extended method
  269.     Kath.GameOver.Scene_Gameover_gotoTitle = Scene_Gameover.prototype.gotoTitle;
  270.     Scene_Gameover.prototype.gotoTitle = function() {
  271.         var saveId = DataManager.lastAccessedSavefileId();
  272.         if (!DataManager.isThisGameFile(saveId)) {
  273.             // This game hasn't been saved yet. Go to the title screen.
  274.             return Kath.GameOver.Scene_Gameover_gotoTitle.call(this);
  275.         }
  276.         DataManager.loadGame(saveId);
  277.         $gamePlayer.requestMapReload();
  278.         $gameScreen.startFadeOut(1); // start next scene blacked out
  279.         if (Kath.Param.AfterGameOverCommonEventID > 0) {
  280.             $gameTemp.reserveCommonEvent(Kath.Param.AfterGameOverCommonEventID);
  281.             SceneManager.goto(Scene_Map);
  282.         } else {
  283.             SceneManager.goto(Scene_Map);
  284.             // Transfer to where we are, to set BGM, map fadein, etc.
  285.             $gamePlayer.reserveTransfer($gameMap.mapId(),
  286.                 $gamePlayer.x, $gamePlayer.y, $gamePlayer.direction(), 0);
  287.             $gameScreen.startFadeIn(this.slowFadeSpeed());
  288.         }
  289.     };
  290. } else if (Kath.Param.AfterGameOverCommonEventID > 0) {
  291.     // replacement method
  292.     Scene_Gameover.prototype.gotoTitle = function() {
  293.         $gameScreen.startFadeOut(1); // start next scene blacked out
  294.         $gameParty.reviveLeader();
  295.         $gameTemp.reserveCommonEvent(Kath.Param.AfterGameOverCommonEventID);
  296.         SceneManager.goto(Scene_Map);
  297.     };
  298. }
  299.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement