Map name as save file name
#1
Hey guys, its me again. (BTW is that forum almost dead? I don't see many new threats; at least in this section)
Well, now I would like to have map name included in save file name. To clarify — not when I pick a save file, but as ins name in the load screen. For example:

1 Sacred Forest               29-04-2020  16:13
2 Temple of Random God 29-04-2020  16:13
3 Test map234finalxx       29-04-2020  16:13

Right now its "Wstaw nazwę lokacji" which basically means "Insert location name". I set this up like that after few hours of futile attempts to make it by myself. Well... my Ruby knowledge is pretty poor, I'm able to modify only simple things so far.

[Image: EiD1G8R.png]

Here is link to project with scripts I'm using.
https://drive.google.com/open?id=1D6SR70...4hTeEFKpoT

Any help is really appreciated. I assure you guys that before I'll ask for help I'm spending 4-8 hours trying to do it myself. I don't want you to feel that I'm lazy and abusing your good will...
Reply }
#2
Hrm... thinking thinking.... lotta projects in my mind (and others that I get suckered into...)

At first thought, I figured you would need to have the SaveFile change its design from saving files like Save1.rxdata, Save2.rxdata... and so on.

Instead, I was thinking something else.... When the default system shows the 'SaveFile' windows, it shows the party members as chararactersets in each window. This means, you can access the game data for each save file.

Now the default system only loads but so much data, and not the name of the game map. BUT that can be fixed... and I did. Winking It just meant adding in a tried and true method of getting the map name, and performing a few edits to the Window_SaveFile class....

Code:
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Get Map Name
  #--------------------------------------------------------------------------  
  def map_name
    @mapinfo = load_data("Data/MapInfos.rxdata") if @mapinfo == nil
    return @mapinfo[@map_id].name
  end
end


#==============================================================================
# ** Window_SaveFile
#------------------------------------------------------------------------------
#  This window displays save files on the save and load screens.
#==============================================================================

class Window_SaveFile < Window_Base
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :filename                 # file name
  attr_reader   :selected                 # selected
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     file_index : save file index (0-3)
  #     filename   : file name
  #--------------------------------------------------------------------------
  def initialize(file_index, filename)
    super(0, 64 + file_index % 4 * 104, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "Save#{@file_index + 1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      # ==================================================
      #  -- This skips through other pieces of data until
      #     We get to the game map section
      t = Marshal.load(file) # Self Switches
      t = Marshal.load(file) # Screen
      t = Marshal.load(file) # Actors
      t = Marshal.load(file) # Party
      t = Marshal.load(file) # Troop
      # ==================================================
      @game_map       = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    # If save file exists
    if @file_exist
    # Draw file number
      self.contents.font.color = normal_color
      name = "File#{@file_index + 1}: " + @game_map.map_name
      self.contents.draw_text(4, 0, 600, 32, name)
      @name_width = contents.text_size(name).width
      # 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
      # Draw play time
      hour = @total_sec / 60 / 60
      min = @total_sec / 60 % 60
      sec = @total_sec % 60
      time_string = sprintf("%02d:%02d:%02d", hour, min, sec)
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 8, 600, 32, time_string, 2)
      # Draw timestamp
      self.contents.font.color = normal_color
      time_string = @time_stamp.strftime("%Y/%m/%d %H:%M")
      self.contents.draw_text(4, 40, 600, 32, time_string, 2)
    else
    # Draw file number
    self.contents.font.color = normal_color
    name = "File#{@file_index + 1}"
    self.contents.draw_text(4, 0, 600, 32, name)
    @name_width = contents.text_size(name).width
    end
  end
end

Enjoy.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#3
I found this scriptlet has 2 flaws. First of all, it doesn't apply a filter to map names that include codes that are not supposed to be displayed on screen. And on the other hand, you knew you can load chunks of loaded files without assigning them to any variable at all if you don't need to process them, right? Laughing + Tongue sticking out
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#4
First of all, I have no idea if he is using anything that alters the map name. This would be up to him to address. And second, yes, I could just type Load_Marshal by itself. But I was keeping with standards. AND gave notation/comments to explain the reason behind them.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#5
Script works good in "plain" project, but I don't know how to implement the solution to my game. Apparently script that I'm using utilizes class Window_File < Window_Selectable to display save details. When I try transfer solution to that script I'm getting error message. I'm using modified 1-Scene Custom Menu System 1.17b by LegACy. (Line 1715 probably)

[Image: p6tCvdF.png]

I'm also using Kylock's Time System, so some maps has
[*] in their name, but script seems to skip that part, so its fine.
"Demo" project that include all scripts I'm using you can find in the first post :)

https://drive.google.com/open?id=1D6SR70...4hTeEFKpoT
Reply }
#6
If you're talking about the load game scene the default game or the projects that still use a very similar system, it shouldn't work. At the moment you try to load the data to display it, $game_map as a global variable doesn't. Probably that happens because the game usually creates it AFTER you have picked a saved game data file.

How do you fix it?

Create it yourself. Add the line

$game_map ||= Game_Map.new

Where do you place it?

It could be either in Scene_Title if you use it or in the initialize method of Window_SaveFile.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#7
(04-30-2020, 08:56 PM)kyonides Wrote: If you're talking about the load game scene the default game or the projects that still use a very similar system, it shouldn't work. At the moment you try to load the data to display it, $game_map as a global variable doesn't. Probably that happens because the game usually creates it AFTER you have picked a saved game data file.

How do you fix it?

Create it yourself. Add the line

$game_map ||= Game_Map.new

Where do you place it?

It could be either in Scene_Title if you use it or in the initialize method of Window_SaveFile.

I followed the instruction, then replaced @game_map with $game_map, and there is no error now, but... it doesn't work. It does show map name in save file name, but its ALWAYS THE NAME OF THE CURRENT MAP. So I can save on map "Testy" but when I teleport to map "Location 2", all savegames will be named "Location 2", even though it was saved on map "Testy".
Reply }
#8
I never told you to replace @game_map with $game_map because they are different
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }
#9
Investigation.... Detective Realization... Thinking Recognition... Plan

You're using Legacy's menu. Good thing I didn't delete your old project, right?

Paste THIS directly below Legacy's Menu instead:

Code:
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
  #--------------------------------------------------------------------------
  # * Get Map Name
  #--------------------------------------------------------------------------  
  def map_name
    @mapinfo = load_data("Data/MapInfos.rxdata") if @mapinfo == nil
    return @mapinfo[@map_id].name
  end
end


#==============================================================================
# ** Window_File
#------------------------------------------------------------------------------
#  This window displays files on the save and load screens.
#==============================================================================

class Window_File < Window_Selectable
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    time_stamp = Time.at(0)
    for i in 0...LegACy::SAVE_NUMBER
      filename = "Save#{i + 1}.rxdata"
      self.contents.draw_text(1, i * 32, 32, 32, (i + 1).to_s, 1)
      
      
      if FileTest.exist?(filename)
        #===================================================================
        file = File.open(filename, "r")
        @time_stamp = file.mtime
        @characters = Marshal.load(file)
        @frame_count = Marshal.load(file)
        @game_system = Marshal.load(file)
        @game_switches = Marshal.load(file)
        @game_variables = Marshal.load(file)
        # ==================================================
        #  -- This skips through other pieces of data until
        #     We get to the game map section
        t = Marshal.load(file) # Self Switches
        t = Marshal.load(file) # Screen
        t = Marshal.load(file) # Actors
        t = Marshal.load(file) # Party
        t = Marshal.load(file) # Troop
        # ==================================================
        @game_map       = Marshal.load(file)
        @total_sec = @frame_count / Graphics.frame_rate
        file.close          
        #===================================================================
=begin        
        size = File.size(filename)
        if size.between?(1000, 999999)
          size /= 1000
          size_str = "#{size} KB"
        elsif size > 999999
          size /= 1000000
          size_str = "#{size} MB"
        else
          size_str = size.to_s
        end
        time_stamp = File.open(filename, "r").mtime
        date = time_stamp.strftime("%m/%d/%Y")
        time = time_stamp.strftime("%H:%M")
        self.contents.font.size = 18 #20
        self.contents.font.bold = true
        self.contents.draw_text(38, i * 32, 120, 32, date)
        self.contents.draw_text(160, i * 32, 100, 32, time)
        self.contents.draw_text(0, i * 32, 284, 32, size_str, 2)
=end  
        #===================================================================
        # HERE is where you edit!!!!!
        time_stamp  = File.open(filename, "r").mtime
        date        = time_stamp.strftime("%m/%d/%Y")
        name        = @game_map.map_name
        self.contents.draw_text (38, (i-1) * 32, 320, 32, name)
        self.contents.draw_text(160, (i-1) * 32, 120, 32, date)
        
        #===================================================================
      end

      
    end
  end
end

Note the area between thick lines that you may edit.

And as Doug would say... Doug Marcaida It will kill...
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#10
Yaaaaaaaassss! That works perfect.
Thank you guys, you're THE BEST. How can I return the favor?
PS DerVVulfman — I linked project with all scripts I'm using and mentioned it twice, so you didn't require my old project ;)
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Weird error when using a custom save script. Steel Beast 6Beets 8 11,453 06-27-2015, 05:54 PM
Last Post: Steel Beast 6Beets
   Custom Save/Load screen Raou 2 7,570 04-01-2015, 08:18 PM
Last Post: Raou
   Script Request - Variables Specific Save File JayRay 2 5,120 04-28-2014, 05:15 AM
Last Post: JayRay
   Checking if a file exists without knowing the extension? PK8 1 5,060 05-29-2011, 10:13 AM
Last Post: MGC
   Save Screen Screenshot Yin 2 6,214 07-05-2010, 06:31 PM
Last Post: Yin
   Can I execute a txt file from a script? deValdr 8 11,021 04-18-2010, 07:34 PM
Last Post: deValdr
   Help With Law's Save System Ryu-ka 0 3,822 04-06-2010, 06:37 PM
Last Post: Ryu-ka
   Need advice on best/easiest save setup rcg916 3 6,268 11-08-2009, 06:24 AM
Last Post: DerVVulfman
   How can I save a map? Charlie Fleed 3 6,713 07-08-2009, 09:55 PM
Last Post: dacloudster
   Forced Save? Yin 9 13,938 04-18-2009, 08:41 PM
Last Post: DerVVulfman



Users browsing this thread: 1 Guest(s)