Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Changing Gameovers and Gameover themes mid-game

You'd think rmxp would already have events that let you change the gameover image along with the theme that plays with it, but I guess not.

I'm just looking for something easy to use when the script is called, like if I needed to change a gameover image, I'd type something like

@> Call Script: gameover(gameover 2)

Or if I needed to change the gameover ME, I'd type

@> Call Script: gme(boss defeat)

in order to specify both what I'm changing, and what I'm changing it to by writing the name of the script, and the exact name of the replacement file in paratheses.

Hope that makes sense.
 
$data_system.gameover_name = "name"
$data_system.gameover_me = \
AudioFile.new("name")

name is the filename without the extension
\ is because of the script command editor only has so much room
make sure there is no space after the \

Be Well
 
Sorry, that is what you would use in the Call Script event command at the point in the game when you want to change it.

Let's say, part way through the game you change the image & melody to:

$data_system.gameover_name = "gameover_image2"
$data_system.gameover_me = \
AudioFile.new("Audio/ME/gameover_me2")

Then, later you want to change it again

$data_system.gameover_name = "gameover_image3"
$data_system.gameover_me = \
AudioFile.new("Audio/ME/gameover_me3")

Now, if you came up with a standard, such as all files will be named: gameover_image#, and gameover_me#
where # is a number, we could modify Scene_Gameover to use a game variable as the suffix on the standard file name.

Insert a new script above 'Main'. (select main, right-click, Insert).
Paste the code below into the script, and give it a name (i.e.  Custom Scene_Gameover)

Code:
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
#  This class performs game over screen processing.
#  Add a suffix to the gameover file name to allow changing image & 
#==============================================================================

class Scene_Gameover
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make game over graphic
    @sprite = Sprite.new
    if $game_variables[1] > 0
      gameover_name = $data_system.gameover_name + $game_variables[1].to_s
      gameover_me_name = $data_system.gameover_me.name + $game_variables[1].to_s
    else
      gameover_name = $data_system.gameover_name
      gameover_me_name = $data_system.gameover_me.name
    end
    @sprite.bitmap = RPG::Cache.gameover(gameover_name)
    # Stop BGM and BGS
    $game_system.bgm_play(nil)
    $game_system.bgs_play(nil)
    # Play game over ME
    gameover_me = RPG::AudioFile.new(gameover_me_name)
    $game_system.me_play(gameover_me)
    # Execute transition
    Graphics.transition(120)
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of game over graphic
    @sprite.bitmap.dispose
    @sprite.dispose
    # Execute transition
    Graphics.transition(40)
    # Prepare for transition
    Graphics.freeze
    # If battle test
    if $BTEST
      $scene = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Switch to title screen
      $scene = Scene_Title.new
    end
  end
end

So, put your files in the following folders, and name them:

Graphics/Gameovers/gameover_image.jpg     (or .png)
Graphics/Gameovers/gameover_image1.jpg
Graphics/Gameovers/gameover_image2.jpg

Audio/ME/gameover_me.mid       (or .ogg, .mp3, .wav)
Audio/ME/gameover_me1.mid
Audio/ME/gameover_me2.mid

Now, in your database, on the system tab, select gameover_image.jpg as your Gameover Graphic,
and gameover_me.mid as your Gameover ME.

Then, when you want to use the files with the '1' suffix, change game variable 1 to 1

If you want to use a different variable, edit lines 16-17 of the script, where it says, "$game_variables[1]"
and change the [1] to the variable number you want to use.

Be Well


REF: Tosharu_message_wait
 
Okay, so I copy and paste the script to the script editor, and then I rename all of the images and me's to gameover_image#.png and gameover_me#.mp3, and then to change to them, I simply change the variable count for varibale no. 1, is that right so far?

So, in order to mix images and me's, would I need to import multiple copies of each under the same numbers? And if variable changing all there is to it, what use does the Call Script code have?

It feels as though you're offering two different ways to do it, but if you are, I really can't figure out either one.
 
Yes, that was 2 different options.

In the first option, use the Event Script Command above to change either the graphic or the ME.

Just cut/paste the command for the file you want to change into the Event Script Command editor,
and change the file name to the base name (no extension) of the file you want to use.

So, to change the image, use:

$data_system.gameover_name = "gameover_image2"

and change gameover_image2 to the filename you want to use.

To change the ME, use:

$data_system.gameover_me = \
AudioFile.new("Audio/ME/gameover_me2")



IN the second option, yes you have to rename your images & me's.
The first, or default file will not have a number.  (i.e.  my_gameover.png, or my_gameover_me.mid)
Each consecutive file will have a number that corresponds to the variable setting. (i.e.  my_gameover1.png, or my_gameover_me1.mid)
The name doesn't matter as long as they all match within one folder. (all the images have the same base name,
and all the sounds have the same base name.)
And yes, this will swap out both files at the same time. So, if you only want to change the image when you set
the variable to the next number, you would have to duplicate the sound file with both numbers.

If you're going to do a lot of mixing & matching, use the first option.


Here's another version of the script that will allow you to change only one at a time.
It still uses the variable, but if the file doesn't exist, it will use the previous file.
So, if you have a gameover3.png, but you don't have a gameover_me3.mid, it will use
gameover3.png, and gameover_me2.mid

Code:
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
#  This class performs game over screen processing.
#  Add a suffix to the gameover file name to allow changing image & ME
#==============================================================================

class Scene_Gameover
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make game over graphic
    @sprite = Sprite.new
    gameover_name = $data_system.gameover_name
    gameover_me_name = $data_system.gameover_me.name
    if $game_variables[1] > 0
      for i in 1..$game_variables[1]
        extensions = [".png", ".jpg"]
        for ext in extensions
          filetest = "Graphics/Gameovers/"
          filetest += $data_system.gameover_name + i.to_s
          filetest += ext
          if FileTest.exist?(filetest)
            gameover_name = $data_system.gameover_name + i.to_s
          end
        end
        extensions = [".mid", ".ogg", ".wma", ".mp3", ".wav"]
        for ext in extensions
          filetest = "Audio/ME/"
          filetest += $data_system.gameover_me.name + i.to_s
          filetest += ext
          if FileTest.exist?(filetest)
            gameover_me_name = $data_system.gameover_me.name + i.to_s
          end
        end
      end
    end
    @sprite.bitmap = RPG::Cache.gameover(gameover_name)
    # Stop BGM and BGS
    $game_system.bgm_play(nil)
    $game_system.bgs_play(nil)
    # Play game over ME
    gameover_me = RPG::AudioFile.new(gameover_me_name)
    $game_system.me_play(gameover_me)
    # Execute transition
    Graphics.transition(120)
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of game over graphic
    @sprite.bitmap.dispose
    @sprite.dispose
    # Execute transition
    Graphics.transition(40)
    # Prepare for transition
    Graphics.freeze
    # If battle test
    if $BTEST
      $scene = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Switch to title screen
      $scene = Scene_Title.new
    end
  end
end


Another Option would be to just randomly pick an image & ME from whatever is available in the folder.
that would be kinda cool. Maybe I'll script that one up too.


Be Well
 
Ok, here's one that will randomly select an image & ME

All of the files MUST be named:  gameover_#.<ext>

where # is a number starting with 0, and increasing by one up to the max number of files.

There are 2 constants in the script, which you set to the max number of files for each file type
  MAX_GO = 2    # highest number for gameover image files
  MAX_ME = 1    # highest number for gameover ME files

set these to the number of files you want to use for each type
Code:
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
#  This class performs game over screen processing.
#
#  randomize the gameover image & ME
#  all files must be named:  "gameover_#.<ext>"
#  # is a number starting with 0.  I'm not checking for file existance,
#  so you need to have files with the numbers 0 - MAX_GO, MAX_ME
#  Set the MAX_ constants to the highest number for each file type
#==============================================================================

class Scene_Gameover
  MAX_GO = 2    # highest number for gameover image files
  MAX_ME = 1    # highest number for gameover ME files
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make game over graphic
    @sprite = Sprite.new
    gameover_name = "gameover_" 
    gameover_me_name = "gameover_"
    gameover_name += rand(MAX_GO + 1).to_s
    gameover_me_name += rand(MAX_ME + 1).to_s
    @sprite.bitmap = RPG::Cache.gameover(gameover_name)
    # Stop BGM and BGS
    $game_system.bgm_play(nil)
    $game_system.bgs_play(nil)
    # Play game over ME
    gameover_me = RPG::AudioFile.new(gameover_me_name)
    $game_system.me_play(gameover_me)
    # Execute transition
    Graphics.transition(120)
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of game over graphic
    @sprite.bitmap.dispose
    @sprite.dispose
    # Execute transition
    Graphics.transition(40)
    # Prepare for transition
    Graphics.freeze
    # If battle test
    if $BTEST
      $scene = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Switch to title screen
      $scene = Scene_Title.new
    end
  end
end

Be Well
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top