Tweaking this checkpoint script

Bravo's checkpoint script located here:

Spoiler
#==============================================================================
# Bravo Checkpoint System
#------------------------------------------------------------------------------
# Author: Bravo2Kilo
# Version: 1.0a
#
# Version History:
# v1.0 = Initial Release
# v1.0a = Fixed a bug
#==============================================================================
# To set a checkpoint use this in an event script call
# set_checkpoint
#
# To add/remove lives use this in an event script call
# add_life(amount) amount = the amount of lives to want to add/remove
#==============================================================================
module BRAVO_CHECKPOINT
# Switch to activate/deactivate the checkpoint respawning on death.
CHECKPOINT_SWITCH = 1
# Switch to activate/deactivate the life system. When activated the player
# must have a life to respawn.
LIFE_SWITCH = 2
# Method for restoring health upon respawning. Values are 1, 2, or 3
# When 1 the actors hp will be set to 1, When 2 the actors hp will be set to max
# When 3 the actors hp will be restored by a percentage(percent set below)
HP_RESTORE = 2
# If the above is set to 3 this will be the percent restored
HP_PERCENT = 100
# This is the percent of exp points loss upon respawning
EXP_LOSS = 5
# This is the percent of gold loss upon respawning.
GOLD_LOSS = 10
#==============================================================================
# END OF CONFIGURATION
#==============================================================================
end
$imported ||= {}
$imported[:Bravo_Checkpoint] = true

#==============================================================================
# ** BattleManager
#==============================================================================

module BattleManager
#--------------------------------------------------------------------------
# * Defeat Processing
#--------------------------------------------------------------------------
def self.process_defeat
$game_message.add(sprintf(Vocab:😀efeat, $game_party.name))
wait_for_message
if @can_lose
revive_battle_members
replay_bgm_and_bgs
SceneManager.return
else
replay_bgm_and_bgs
SceneManager.scene.check_gameover
end
battle_end(2)
return true
end
end

#==============================================================================
# ** Scene_Base
#==============================================================================

class Scene_Base
#--------------------------------------------------------------------------
# * Determine if Game Is Over
#--------------------------------------------------------------------------
alias bravo_checkpoint_check_gameover check_gameover
def check_gameover
if $game_party.all_dead?
if $game_switches[BRAVO_CHECKPOINT::CHECKPOINT_SWITCH] == true
if $game_switches[BRAVO_CHECKPOINT::LIFE_SWITCH] == true
if $game_party.checkpoint_life == 0
bravo_checkpoint_check_gameover
else
process_respawn
$game_party.checkpoint_life -= 1
end
else
process_respawn
end
else
bravo_checkpoint_check_gameover
end
end
end
#--------------------------------------------------------------------------
# * Process Respawn
#--------------------------------------------------------------------------
def process_respawn
$game_party.battle_members.each do |actor|
if BRAVO_CHECKPOINT::HP_RESTORE == 1
actor.hp = 1 if actor.dead?
elsif BRAVO_CHECKPOINT::HP_RESTORE == 2
actor.hp = actor.mhp if actor.dead?
elsif BRAVO_CHECKPOINT::HP_RESTORE == 3
amount = (BRAVO_CHECKPOINT::HP_PERCENT * 0.01) * actor.mhp
actor.hp = amount.to_i if actor.dead?
end
current_exp = actor.exp - actor.current_level_exp
exp_loss = (BRAVO_CHECKPOINT::GOLD_LOSS * 0.01) * current_exp
actor.change_exp(actor.exp - exp_loss.to_i, false)
end
gold_loss = (BRAVO_CHECKPOINT::GOLD_LOSS * 0.01) * $game_party.gold
$game_party.lose_gold(gold_loss.to_i)
$game_map.setup($game_party.checkpoint_mapid)
SceneManager.goto(Scene_Map)
$game_player.moveto($game_party.checkpoint_x, $game_party.checkpoint_y)
$game_player.set_direction($game_party.checkpoint_dir)
end
end

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :checkpoint_life
attr_reader :checkpoint_mapid
attr_reader :checkpoint_x
attr_reader :checkpoint_y
attr_reader :checkpoint_dir
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias bravo_checkpoint_initialize initialize
def initialize
bravo_checkpoint_initialize
@checkpoint_life ||= 0
end
#--------------------------------------------------------------------------
# * Set Checkpoint
#--------------------------------------------------------------------------
def set_checkpoint
@checkpoint_mapid = $game_map.map_id
@checkpoint_x = $game_player.x
@checkpoint_y = $game_player.y
@checkpoint_dir = $game_player.direction
end
end

#==============================================================================
# ** Game_Interpreter
#==============================================================================

class Game_Interpreter
#--------------------------------------------------------------------------
# * Set Checkpoint
#--------------------------------------------------------------------------
def set_checkpoint
$game_party.set_checkpoint
end
#--------------------------------------------------------------------------
# * Add Life
#--------------------------------------------------------------------------
def add_life(amount)
$game_party.checkpoint_life += amount
end
end

I want to tweak it just a bit.

What happens when you die is that it instantly goes to the checkpoint in a seamless transition. I would like for it to first go to a screen that says "You died" with music playing, THEN transition into the checkpoint. Not sure how I would go about making this script.
Some theory-crafting, but I'm basing this on how I made my Splash Screen.

1. In process_respawn under this script's Scene_Base, there is a
Code:
$game_map.setup($game_party.checkpoint_mapid)
SceneManager.goto(Scene_Map)
$game_player.moveto($game_party.checkpoint_x, $game_party.checkpoint_y)
$game_player.set_direction($game_party.checkpoint_dir)
We should copy this code and replace it with
SceneManager.goto(Scene_YouDied)

2. We need to create Scene_YouDied. We should copy Scene_GameOver since it has the majority of what we need. First, you need to change the class from Scene_GameOver to Scene _YouDied. Next, under the goto_title method, we replace
SceneManager.goto(Scene_Title) with the checkpoint stuff we copied earlier.

So at the basic, respawning makes you go to the YOU DIED screen, which will then make you go to your checkpoint.

---

3. But since we copied the Scene_Gameover, the picture and sound it uses are associated with Gameover functions. Specifically, you need to change
@sprite.bitmap = Cache.system("GameOver") under create_background and
$data_system.gameover_me.play under play_gameover_music.

a. You can simply replace "GameOver" with your "YouDied" (assuming you have that picture), but the Cache will take this from your System graphics folder. So alternatively, you could use Cache.picture("YouDied") if you place the file in the Pictures folder or
load_bitmap("Graphics/Pictures/", "YouDied") and replace your folder in the first part.

b. Replace $data_system.gameover_me.play with Audio.me_play("Audio/ME/YouDied"). me_play should access the file from the ME folder, so you could use se_play, bgm_play or bgs_play for the respective folder. All of these can also use Audio.me_play("YouDied", 100, 100) where the first 100 represents volume and the second 100 represents pitch.
@Harosata

Thanks this works, however after the You Died screen it continues to play the "You Died" music after you respawn at the checkpoint. I'd like to to play whatever music is active within the scene (the scene where you spawn at the checkpoint).

Also, is it possible to make the fade in longer after the "You Died" scene? It seems like it fades in way too quickly to the checkpoint.

Also, how difficult would it be to implement a text box at the You died scene? I could just create more texts in the picture, but I'd like a small message at the bottom that says "would you like to continue"? Then if you hit yes it would go to checkpoint, no would go to title screen.
1. Add $game_map.autoplay after you go back to the map (should be where we put the checkpoint thing in the goto_title method)

2. This one is a bit tricky since the fade in you're asking for is part of the Scene_Map (Scene_GameOver covers both fades from map/battle to scene and fadeout_all from scene to map. And I took care of it.

First, add a global switch like one of the $game_switches[something] (replace something with a number) to goto_title and set it to true. Next, we also add this little snippet
Code:
class Scene_Map < Scene_Base
  def fadein_speed
  if $game_switches[something]
    $game_switches[something] = false
    return 120
  else
    return 30
  end
  end
end
Pretty much this returns the normal fade in speed unless you have a switch turned on, which should only be possible from our script.

3. For Textboxes, it would have been better to copy Scene_Title. Actually, it'll be a hassle to explain all the steps, so just replace the old YouDied script with this one:
Code:
class Scene_Map < Scene_Base
  def fadein_speed
  if $game_switches[50]
    $game_switches[50] = false
    return 120
  else
    return 30
  end
  end
end

class Scene_YouDied < Scene_Base

  def start
    super
    SceneManager.clear
    Graphics.freeze
    create_background
    create_command_window
    play_title_music
  end

  def transition_speed
    return 20
  end

  def terminate
    super
    SceneManager.snapshot_for_background
    dispose_background
  end

  def create_background
    @sprite1 = Sprite.new
    @sprite1.bitmap = Cache.system("YouDied")
    center_sprite(@sprite1)
  end

  def dispose_background
    @sprite1.bitmap.dispose
    @sprite1.dispose
  end

  def center_sprite(sprite)
    sprite.ox = sprite.bitmap.width / 2
    sprite.oy = sprite.bitmap.height / 2
    sprite.x = Graphics.width / 2
    sprite.y = Graphics.height / 2
  end

  def create_command_window
    @command_window = Window_GameEnd2.new
    @command_window.set_handler(:checkpoint, method(:command_checkpoint))
    @command_window.set_handler(:to_title, method(:command_title))
    @question_window = Window_Question.new
  end

  def close_command_window
    @command_window.close
    @question_window.close
    update until @command_window.close? and @question_window.close?
    
  end

  def command_title
    close_command_window
    fadeout_all
    SceneManager.goto(Scene_Title)
  end

  def command_checkpoint
    close_command_window
    fadeout_all
    $game_map.setup($game_party.checkpoint_mapid)
    SceneManager.goto(Scene_Map)
    $game_player.moveto($game_party.checkpoint_x, $game_party.checkpoint_y)
    $game_player.set_direction($game_party.checkpoint_dir)
    $game_map.autoplay
    $game_switches[50] = true
  end

  def play_title_music
    RPG::BGM.stop
    RPG::BGS.stop
    RPG::ME.stop
    Audio.me_play("Audio/ME/YouDied")
  end
end




class Window_GameEnd2 < Window_Command
  def initialize
    super(0, 0,)
    update_placement
    self.openness = 0
    open
  end

  def window_width
    return 160
  end
  
  def update_placement
    self.x = (Graphics.width - width)
    self.y = (Graphics.height - height)
  end

  def make_command_list
    add_command("Yes", :checkpoint)
    add_command("No", :to_title)
  end
end


class Window_Question < Window_Base

  def initialize
    super(0, 0, window_width, fitting_height(1))
    update_placement
    self.openness = 0
    open
  end

  def window_width
    return 300
  end

  def update_placement
    self.x = (Graphics.width - width)
    self.y = (Graphics.height - height * 2.5)
  end

  def refresh
    contents.clear
    draw_text(0, 0, window_width, line_height, "Would you like to continue?")
  end
  def open
    refresh
    super
  end
end

So yeah, the fade in snippet is on top (Switch 50 by default), and included are the two windows for the question and going to the checkpoint/title.
Thanks, it seems to work I just need to know how to make the fade in even longer, and also I would like to know how to make a long pause before the text box pops up. So you see "You Died" then maybe 200frames THEN the text box pops up.
1. If you mean the speed from Checkpoint to Map, it's in that Scene_Map Scriplet. The number under the switch is that, and the number under else is the normal transition speed from battle/map to map. In other words, this is the 120 and 30 in the scriplet, and 120 is the number related to the Checkpoint script. If you mean the speed from battle/map to Checkpoint, the Scene_Title uses transition_speed.

Speaking of transition_speed, Scene_Title's transition goes from map to pic instead of map to black to pic. If you want the map-to-black-to-pic transition, place Graphics.transition(60) before Graphics.freeze under Scene_YouDied's start method, with 60 being your fade-out frames.

---

2. Anyway, place this in your Scene_YouDied
Code:
  def perform_transition
    Graphics.transition(transition_speed)
    Graphics.wait(200)
  end

Both transition and wait will make the windows pop up later, though it should be obvious that transition changes the picture and wait doesn't do anything to the picture, aka the screen would shift/fade into the You Died screen for 30 frames and then show the You Died screen for 200 frames before the windows pop up. You can change the transition speed to what you want.

===

Review of Fades for this script:
Transition speed is by frames, about 60 frames per second.
Fade out 1- Can be defined in start
Fade in 1- Defined in perform_transition or by changing transition_speed
Fade out 2- fadeout_all(number) under command_title and command_checkpoint, where number is 1000 by default, with 1000 equal to about 1 second.
Fade in 2- Part of the next scene aka Scene_Map
Alright, I think I have it working how I want it. Thansk Harosata.
@Harosata

Not sure if I should make a new thread or not, but I'm still working with this checkpoint script in a new way if anyone can help me.

My problem is that when I get to an event cutscene, for example, a boss fight.

If the player dies during the boss fight then the checkpoint will just make it so it is as though he won the fight and the cutscene continues.

I'm wondering if I can do something like transfer the player into my YouDied screen if they lose the fight, and hopefully that means the cutscene will start from the beginning when they return to that point. Would this work?
I think you may be mistaken. I tested this script and a Game Over that goes to the map, and it seems that events are designed to process the whole page; New Game and Continue load data which is why you wouldn't see the second half of the cutscene, so one of those loaded item would "reset" the event. Data manipulation or event manipulation isn't something I have dabbled in yet, so I would need time to test this.

Anyway, I'm guessing your cutscene structure is text-battle-text, though the checkpoint means losing would make it text-battle-checkpoint-text. This is the same processing as text-menu/save-text: you only need to end that process and get back to the map, not win it. Until I can find a good fix, you might have to make battles with Win-Lose conditions (text-battle>win(text)>lose(die)), with all your cutscene under Win and a
SceneManager.goto(Scene_YouDied) script call under Lose.

The small edit I can offer if you'd rather go to the checkpoint from the battle rather than the map is to go to the Checkpoint script's process_defeat under BattleManager and replace
SceneManager.return with $game_switches[something] ? SceneManager.return : SceneManager.scene.check_gameover so you don't need to place a script call in Lose. I placed the switch there in case you have battles where losing continues the game (you could also turn the switch off at the end of the method so you only need to turn it on for certain battles).

---

Edit: Just realized there is an Exit Event Processing button which can exit the event right there. In theory, I just need $game_map.events[@event_id].interpreter.command_115...But if I can get that to work, then you should be able to write text-battle-text again.

If you are going this route, I suggest placing that line somewhere in the checkpoint script or YouDied script, though the earliest would be just above SceneManager.scene.check_gameover in the process_defeat of the Checkpoint's BattlManager. If @event_id doesn't work, you'll have to store the event id in a variable.
SceneManager.goto(Scene_YouDied) in Lose condition does the trick quite nicely, thanks. It makes it so it goes directly to the death screen and then restarts the entire cutscene when you reach that point again.

Now all I need is a possible cutscene skip button or something, but that is another thread. Thanks for the help Harosata.

Original thread: https://forums.rpgmakerweb.com/threads/tweaking-this-checkpoint-script.75820/