Change Switches/Self Switches/Variables to Global Save Data

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by MeowFace, Jan 3, 2016.

  1. MeowFace

    MeowFace Meow Veteran

    Messages:
    1,034
    Likes Received:
    177
    Location:
    La La Land
    First Language:
    Meowish
    Made for a request here.

    This script changes the default game Switches/Self Switches/Variables into global save at the developer's choice.

    Allowing them to be shared across the game saved files/new game.

    Features:

    [1] Able to change default Switches/Variables/Self Switches into global shared data

    [2] Auto update global data when players save their game

    [3] Global data is shared among all loaded game/new game

    [4] Able to choose which set of data to be changed into global save data

    [5] Able to set the name of the save file

    How to Use:

    [1] Paste this below Material and above all your custom scripts in the script editor.

    [2] Use this script call to force save the global data only.

    force_global_saveCompatibility:

    This script overwrites the save/load method of the default engine.

    It might conflicts with custom scripts that overwrite the save/load method.

    Try place this script above all your custom scripts to avoid problems.

    Note that Save files made before installing this script will not be usable after the installation.

    Any changes made to the script after installation will require a new set of save files after that too.

    Terms of Use:

    Free for both commercial and non-commercial

    Script:

    Code:
    #==============================================================================# ■ Meow Face Global Data Manager#------------------------------------------------------------------------------# Change Self Switches / Switches / Variables into Global#==============================================================================# How to Use:# [1] Paste this below Material and above All your Custom Scripts# [2] Use this script call to force save global file only#     force_global_save#==============================================================================module MeowDataManager #Do Not Remove!!#==============================================================================# Settings Area#==============================================================================  FILENAME = "Save00.rvdata2"     #File Name for Global Save  GLOBAL_SWITCH = true              #Use Global Switch? (true/false)  GLOBAL_VARIABLE = true           #Use Global Variable? (true/false)  GLOBAL_SELF_SWITCH = false      #Use Global Self Switch? (true/false)#==============================================================================# End of Settings Area# Edit anything past this line at your own risk!#==============================================================================endmodule DataManager  def self.make_save_contents #overwrite    contents = {}    contents[:system]        = $game_system    contents[:timer]         = $game_timer    contents[:message]       = $game_message    contents[:switches]      = $game_switches if !MeowDataManager::GLOBAL_SWITCH    contents[:variables]     = $game_variables if !MeowDataManager::GLOBAL_VARIABLE    contents[:self_switches] = $game_self_switches if !MeowDataManager::GLOBAL_SELF_SWITCH    contents[:actors]        = $game_actors    contents[:party]         = $game_party    contents[:troop]         = $game_troop    contents[:map]           = $game_map    contents[:player]        = $game_player    contents  end  def self.extract_save_contents(contents) #overwrite    $game_system        = contents[:system]    $game_timer         = contents[:timer]    $game_message       = contents[:message]    $game_switches      = contents[:switches] if !MeowDataManager::GLOBAL_SWITCH    $game_variables     = contents[:variables] if !MeowDataManager::GLOBAL_VARIABLE    $game_self_switches = contents[:self_switches] if !MeowDataManager::GLOBAL_SELF_SWITCH    $game_actors        = contents[:actors]    $game_party         = contents[:party]    $game_troop         = contents[:troop]    $game_map           = contents[:map]    $game_player        = contents[:player]  end  def self.make_global_contents #new    contents = {}    contents[:switches]      = $game_switches if MeowDataManager::GLOBAL_SWITCH    contents[:variables]     = $game_variables if MeowDataManager::GLOBAL_VARIABLE    contents[:self_switches] = $game_self_switches if MeowDataManager::GLOBAL_SELF_SWITCH    contents  end  def self.extract_global_contents(contents) #new    $game_switches      = contents[:switches] if MeowDataManager::GLOBAL_SWITCH    $game_variables     = contents[:variables] if MeowDataManager::GLOBAL_VARIABLE    $game_self_switches = contents[:self_switches] if MeowDataManager::GLOBAL_SELF_SWITCH  end  def self.save_game_without_rescue(index) #overwrite    File.open(make_filename(index), "wb") do |file|      $game_system.on_before_save      Marshal.dump(make_save_header, file)      Marshal.dump(make_save_contents, file)      @last_savefile_index = index    end    self.global_save    return true  end  def self.load_game_without_rescue(index) #overwrite    File.open(make_filename(index), "rb") do |file|      Marshal.load(file)      extract_save_contents(Marshal.load(file))      reload_map_if_updated      @last_savefile_index = index    end    self.global_load    return true  end  def self.global_save #new    File.open(MeowDataManager::FILENAME, "wb") do |file|      Marshal.dump(make_global_contents, file)    end    return true  end  def self.global_load #new    File.open(MeowDataManager::FILENAME, "rb") do |file|      extract_global_contents(Marshal.load(file))      reload_map_if_updated    end    return true  end  def self.setup_new_game #overwrite    create_game_objects    $game_party.setup_starting_members    $game_map.setup($data_system.start_map_id)    if File.exist?(MeowDataManager::FILENAME)      self.global_load    end    $game_player.moveto($data_system.start_x, $data_system.start_y)    $game_player.refresh    Graphics.frame_count = 0  endendclass Game_Interpreter  def force_global_save #new    DataManager.global_save  endend
     
    #1
    Kizami likes this.
  2. MeowFace

    MeowFace Meow Veteran

    Messages:
    1,034
    Likes Received:
    177
    Location:
    La La Land
    First Language:
    Meowish
    Due to V3 to V4 migration, the codes in the top post is being messed up.


    Here's the alternative version of the code until the webstaff can fix the top post.

    Code:
    #==============================================================================
    # ■ Meow Face Global Data Manager
    #------------------------------------------------------------------------------
    # Change Self Switches / Switches / Variables into Global
    #==============================================================================
    # How to Use:
    # [1] Paste this below Material and above All your Custom Scripts
    # [2] Use this script call to force save global file only
    #     force_global_save
    #==============================================================================
    module MeowDataManager #Do Not Remove!!
    #==============================================================================
    # Settings Area
    #==============================================================================
      FILENAME = "Save00.rvdata2"     #File Name for Global Save
      GLOBAL_SWITCH = true              #Use Global Switch? (true/false)
      GLOBAL_VARIABLE = true           #Use Global Variable? (true/false)
      GLOBAL_SELF_SWITCH = true     #Use Global Self Switch? (true/false)
    #==============================================================================
    # End of Settings Area
    # Edit anything past this line at your own risk!
    #==============================================================================
    end
    module DataManager
      def self.make_save_contents #overwrite
        contents = {}
        contents[:system]        = $game_system
        contents[:timer]         = $game_timer
        contents[:message]       = $game_message
        contents[:switches]      = $game_switches if !MeowDataManager::GLOBAL_SWITCH
        contents[:variables]     = $game_variables if !MeowDataManager::GLOBAL_VARIABLE
        contents[:self_switches] = $game_self_switches if !MeowDataManager::GLOBAL_SELF_SWITCH
        contents[:actors]        = $game_actors
        contents[:party]         = $game_party
        contents[:troop]         = $game_troop
        contents[:map]           = $game_map
        contents[:player]        = $game_player
        contents
      end
      def self.extract_save_contents(contents) #overwrite
        $game_system        = contents[:system]
        $game_timer         = contents[:timer]
        $game_message       = contents[:message]
        $game_switches      = contents[:switches] if !MeowDataManager::GLOBAL_SWITCH
        $game_variables     = contents[:variables] if !MeowDataManager::GLOBAL_VARIABLE
        $game_self_switches = contents[:self_switches] if !MeowDataManager::GLOBAL_SELF_SWITCH
        $game_actors        = contents[:actors]
        $game_party         = contents[:party]
        $game_troop         = contents[:troop]
        $game_map           = contents[:map]
        $game_player        = contents[:player]
      end
      def self.make_global_contents #new
        contents = {}
        contents[:switches]      = $game_switches if MeowDataManager::GLOBAL_SWITCH
        contents[:variables]     = $game_variables if MeowDataManager::GLOBAL_VARIABLE
        contents[:self_switches] = $game_self_switches if MeowDataManager::GLOBAL_SELF_SWITCH
        contents
      end
      def self.extract_global_contents(contents) #new
        $game_switches      = contents[:switches] if MeowDataManager::GLOBAL_SWITCH
        $game_variables     = contents[:variables] if MeowDataManager::GLOBAL_VARIABLE
        $game_self_switches = contents[:self_switches] if MeowDataManager::GLOBAL_SELF_SWITCH
      end
      def self.save_game_without_rescue(index) #overwrite
        File.open(make_filename(index), "wb") do |file|
          $game_system.on_before_save
          Marshal.dump(make_save_header, file)
          Marshal.dump(make_save_contents, file)
          @last_savefile_index = index
        end
        self.global_save
        return true
      end
      def self.load_game_without_rescue(index) #overwrite
        File.open(make_filename(index), "rb") do |file|
          Marshal.load(file)
          extract_save_contents(Marshal.load(file))
          reload_map_if_updated
          @last_savefile_index = index
        end
        self.global_load
        return true
      end
      def self.global_save #new
        File.open(MeowDataManager::FILENAME, "wb") do |file|
          Marshal.dump(make_global_contents, file)
        end
        return true
      end
      def self.global_load #new
        File.open(MeowDataManager::FILENAME, "rb") do |file|
          extract_global_contents(Marshal.load(file))
          reload_map_if_updated
        end
        return true
      end
      def self.setup_new_game #overwrite
        create_game_objects
        $game_party.setup_starting_members
        $game_map.setup($data_system.start_map_id)
        if File.exist?(MeowDataManager::FILENAME)
          self.global_load
        end
        $game_player.moveto($data_system.start_x, $data_system.start_y)
        $game_player.refresh
        Graphics.frame_count = 0
      end
    end
    class Game_Interpreter
      def force_global_save #new
        DataManager.global_save
      end
    end
     
    #2

Share This Page