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.

[Solved!]Easy Weapon-Equipping (simple)

Hey talented scripters!
For my new game handling with an ABS, I need a script which lets me equip a weapon quickly;
http://img353.imageshack.us/img353/9278/scriptrmh2.th.jpg[/img]
1: In the top of the right corner there is the icon of the equipped weapon shown.
When I press E  , then window 2 & 3 should open.
2: In this window  the equipped weapon icon + name is shown.
3: In this scrollable window you can exchange your eqiupped weapon with another out of your inventary.
[The boxes are just drawn with the window skin!]
[The icons are the icons set in the database!]

I hope you understand what I mean...
Thanks in advance, 'd be grateful - and would have you listed in the credits of course! ;)
 
God its sad I can do this in quick reply.

Code:
#==============================================================================
# ** Quick_Map_Equip
#------------------------------------------------------------------------------
#  SephirothSpawn
#  Version 1.0
#  2008-09-17
#==============================================================================

module Quick_Map_Equip
  # 0: Top-Left, 1: Top-Right, 2-Bottom Left, 3-Bottom-Right
  Equipped_Corner = 1
  # Equipping Position Start
  Equipping_Window_X = 320
  Equipping_Window_Y = 160
  Equipping_Window_Width  = 224
  Equipping_Window_Height = 160
  # Open Quick Equipper Button
  Open_Equipper = Input::R
  # Visibility Switch ID
  Switch_ID = 1
end

class Quick_Map_Equip::Window_CEquipped < Window_Base
  include Quick_Map_Equip
  def initialize
    x = (Equipped_Corner == 0 || Equipped_Corner == 2) ? 0 : 640 - 64
    y = (Equipped_Corner == 0 || Equipped_Corner == 1) ? 0 : 480 - 64
    super(x, y, 64, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    update
  end
  def update
    super
    self.visible = $game_switches[Switch_ID]
    return unless self.visible
    if $game_party.actors[0].nil?
      self.contents.clear
      return
    end
    if @weapon_id != $game_party.actors[0].weapon_id
      self.contents.clear
      @weapon_id = $game_party.actors[0].weapon_id
      return if $data_weapons[@weapon_id] == nil
      bitmap = RPG::Cache.icon($data_weapons[@weapon_id].icon_name)
      self.contents.blt(4, 4, bitmap, bitmap.rect)
    end
  end
end

class Quick_Map_Equip::Window_Equipped < Window_Base
  include Quick_Map_Equip
  def initialize
    super(Equipping_Window_X, Equipping_Window_Y, Equipping_Window_Width, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 160
    update
  end
  def update
    super
    if $game_party.actors[0] == nil
      self.contents.clear
      return
    end
    if @weapon_id != $game_party.actors[0].weapon_id
      @weapon_id = $game_party.actors[0].weapon_id
      self.contents.clear
      return if $data_weapons[@weapon_id] == nil
      bitmap = RPG::Cache.icon($data_weapons[@weapon_id].icon_name)
      self.contents.blt(4, 4, bitmap, bitmap.rect)
      self.contents.draw_text(32, 0, contents.width - 32, 32, 
        $data_weapons[@weapon_id].name)
    end
  end
end

class Quick_Map_Equip::Window_Equipment < Window_Selectable
  include Quick_Map_Equip
  def initialize
    super(Equipping_Window_X, Equipping_Window_Y + 64, Equipping_Window_Width, 
      Equipping_Window_Height)
    self.back_opacity = 160
    refresh
  end
  def item(index = self.index)
    return @data[index]
  end
  def refresh
    self.index = 0
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_weapons.size
      if $game_party.weapon_number(i) > 0
        if $game_party.actors[0].equippable?($data_weapons[i])
          @data.push($data_weapons[i])
        end
      end
    end
    @item_max = @data.size
    self.height = Equipping_Window_Height
    if @item_max > 0
      self.height = [@item_max * 32 + 32, Equipping_Window_Height].min
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    y = index * 32
    rect = Rect.new(x, y, self.width  - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(4, y + 4, bitmap, bitmap.rect)
    self.contents.draw_text(32, y, 128, 32, item.name)
  end
end

class Scene_Map
  alias_method :seph_quickequipped_scnmap_main,   :main
  alias_method :seph_quickequipped_scnmap_update, :update
  def main
    @window_cequipped = Quick_Map_Equip::Window_CEquipped.new
    seph_quickequipped_scnmap_main
    @window_cequipped.dispose unless Object.const_defined?(:SDK)
  end
  def update
    @window_cequipped.update unless Object.const_defined?(:SDK)
    if @window_equipped != nil
      update_quickequipper
      return
    end
    if Input.trigger?(Quick_Map_Equip::Open_Equipper)
      @window_equipped = Quick_Map_Equip::Window_Equipped.new
      @window_equipment = Quick_Map_Equip::Window_Equipment.new
    end
    seph_quickequipped_scnmap_update
  end
  def update_quickequipper
    unless Object.const_defined?(:SDK)
      @window_equipped.update
      @window_equipment.update
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @window_equipped.dispose
      @window_equipment.dispose
      @window_equipped = nil
      @window_equipment = nil
    end
    if Input.trigger?(Input::C)
      weapon = @window_equipment.item
      if weapon == nil
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      $game_party.actors[0].equip(0, weapon.id)
      @window_equipment.refresh
    end
  end
end

Just copy and paste should do the trick.
 

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