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.

How do I add new menu items?

Inigma

Member

I was just wondering if there was any way to add extra menu items to the in-game menu, say... something that would be able to call a specific map, eg a world map, straight from the menu, is this possible? Can someone help me? This is RGSS2 RPG Maker VX by the way  :smile:
 
Go into Scene_Menu and look at the method that creates the Command Window:
Code:
def create_command_window
    s1 = Vocab::item
    s2 = Vocab::skill
    s3 = Vocab::equip
    s4 = Vocab::status
    s5 = Vocab::save
    s6 = Vocab::game_end
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
    @command_window.index = @menu_index
    if $game_party.members.size == 0          # If number of party members is 0
      @command_window.draw_item(0, false)     # Disable item
      @command_window.draw_item(1, false)     # Disable skill
      @command_window.draw_item(2, false)     # Disable equipment
      @command_window.draw_item(3, false)     # Disable status
    end
    if $game_system.save_disabled             # If save is forbidden
      @command_window.draw_item(4, false)     # Disable save
    end
  end
See that list, s1 - s6?  Let's look at the first one.
Code:
s1 = Vocab::Item
That defines the first command in your list.  Since its name could be different, depending on how the user has changed the vocabulary, it looks to the string saved in the Vocab module under the method Item.  However, we don't really need to do that.  If you want to append your new World Map command to the bottom of the list, then go ahead and add another s at the end of your list.  Something like this would work.
Code:
s7 = "World Map"
If you're not trying to call a variable or method, it's important to use those quotes.  That's the first change you'll need to make.  You then need to look at this line:
Code:
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
Now, what that's actually doing is building a window from a template.  The part you need to look at right now is the array in that call.
Code:
[s1, s2, s3, s4, s5, s6]
Since you're wanting a seventh command, you'll need to add a seventh item to the array.
Code:
@command_window = Window_Command.new(160, [s1, s2, s3, s4, s4, s6, s7])
Congratulations, at this point, your command window now shows you a seventh option, "World Map."

Unfortunately, it doesn't do anything yet.

In order to fix that, we need to go farther down.  Let's look at the very next method.
Code:
def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      if $game_party.members.size == 0 and @command_window.index < 4
        Sound.play_buzzer
        return
      elsif $game_system.save_disabled and @command_window.index == 4
        Sound.play_buzzer
        return
      end
      Sound.play_decision
      case @command_window.index
      when 0      # Item
        $scene = Scene_Item.new
      when 1,2,3  # Skill, equipment, status
        start_actor_selection
      when 4      # Save
        $scene = Scene_File.new(true, false, false)
      when 5      # End Game
        $scene = Scene_End.new
      end
    end
  end
The important part here is after "case @command_window.index".  It's a simple series of statements based on where the cursor is in the window.  The first command will return the index 0, and it counts up from there.  Thus, when the index is 5, it's on s6, or End Game.  You'll need to tack in a "when 6", followed by whatever you actually want it to do.

Say, for instance, you have a Scene_Show_WorldMap already built that you want to use.  Your new version of the method could look something like this:
Code:
def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      if $game_party.members.size == 0 and @command_window.index < 4
        Sound.play_buzzer
        return
      elsif $game_system.save_disabled and @command_window.index == 4
        Sound.play_buzzer
        return
      end
      Sound.play_decision
      case @command_window.index
      when 0      # Item
        $scene = Scene_Item.new
      when 1,2,3  # Skill, equipment, status
        start_actor_selection
      when 4      # Save
        $scene = Scene_File.new(true, false, false)
      when 5      # End Game
        $scene = Scene_End.new
      when 6      # World Map
        $scene = Scene_Show_WorldMap.new
      end
    end
  end

For ease of editing and problem-solving, you should do it not in the default script, but under Materials in a new script.  It should look something like this:
Code:
class Scene_Menu
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    s1 = Vocab::item
    s2 = Vocab::skill
    s3 = Vocab::equip
    s4 = Vocab::status
    s5 = Vocab::save
    s6 = Vocab::game_end
    s7 = "World Map"
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7])
    @command_window.index = @menu_index
    if $game_party.members.size == 0          # If number of party members is 0
      @command_window.draw_item(0, false)     # Disable item
      @command_window.draw_item(1, false)     # Disable skill
      @command_window.draw_item(2, false)     # Disable equipment
      @command_window.draw_item(3, false)     # Disable status
    end
    if $game_system.save_disabled             # If save is forbidden
      @command_window.draw_item(4, false)     # Disable save
    end
  end
  #--------------------------------------------------------------------------
  # * Update Command Selection
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      if $game_party.members.size == 0 and @command_window.index < 4
        Sound.play_buzzer
        return
      elsif $game_system.save_disabled and @command_window.index == 4
        Sound.play_buzzer
        return
      end
      Sound.play_decision
      case @command_window.index
      when 0      # Item
        $scene = Scene_Item.new
      when 1,2,3  # Skill, equipment, status
        start_actor_selection
      when 4      # Save
        $scene = Scene_File.new(true, false, false)
      when 5      # End Game
        $scene = Scene_End.new
      when 6      # World Map
        $scene = Scene_Show_WorldMap.new
      end
    end
  end
end
This overwrites those two methods for Scene_Menu, and your menu now shows the new item and does something with it when it's selected.
Of course, this is assuming that you already have a Scene_Show_WorldMap to be called.  That, however, is not what we're here for.

Please let me know if I've been unclear on how to go about adding an option to the menu.
 

Inigma

Member

WOWOWOWOWOW, nice tutorial man!!!, thanks a lot, right, at the moment, i've just told it to play some sound that i found in another script somewhere lol, so, now I need to figure out how to make the person warp to the world map, using switches/ variable to control where the person goes =], this should be fun
 

Inigma

Member

Ok, i've edited the script a bit now, I have added the menu item, that opens a little box in the middle, that makes you confirm it, and I jsut need to know how to make a script warp you to a map for starters
 

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