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.

[Resolved] Area name along with map name

Hi, I don't feel to request this very simple script so I decide to make it myself.

I'd like to show area name along with map name within the menu. I replaced the step counter (as it's useless to me) with map name. The problem is I have some maps within defined areas, so map name within the menu no longer shows informative name of where the player is currently.

For example, let's say that I have an area (I'd call "supermap") called "Town X". This area has some maps ("submaps"), for example "House", "Pub", and "Inn". Instead of displaying this:

Code:
House <<-- only the submap name

I'd like to display something like this

Code:
[color=blue]Town X[/color] <<-- this is the supermap name
House <<-- submap name

I don't know how to refer to the RMXP map tree since I've classified the supermaps and submaps during design. Can I refer to it?

If can't, so far I can think of this:
1. Create a Hash consisting of supermaps' and submaps' IDs. Unfortunately, I don't really understand how to use Hash. I know that Hash has a format something like key ==> value[, value, ...], but I don't know in my case which should be key and value.

2. Within any Game_XXX class (I don't know which one still), in update method I should check the mapID to display the appropriate super- and submap (using the Hash table from step 1).

The only problem with this is when I have more than one level of submaps. For example, within "House" map I can have submaps as "Bathroom", "Dining room", etc.. Of course, I limit myself to have maximum 3 levels of submaps (so "Bathroom" map will be the deepest level, since it's already in level 3). Furthermore, the display would be something like this:

Code:
Town X <<-- level 1 map
House - Bathroom
   ^            ^
level 2  level 3 map
map

How could I handle this with my algorithm above?

In addition, I also display the chapter number (my game consists of chapters) above the map name. I use a in-game variable for this purpose, but in Submitted Request section I discover that I must limit using in-game variable. Why is it?

So far, this what I do to display chapter name (I'm not sure since I don't bring my project along with me, but it's should be within Window_Step class:
Code:
text = $game_variables[1]
draw_text(0, 0, 48, 32, text)

To change chapter number, I just use regular event such as this:
Code:
<> Some events here...
<> Variable[0001]: Set = 8 <<-- the new chapter number
<> Some events here...

Should I add a script variable for this purpose (since it works well) instead? If yes, should I add it to Game_System class or anywhere else?

Any help would be appreciated (and credited when necessary). Thank you.
 
Here I'll help you out a bit

1)
The code to display a map's name is this

def name
load_data("Data/MapInfos.rxdata")[@map_id].name
end

to get the parent map id just use this code (If there is no parent map then this returns 0)

load_data("Data/MapInfos.rxdata")[@map_id].parent_id

Then you can go on and on sending the map's parent id as the maps id until you get the top most parent map

2)
Hashes are like arrays instead of a index you have keys a the literal for a hash is this {key => value, key => value, ...}

3) You can use the in-game variables, but if you plan on releasing your script to the public then it is not really the most friendly solution
 
Ah, thanks for that Trickster! It helped me a lot.

Now I finished my script so I can display up to level 4 map name (though I must sacrifice my Window_Gold, actualy merge it with Window_Steps, for this purpose to make it fit). This is what I wrote within my modified Window_Steps class:

Code:
 class Window_Steps < Window_Base
  def initialize
    super(0, 0, 160, 144)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    map_name = load_data("Data/MapInfos.rxdata")[$game_map.map_id].name
    if map_name[0,1] == "*" then map_name.slice!(0,1) end
    parent_id = load_data("Data/MapInfos.rxdata")[$game_map.map_id].parent_id
    #this saves the map hierarchy into an array
    maps = Array.new()
    maps.push($game_map.map_id)
    maps.push(parent_id)
    #loops until no more parent map found
    until parent_id == 0
      parent_id = load_data("Data/MapInfos.rxdata")[parent_id].parent_id
      maps.push(parent_id)
    end
    #delete map_id 0 since it was accidentally saved
    maps.delete(0)
    #reverse the map order
    maps.reverse!
    #gets the maximum map level
    level = maps.size
    #draws each map name
    until maps.empty?
      self.contents.font.color = normal_color
      map_id = maps.shift
      self.contents.draw_text(4, 20 * (level - maps.size), 128, 20, name(map_id))
    end
    #self.contents.font.color = normal_color
    #self.contents.draw_text(4, 16, 130, 32, map_name)
    #displays chapter number
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 128, 20, "Chapter " + $game_variables[6].to_s)
#    bitmap = RPG::Cache.icon("020-Accessory05")
#    rect = Rect.new(0, 0, 24, 24)
#    self.contents.blt(105, 20, bitmap, rect)
    #display gold
    cx = self.contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 96, 120-cx-2, 20, $game_party.gold.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 96, cx, 20, $data_system.words.gold, 2)
  end
  def name(map_id)
    map_name = load_data("Data/MapInfos.rxdata")[map_id].name
    if map_name[0,1] == "*" then map_name.slice!(0,1) end
    return map_name
  end
end

The result would be something like this:
Code:
[color=blue]Chapter 1[/color]
Map level 1
Map level 2
Map level 3

       0 Golds

Since I use advanced time system, I must slice the "*" from any maps which names begin with.

Actually I want to give the level 1 map name a different color, but I think I would need one more variable. How can I avoid adding variable to my script to give level 1 map name different color?

It works well with me, but any suggestion for enhancements?

Oh, by the way, is there a
Code:
do
  //do something here
until(<expression>)
syntax in Ruby? If there is, I can avoid the value 0 (from the parent_id attribute) being saved into the array maps
 
yach, sbenernya bisa pake syntax 'break', jadi kira2 :
Code:
loop do
#blah blah
break if <expression>
end
tapi pada dasarnya kodenya dah bagus koq tuh... cuman, kenapa gak ngeloop 3 kali ajah? kan dah jelas cuman ada 3 level peta...

BTW, anybody can guess what language did I just use? ^^
 
Well, in case that I have the 4th or deeper level map... prevention is better than cure.

That's a weird syntax I ever saw...

Anyway, I think I can't avoid map_id 0 saved into the array, since the parent_id = load_data(...).parent_id will always be done at least once (although I use do ... until loop), and there's a possibility that current map is at the highest level (which mean parent_id = 0). Unless I strict it so map_id 0 will be never saved.

How could you speak Indonesian here???
 

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