Export to a New Game Plus
#1
Export to a New Game Plus
by EmilyAnnCoons
Jan 14 2007

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


This is an edit of my Export-Import system to make it work with Scene New Game Plus. However, New Game Plus cannot be removed from it, so please don't try to remove it...if you want the export import system, just go here.

If anyone is familiar with Deke's New Game Plus script, then you all know what this is. For those that don't, New Game Plus is a script that allows the player to save their game at the end (you have to open the save window) and then replay the game over again, using the "New Game Plus" feature. This allows you to add things into the game when the player plays a second time (such as bonus artwork, otherwise in-accessible areas, etc.)

This is an edit of the New Game Plus script to make it work better (it really does). Originally, New Game Plus searched for a specific switch to be on, this caused a glitch that the player can take a "New Game Plus" save and continue to replay it, thus allowing the player to do things like get a bunch of bonus stuff at the beginning, then sell it off for massive money, etc. This script removes that glitch. This uses my export system to make New Game Plus search for a .export file instead of a .rxdata (or .sav for those with unedited scripts) thus keeping the player from being able to glitch the game. It ALSO allows the player to then take their characters out of the game and put them in the sequel to your game (for that, you'd then need to get the export import system, as I don't have an Import New Game Plus yet...sorry...)

With that said, just copy the following scripts and put them above Main, but below Scene_Debug.
Code:
#==============================================================================
# ** Window_ExportFile
#------------------------------------------------------------------------------
#  This window displays save files on the save and load screens.
#==============================================================================

class Window_ExportFile < Window_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :exportname               # file name
  attr_reader   :selected                 # selected
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     file_index : save file index (0-3)
  #     filename   : file name
  #--------------------------------------------------------------------------
  def initialize(file_index, exportname)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @exportname = "E#{@file_index + 1}.export"
    @file_exist = FileTest.exist?(@exportname)
    if @file_exist
      export = File.open(@exportname, "r")
      @characters = Marshal.load(export)
      @frame_count = Marshal.load(export)
      @game_system = Marshal.load(export)
      @game_switches = Marshal.load(export)
      @game_variables = Marshal.load(export)
      export.close
    end
    refresh
    @selected = false
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    # Draw file number
    self.contents.font.color = normal_color
    name = "Export #{@file_index + 1}"
    self.contents.draw_text(4, 0, 600, 32, name)
    @name_width = contents.text_size(name).width
    # If save file exists
    if @file_exist
      # Draw character
      for i in 0...@characters.size
        bitmap = RPG::Cache.character(@characters[i][0], @characters[i][1])
        cw = bitmap.rect.width / 4
        ch = bitmap.rect.height / 4
        src_rect = Rect.new(0, 0, cw, ch)
        x = 300 - @characters.size * 32 + i * 64 - cw / 2
        self.contents.blt(x, 68 - ch, bitmap, src_rect)
      end
      end
  end
  #--------------------------------------------------------------------------
  # * Set Selected
  #     selected : new selected (true = selected, false = unselected)
  #--------------------------------------------------------------------------
  def selected=(selected)
    @selected = selected
    update_cursor_rect
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    if @selected
      self.cursor_rect.set(0, 0, @name_width + 8, 32)
    else
      self.cursor_rect.empty
    end
  end
end

Code:
#==============================================================================
# ** Scene_ExportFile
#------------------------------------------------------------------------------
#  This is a superclass for the save screen and load screen.
#==============================================================================

class Scene_ExportFile
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     help_text : text string shown in the help window
  #--------------------------------------------------------------------------
  def initialize(help_text)
    @help_text = help_text
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    # Make save file window
    @exportfile_windows = []
    for i in 0..3
      @exportfile_windows.push(Window_ExportFile.new(i, make_exportname(i)))
    end
    # Select last file to be operated
    @file_index = $game_temp.last_file_index
    @exportfile_windows[@file_index].selected = true
    # 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 windows
    @help_window.dispose
    for i in @exportfile_windows
      i.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    for i in @exportfile_windows
      i.update
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Call method: on_decision (defined by the subclasses)
      on_decision(make_exportname(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    # If B button was pressed
    if Input.trigger?(Input:: B)       # Call method: on_cancel (defined by the subclasses)
      on_cancel
      return
    end
    # If the down directional button was pressed
    if Input.repeat?(Input::DOWN)
      # If the down directional button pressed down is not a repeat,
      # or cursor position is more in front than 3
      if Input.trigger?(Input::DOWN) or @file_index < 3
        # Play cursor SE
        $game_system.se_play($data_system.cursor_se)
        # Move cursor down
        @exportfile_windows[@file_index].selected = false
        @file_index = (@file_index + 1) % 4
        @exportfile_windows[@file_index].selected = true
        return
      end
    end
    # If the up directional button was pressed
    if Input.repeat?(Input::UP)
      # If the up directional button pressed down is not a repeat、
      # or cursor position is more in back than 0
      if Input.trigger?(Input::UP) or @file_index > 0
        # Play cursor SE
        $game_system.se_play($data_system.cursor_se)
        # Move cursor up
        @exportfile_windows[@file_index].selected = false
        @file_index = (@file_index + 3) % 4
        @exportfile_windows[@file_index].selected = true
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Make File Name
  #     file_index : save file index (0-3)
  #--------------------------------------------------------------------------
  def make_exportname(file_index)
    return "E#{file_index + 1}.export"
  end
end

Code:
#==============================================================================
# ** Scene_Export
#------------------------------------------------------------------------------
#  This class performs save screen processing.
#==============================================================================

class Scene_Export < Scene_ExportFile
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super("Which file would you like to export to?")
  end
  #--------------------------------------------------------------------------
  # * Decision Processing
  #--------------------------------------------------------------------------
  def on_decision(exportname)
    # Play save SE
    $game_system.se_play($data_system.save_se)
    # Write save data
    export = File.open(exportname, "wb")
    write_save_data(export)
    export.close
    # If called from event
    if $game_temp.save_calling
      # Clear save call flag
      $game_temp.save_calling = false
      # Switch to map screen
      $scene = Scene_Title.new
      return
    end
    # Switch to map screen
      $scene = Scene_Title.new
    end
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # If called from event
    if $game_temp.save_calling
      # Clear save call flag
      $game_temp.save_calling = false
      # Switch to map screen
      $scene = Scene_Title.new
      return
    end
    # Switch to map screen
      $scene = Scene_Title.new
  end
  #--------------------------------------------------------------------------
  # * Write Save Data
  #     file : write file object (opened)
  #--------------------------------------------------------------------------
  def write_save_data(export)
    # Make character data for drawing save file
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    # Write character data for drawing save file
    Marshal.dump(characters, export)
    # Save magic number
    # (A random value will be written each time saving with editor)
    $game_system.magic_number = $data_system.magic_number
    # Write each type of game object
    Marshal.dump($game_system, export)
    Marshal.dump($game_switches, export)
    Marshal.dump($game_variables, export)
    Marshal.dump($game_self_switches, export)
    Marshal.dump($game_screen, export)
    Marshal.dump($game_actors, export)
    Marshal.dump($game_party, export)
    Marshal.dump($game_troop, export)
    Marshal.dump($game_map, export)
    Marshal.dump($game_player, export)
  end
end

Code:
#==============================================================================
# ** Scene_Import
#------------------------------------------------------------------------------
#  This class performs load screen processing.
#==============================================================================

class Scene_Import < Scene_ExportFile
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Remake temporary object
    $game_temp = Game_Temp.new
    # Timestamp selects new file
    $game_temp.last_file_index = 0
    for i in 0..3
      exportname = make_exportname(i)
      if FileTest.exist?(exportname)
        export = File.open(exportname, "r")
        export.close
      end
    end
    super("Which file would you like to import?")
  end
  #--------------------------------------------------------------------------
  # * Decision Processing
  #--------------------------------------------------------------------------
  def on_decision(exportname)
    # If file doesn't exist
    unless FileTest.exist?(exportname)
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # Play load SE
    $game_system.se_play($data_system.load_se)
    # Read save data
    export = File.open(exportname, "rb")
    read_save_data(export)
    export.close
end
  #--------------------------------------------------------------------------
  # * Cancel Processing
  #--------------------------------------------------------------------------
  def on_cancel
    # Play cancel SE
    $game_system.se_play($data_system.cancel_se)
    # Switch to title screen
    $scene = Scene_Title.new
  end
  #--------------------------------------------------------------------------
  # * Read Save Data
  #     file : file object for reading (opened)
  #--------------------------------------------------------------------------
  def read_save_data(export)
    # Read character data for drawing save file
    characters = Marshal.load(export)
    # Read each type of game object  
    $game_system        = Marshal.load(export)
    $game_switches      = Marshal.load(export)
    $game_variables     = Marshal.load(export)
    $game_self_switches = Marshal.load(export)
    $game_screen        = Marshal.load(export)
    $game_actors        = Marshal.load(export)
    $game_party         = Marshal.load(export)
    $game_troop         = Marshal.load(export)
    $game_map           = Marshal.load(export)
    $game_player        = Marshal.load(export)
    # If magic number is different from when saving
    # (if editing was added with editor)
    # If magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup($game_map.start_map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # Refresh party members
    $game_party.refresh
  end
end

Code:
#==============================================================================
# ¦ Scene_New_Game_Plus (coded by Deke)
#     This purpose of this class is to allow the player to restart the game using saved characters if
#      they have completed the game with that party.
#---------------------------------------------------------------------------------------------------------------------------------------------
# A new feature (small one) was added by myself (Dubealex) to enable a
# count of the number of times you finished the game.
# Copy the lines between my comments and paste them in your original script,
# or simply use that full one.

class Scene_New_Game_Plus < Scene_Import
#--------------------------------------------------------------------
def initialize
  #You need to add the following line:
  @game_completion_count=0
  #ENd of the line to copy.
  $game_temp = Game_Temp.new
  $game_temp.last_file_index = 0
  latest_time = Time.at(0)
  for i in 0..3
    exportname = make_exportname(i)
    if FileTest.exist?(exportname)
      export = File.open(exportname, "r")
      export.close
    end
  end
  @help_text="Which adventure would you like to begin again?"
end

#-----------------------------------------------------------------------------
#This method checks to see if the selected game file has completed the game.
#  (A completed game is indicated by turning switch 1 ON.)

def game_completed(exportname)
  export = File.open(exportname, "rb")
  read_save_data(export)
  export.close
  return($game_switches[38])
end

#------------------------------------------------------------------------------
#This method is identical to the one of the same name in the Scene_Load class, with the
#the added effect of reseting the maps, switches,...

def on_decision(exportname)
  unless FileTest.exist?(exportname)
    $game_system.se_play($data_system.buzzer_se)
    return
  end
  $game_system.se_play($data_system.load_se)
  export = File.open(exportname, "rb")
  read_save_data(export)
  export.close
if ! game_completed(exportname)
   $scene=Scene_New_Game_Plus.new
   return
end

#New code to copy for the "Game Completion Count" feature.
#Begin copying here, and stop at my other comments.
#You also need to copy line #15, shown by a comment also.
@game_completion_count=$game_variables[41]
$game_variables     = Game_Variables.new  
$game_temp          = Game_Temp.new
#$game_system        = Game_System.new
$game_switches      = Game_Switches.new
$game_self_switches = Game_SelfSwitches.new
$game_screen        = Game_Screen.new
#$game_actors        = Game_Actors.new
#$game_party         = Game_Party.new
$game_troop         = Game_Troop.new
$game_map           = Game_Map.new
#$game_player        = Game_Player.new
#$game_party.setup_starting_members
$game_map.setup($data_system.start_map_id)
$game_player.moveto($data_system.start_x, $data_system.start_y)
$game_player.refresh
$game_map.autoplay
$scene = Scene_Map.new
$game_system.bgm_play($game_system.playing_bgm)
$game_system.bgs_play($game_system.playing_bgs)
$game_map.update
$game_switches[38]=true #Since the switches were all reset, this one need to
                                     #be turned back on to indicate the game was completed.
$game_variables[41]=@game_completion_count
#Stop copying new "Game Completion Count" here.

end

end

After all of those are copied, replace Scene_Title with this following:
Code:
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
#  This class performs title screen processing.
#==============================================================================

class Scene_Title
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
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
    @sprite.bitmap = RPG::Cache.title($data_system.title_name)
    # Make command window
    s1 = "New Game"
    s2 = "Import"
    s3 = "Continue"
    s4 = "Exit"
    @command_window = Window_Command.new(192, [s1, s2, s3, s4])
    @command_window.back_opacity = 160
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 288
    # 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
    @import_enabled = false
    for i in 0..3
      if FileTest.exist?("Save#{i+1}.rxdata")
        @continue_enabled = true
      end
      if FileTest.exist?("E#{i+1}.export")
        @import_enabled = true
      end
    end
    # If continue is enabled, move cursor to "Continue"
    # If disabled, display "Continue" text in gray
    if @continue_enabled
      @command_window.index = 2
    else
      @command_window.disable_item(2)
    end
    #--------------------------------------------------------------------------
    # Addition start
    #--------------------------------------------------------------------------
    if @import_enabled
      @command_window.index = 1
    else
      @command_window.disable_item(1)
    end
    #--------------------------------------------------------------------------
    # Addition 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
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update command window
    @command_window.update
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by command window cursor position
      case @command_window.index
      when 0  # New game
        command_new_game
      #---------------------------------------------------------------------
      # Addition Start
      #---------------------------------------------------------------------
      when 1  # Import
        command_import
      #---------------------------------------------------------------------
      # Addition End
      #---------------------------------------------------------------------
      when 2  # Continue
        command_continue
      when 3  # Shutdown
        command_shutdown
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Command: New Game
  #--------------------------------------------------------------------------
  def command_new_game
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Stop BGM
    Audio.bgm_stop
    # Reset frame count for measuring play time
    Graphics.frame_count = 0
    # Make each type of game object
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    # Set up initial party
    $game_party.setup_starting_members
    # Set up initial map position
    $game_map.setup($data_system.start_map_id)
    # Move player to initial position
    $game_player.moveto($data_system.start_x, $data_system.start_y)
    # Refresh player
    $game_player.refresh
    # Run automatic change for BGM and BGS set with map
    $game_map.autoplay
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # Addition Start
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  # * Command: Import
  #--------------------------------------------------------------------------
  def command_import
    # If Import is disabled
    unless @import_enabled
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch to load screen
    $scene = Scene_New_Game_Plus.new
  end
  #--------------------------------------------------------------------------
  # Addition End
  #--------------------------------------------------------------------------
  #--------------------------------------------------------------------------
  # * Command: Continue
  #--------------------------------------------------------------------------
  def command_continue
    # If continue is disabled
    unless @continue_enabled
      # Play buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      return
    end
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Switch to load screen
    $scene = Scene_Load.new
  end
  #--------------------------------------------------------------------------
  # * Command: Shutdown
  #--------------------------------------------------------------------------
  def command_shutdown
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Fade out BGM, BGS, and ME
    Audio.bgm_fade(800)
    Audio.bgs_fade(800)
    Audio.me_fade(800)
    # Shutdown
    $scene = nil
  end
  #--------------------------------------------------------------------------
  # * Battle Test
  #--------------------------------------------------------------------------
  def battle_test
    # Load database (for battle test)
    $data_actors        = load_data("Data/BT_Actors.rxdata")
    $data_classes       = load_data("Data/BT_Classes.rxdata")
    $data_skills        = load_data("Data/BT_Skills.rxdata")
    $data_items         = load_data("Data/BT_Items.rxdata")
    $data_weapons       = load_data("Data/BT_Weapons.rxdata")
    $data_armors        = load_data("Data/BT_Armors.rxdata")
    $data_enemies       = load_data("Data/BT_Enemies.rxdata")
    $data_troops        = load_data("Data/BT_Troops.rxdata")
    $data_states        = load_data("Data/BT_States.rxdata")
    $data_animations    = load_data("Data/BT_Animations.rxdata")
    $data_tilesets      = load_data("Data/BT_Tilesets.rxdata")
    $data_common_events = load_data("Data/BT_CommonEvents.rxdata")
    $data_system        = load_data("Data/BT_System.rxdata")
    # Reset frame count for measuring play time
    Graphics.frame_count = 0
    # Make each game object
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    # Set up party for battle test
    $game_party.setup_battle_test_members
    # Set troop ID, can escape flag, and battleback
    $game_temp.battle_troop_id = $data_system.test_troop_id
    $game_temp.battle_can_escape = true
    $game_map.battleback_name = $data_system.battleback_name
    # Play battle start SE
    $game_system.se_play($data_system.battle_start_se)
    # Play battle BGM
    $game_system.bgm_play($game_system.battle_bgm)
    # Switch to battle screen
    $scene = Scene_Battle.new
  end
end

With that all said and done, simply use $scene = Scene_Export.new as the last event command in your game. This will allow the player to export their characters out, and will then send them straight to Scene_Title. I'll upload a demo sometime I hope...busy mapping right now, though...
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Export and Import System EmilyAnnCoons 0 2,414 12-29-2006, 01:00 PM
Last Post: EmilyAnnCoons
  Change color of text in game corbaque 0 2,048 11-05-2006, 01:00 PM
Last Post: corbaque
  Platform Game Script link2795 0 2,421 10-06-2006, 01:00 PM
Last Post: link2795
  Compiling RPG Maker XP Game into one exe sheefo 0 3,420 01-22-2006, 01:00 PM
Last Post: sheefo
  Progress Scripts/game Completion Wulfie 0 2,472 07-08-2005, 01:00 PM
Last Post: Wulfie



Users browsing this thread: 1 Guest(s)