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.

(RMVX) Menu | Style Help.

Alright, it's been 3,6,9 days now, I guess I'll give even more information. First, refering to the image.

http://www4.mediafire.com/imgbnc.php/d3e30cb6ec19aa8f561410818b38e7d75g.jpg[/img]

^^ Basically, I want the menu to look like that, with the "Equip" option leading to the Weapon, Shield|Weapon2, Head, Body, and Accessory.
Then I want the "Style" option to give two options: "Defensive", changing from Weapon2 to Shield, and "Offensive", changing Shield to Weapon2.

Also, if you're already in "Defensive" or "Offensive" mode, I want which one you're in, to be grayed, but still able to hover over, but not able to select.
 

poccil

Sponsor

The following script modifies the Scene_Equip class to meet your needs.  Put it after all other
scripts in the Materials section in the script editor.

Please notify me if there are errors or if the menu doesn't behave as you want it to.

Put the IDs of the actors who should switch between offensive and defensive mode in the
TWO_SWORDS_ACTORS array at the top of this script.

Code:
class Game_Actor
########
  TWO_SWORDS_ACTORS = [1, 3] # Actor IDs of Offensive/Defensive actors
########
  def two_swords_style
    @two_swords_style=actor.two_swords_style if @two_swords_style==nil
    return @two_swords_style
  end
  def two_swords_style=(value)
    @two_swords_style=value
  end
end

class SingleSelectionWindow < Window_Base
  attr_reader :selected
  attr_reader :disabled
  def initialize(text,x,y,width,height)
    super(x,y,width,height)
    @item_max = 1
    @column_max = 1
    @text=text
    @selected=false
    @disabled=false
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.size=25
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = @disabled ? 128 : 255
    self.contents.draw_text(
      0,0,self.contents.width,self.contents.height,@text,1)
  end
  def disabled=(value)
    @disabled=value
    refresh
  end
  def selected=(selected)
    @selected=selected
    update_cursor
  end
  def update_cursor
    if @selected
      self.cursor_rect.set(0, 0, self.contents.width,self.contents.height)
    else
      self.cursor_rect.empty
    end
  end
end

def commandWindowInScene(scene,x,y,width,commands,enabledCommands,currentIndex)
  tmpcommand=Window_Command.new(width,commands)
  tmpcommand.contents.clear
  haveenabled=false
  index=0
  for i in 0...commands.length
    tmpcommand.draw_item(i,enabledCommands[i])
    haveenabled=true if enabledCommands[i]
    index=i if index==0 && enabledCommands[i]
  end
  if currentIndex && currentIndex>=0
    index=currentIndex
  end
  if !haveenabled
    Sound.play_buzzer
    tmpcommand.dispose
    return -1
  end
  tmpcommand.index=index
  tmpcommand.y=y
  tmpcommand.x=x
  tmpcommand.z+=1
  command=-1
  loop do
    Graphics.update
    Input.update
    tmpcommand.update
    scene.update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      command=-1
      break
    elsif Input.trigger?(Input::C)
      if !enabledCommands[tmpcommand.index]
        Sound.play_buzzer
      else
        Sound.play_decision
        command=tmpcommand.index
        break
      end
    end
    break if $scene!=scene
  end
  tmpcommand.dispose
  return command
end

class Scene_Equip < Scene_Base
  #--------------------------------------------------------------------------
  # * Constants
  #--------------------------------------------------------------------------
  EQUIP_TYPE_MAX = 5                      # Number of equip region
  OFFENSE_DEFENSE_ACTORS = [1, 3] # Actor IDs of Offensive/Defensive actors
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor_index : actor index
  #     equip_index : equipment index
  #--------------------------------------------------------------------------
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
    @equip_index = equip_index
  end
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @actor = $game_party.members[@actor_index]
    @equipSelection=SingleSelectionWindow.new(
       "Equip",0,0,Graphics.width/2,Window_Base::WLH+32)
    @styleSelection=SingleSelectionWindow.new(
       "Style",Graphics.width/2,0,Graphics.width/2,Window_Base::WLH+32)
    @styleSelection.disabled=!Game_Actor::TWO_SWORDS_ACTORS.include?(@actor.id)
    @equipSelection.selected=true
    @mode=0
    @phase=0
    @help_window=Window_Help.new
    @help_window.visible=false
    @equip_window = Window_Equip.new(208, 56, @actor)
    @equip_window.help_window = @help_window
    @equip_window.index = @equip_index
    create_item_windows
    @status_window = Window_EquipStatus.new(0, 56, @actor)
    @equip_window.active=false
    @tmpcommand=nil
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    @help_window.dispose
    @equipSelection.dispose
    @styleSelection.dispose
    @equip_window.dispose
    @status_window.dispose
    dispose_item_windows
  end
  #--------------------------------------------------------------------------
  # * Return to Original Screen
  #--------------------------------------------------------------------------
  def return_scene
    $scene = Scene_Menu.new(2)
  end
  #--------------------------------------------------------------------------
  # * Switch to Next Actor Screen
  #--------------------------------------------------------------------------
  def next_actor
    @actor_index += 1
    @actor_index %= $game_party.members.size
    $scene = Scene_Equip.new(@actor_index, @equip_window.index)
  end
  #--------------------------------------------------------------------------
  # * Switch to Previous Actor Screen
  #--------------------------------------------------------------------------
  def prev_actor
    @actor_index += $game_party.members.size - 1
    @actor_index %= $game_party.members.size
    $scene = Scene_Equip.new(@actor_index, @equip_window.index)
  end
  #--------------------------------------------------------------------------
  # * Update Frame
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @help_window.update
    if @mode==1
      # nothing
    elsif @phase==0
      @equipSelection.update
      @styleSelection.update
      if Input.repeat?(Input::RIGHT) || Input.repeat?(Input::LEFT)
        @equipSelection.selected=!@equipSelection.selected
        @styleSelection.selected=!@styleSelection.selected
        Sound.play_cursor
      elsif Input.repeat?(Input::B)
        Sound.play_cancel
        return_scene
      elsif Input.repeat?(Input::C)
        @mode=(@equipSelection.selected) ? 0 : 1
        @phase=1
        if @mode==1
          if !Game_Actor::TWO_SWORDS_ACTORS.include?(@actor.id)
           Sound.play_buzzer
           @phase=0
           @mode=0
          else
            Sound.play_decision
            @equipSelection.active=false
            @styleSelection.active=false
            currentIndex=-1
            loop do
             choice=commandWindowInScene(
              self,
              Graphics.width-150,
              Window_Base::WLH+32,
              150,
              ["Defensive","Offensive"],
              [@actor.two_swords_style,!@actor.two_swords_style],
              -1 # You can also replace with the word "currentIndex"
             )
             if choice==0
              @actor.change_equip(1,nil)  # Must unequip here!
              @actor.two_swords_style=false
              dispose_item_windows
              create_item_windows
             elsif choice==1
              @actor.change_equip(1,nil)  # Must unequip here!
              @actor.two_swords_style=true
              dispose_item_windows
              create_item_windows              
             end
             @equip_window.refresh
             @status_window.refresh
             for window in @item_windows
               window.refresh
             end
             if choice<0
               break
             end
             currentIndex=choice
            end
            @phase=0
            @mode=0
            @equipSelection.active=true
            @styleSelection.active=true
          end
        else
            Sound.play_decision
            @help_window.visible=true
            @equipSelection.visible=false
            @styleSelection.visible=false
            @equipSelection.active=false
            @styleSelection.active=false
            @equip_window.active=true
        end
      end
    elsif @equip_window.active
      update_equip_window
      update_status_window
      update_item_windows
      update_equip_selection
    elsif @item_window.active
      update_equip_window
      update_status_window
      update_item_windows
      update_item_selection
    end
  end
  #--------------------------------------------------------------------------
  # * Create Item Window
  #--------------------------------------------------------------------------
  def create_item_windows
    @item_windows = []
    for i in 0...EQUIP_TYPE_MAX
      @item_windows[i] = Window_EquipItem.new(0, 208, 544, 208, @actor, i)
      @item_windows[i].help_window = @help_window
      @item_windows[i].visible = (@equip_window.index == i)
      @item_windows[i].y = 208
      @item_windows[i].height = 208
      @item_windows[i].active = false
      @item_windows[i].index = -1
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose of Item Window
  #--------------------------------------------------------------------------
  def dispose_item_windows
    for window in @item_windows
      window.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Update Item Window
  #--------------------------------------------------------------------------
  def update_item_windows
    for i in 0...EQUIP_TYPE_MAX
      @item_windows[i].visible = (@equip_window.index == i)
      @item_windows[i].update
    end
    @item_window = @item_windows[@equip_window.index]
  end
  #--------------------------------------------------------------------------
  # * Update Equipment Window
  #--------------------------------------------------------------------------
  def update_equip_window
    @equip_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Status Window
  #--------------------------------------------------------------------------
  def update_status_window
    if @equip_window.active
      @status_window.set_new_parameters(nil, nil, nil, nil)
    elsif @item_window.active
      temp_actor = @actor.clone
      temp_actor.change_equip(@equip_window.index, @item_window.item, true)
      new_atk = temp_actor.atk
      new_def = temp_actor.def
      new_spi = temp_actor.spi
      new_agi = temp_actor.agi
      @status_window.set_new_parameters(new_atk, new_def, new_spi, new_agi)
    end
    @status_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Equip Region Selection
  #--------------------------------------------------------------------------
  def update_equip_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @phase=0
      @help_window.visible=false
      @equipSelection.visible=true
      @styleSelection.visible=true
      @equipSelection.active=true
      @styleSelection.active=true
      @equip_window.active=false
    elsif Input.trigger?(Input::R)
      Sound.play_cursor
      next_actor
    elsif Input.trigger?(Input::L)
      Sound.play_cursor
      prev_actor
    elsif Input.trigger?(Input::C)
      if @actor.fix_equipment
        Sound.play_buzzer
      else
        Sound.play_decision
        @equip_window.active = false
        @item_window.active = true
        @item_window.index = 0
      end
    end
  end
  def update_item_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @equip_window.active = true
      @item_window.active = false
      @item_window.index = -1
    elsif Input.trigger?(Input::C)
      Sound.play_equip
      @actor.change_equip(@equip_window.index, @item_window.item)
      @equip_window.active = true
      @item_window.active = false
      @item_window.index = -1
      @equip_window.refresh
      for item_window in @item_windows
        item_window.refresh
      end
    end
  end
end
 
Oh, great, THANKS, I tried it before posting so here it goes...

1) Works great, what I wanted.

2) When I switch from Defensive to Offensive the shield I have equppied gets replaced by the first form in the weapons database.
I got a Wooden Shield equipped, than I switch to Offensive WITH IT equipped, it un-equips alright but when I go into the Inventory,
the Wooden Shield is replaced by, eg. Club. I tried it again before posting, THIS TIME, I un-equip the Wooden Shield, switch to   
Offensive, but I'm still able to EQUIP the Wooden Shield, but instead, it turns into a Club and equips. Do know it's fine if you EXIT to   
Menu and go back in, the shild doesn't show up with Weapon 2, but does if you on't exit and go back in.

I am not sure if that is what it's suppose to do or not, I am still learning RGSS so I don't know what to change.

3) This affects all characters, I noticed, and I forgot to ask to make it affect x actors.
eg. I want Only Ralph and Bennett to be able to go Offensive and Defensive and no one else, or even Ulrika, in the future, if I wanted.
I can do the Ulrika in the future myself. I was wondering if you can make this to affect only X actors of choice.

Please and Thanks, Wern25.
 
Uh, I must be getting annoying, but when Iget a script I make sure there are absolutely no bugs at all.

BUGS:
1) I un-equip my sword, hover over shield and than switch to Defensive, and go back into to Equip I can equip the sword but then it equips to the armor in index 1 of the database.

2) I have 2 swords in my inventory, I switch to offensive from Defensive, the 2nd Sword doesn't appear until I either back out or equip the empty Weapon 2.

3) I noticed I had Actor1 set to Two Swords Style already with 2 Long Swords equipped. In the Equip Status Menu, He has a Long Sword and a Scale Shield equipped. Is there a way for it not to over-ride the default settings in the Database?

NOTE: I'm using a test Project to find these bugs.

EDIT: You don't need to include comments and instructions as I can read scripts fine without them... I think it's kind of late for that?

Last Request) Instead of auto-exiting the Style Selection, maybe you can make it so you have to Back Out in order to Exit. Sorry, I am not use to Menu's exiting for you, it really annoys me, and I dislike getting use to that.
 

poccil

Sponsor

Once again, I've made the changes and fixes requested above.

For the last request, I couldn't decide whether or not the Style menu should automatically move to the first enabled selection after the player has made the choice.  I decided that it should, but I added a comment explaining how to prevent this behavior.  The comment was necessary in this case
 

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