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.

Title Screen Based on Level

Noru

Member

I remember seeing this script on these forums awhile ago but when I searched for it, Had no luck finding it again. If anyone has a link to, That would be great.
For those who don't know what it is. Its a script I seen that changes the title screen based on your level. Any help looking for it would be great.
 

khmp

Sponsor

Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  TITLE_LEVELS = {
    (1...10)  => 'Title1.png', # For levels 1-9 use 'Title1.png'
    (10...20) => 'Title2.png', # For levels 10-19 use 'Title2.png'
    (20...40) => 'Title3.png', # For levels 20-39 use 'Title3.png'
  }
  TITLE_LEVELS.default = 'Title.png' # Default title to use.
  
  #--------------------------------------------------------------------------
  # HIGHEST_LEVEL
  #   True  : Decide title based on the highest level of the current party.
  #   False : Base title off of party leader.
  #--------------------------------------------------------------------------
  HIGHEST_LEVEL = true
  #--------------------------------------------------------------------------
  # * Main Processing !OVERRIDE!
  #--------------------------------------------------------------------------
  def main
    # If battle test
    if $BTEST
      battle_test
      return
    end
    # Load database
    $data_actors        = load_data("Data/Actors.rxdata")
    $data_classes       = load_data("Data/Classes.rxdata")
    $data_skills        = load_data("Data/Skills.rxdata")
    $data_items         = load_data("Data/Items.rxdata")
    $data_weapons       = load_data("Data/Weapons.rxdata")
    $data_armors        = load_data("Data/Armors.rxdata")
    $data_enemies       = load_data("Data/Enemies.rxdata")
    $data_troops        = load_data("Data/Troops.rxdata")
    $data_states        = load_data("Data/States.rxdata")
    $data_animations    = load_data("Data/Animations.rxdata")
    $data_tilesets      = load_data("Data/Tilesets.rxdata")
    $data_common_events = load_data("Data/CommonEvents.rxdata")
    $data_system        = load_data("Data/System.rxdata")
    # Make system object
    $game_system = Game_System.new
    # Make title graphic
    @sprite = Sprite.new
    # Make command window
    s1 = "New Game"
    s2 = "Continue"
    s3 = "Shutdown"
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    
    title = $data_system.title_name
    
    # Continue enabled determinant
    # Check if at least one save file exists
    # If enabled, make @continue_enabled true; if disabled, make it false
    @continue_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
        # If saves exist determine the title to use.
        title = decide_title_from_save(decide_latest_save)
        break
      end
    end
    
    @sprite.bitmap = RPG::Cache.title(title)
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    if @continue_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
    # Play title BGM
    $game_system.bgm_play($data_system.title_bgm)
    # Stop playing ME and BGS
    Audio.me_stop
    Audio.bgs_stop
    # Execute transition
    Graphics.transition
    # 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 command window
    @command_window.dispose
    # Dispose of title graphic
    @sprite.bitmap.dispose
    @sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Decide Latest Save File
  #--------------------------------------------------------------------------
  def decide_latest_save
    file_dates = []
    
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        file = File.open("Save#{i+1}.rxdata", "r")
        file_dates << [file.mtime, i + 1]
        file.close
      end
    end

    # Sort them by date
    file_dates.sort! {|a, b| b[0] <=> a[0] }
    
    return "Save#{file_dates.first[1]}.rxdata"
  end
  #--------------------------------------------------------------------------
  # * Decide what title to use
  #     save : the save file string.
  #--------------------------------------------------------------------------
  def decide_title_from_save(save)
    # Open the latest file.
    file = File.open(save, "r")
    
    # Initialize the party leader level.
    highest_level = 0
    
    # Partially load the file to get the party.
    
    characters         = Marshal.load(file)
    frame_count        = Marshal.load(file)
    game_system        = Marshal.load(file)
    game_switches      = Marshal.load(file)
    game_variables     = Marshal.load(file)
    game_self_switches = Marshal.load(file)
    game_screen        = Marshal.load(file)
    game_actors        = Marshal.load(file)
    game_party         = Marshal.load(file) # <- We need this one :(
    
    # Close the file it is no longer needed.
    file.close
    
    # Based on user specification determine highest_level.
    if HIGHEST_LEVEL
      # Highest party member's level.
      game_party.actors.each do |actors|
        highest_level = [highest_level, actors.level].max
      end
    else
      # Party leader level.
      highest_level = game_party.actors.first.level
    end

    # Iterate through the hash and decide what to do.
    TITLE_LEVELS.each do |level_range, title_screen|
      # If the character level is within the range.
      if level_range.to_a.include?(highest_level)
        # Return the title screen.
        return title_screen
      end
    end
    
    # If we reached here than the level was not within any range so we 
    # return to the default.
    return TITLE_LEVELS.default
  end
end

It overrides Scene_Title.main. There is one very important hash. A range is the key to a title image file name. What that means is that if inside that hash you have:
Code:
TITLE_LEVELS = { (40...50) => "Title.png" }
That means that if your party leader's or highest level character's level is between 40 and 49 than the Title background will be "Title.png"

The other constant near the top is a true false. If HIGHEST_LEVEL is true than the party's highest level will determine the title background. If it is false than the party leader's level will determine the background.

Good luck with it Noru! :thumb:
 

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