Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bag item menu
#1
Bag item menu
by rune76
Aug 12 2005

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


This script let's you define how many items the player should be able to carry (Items, Weapons and Armors that is).
I'll explain the functions after the script:
First of all, add these lines of code in your original Game_Party, replace the line that says def initialize with:

Code:
attr_accessor :bag_size
attr_accessor :items_now
def initialize
   @bag_size = 30
   @items_now = 0


Now place this code in a new place above Main:
Code:
# Made by: Matte
#--------------------------------------------------------------------------
# To use this first place the next following code in your original Game_Party
# or if you have one that's edited just place it there:
# attr_accessor :bag_size
# attr_accessor :items_now
# def initialize
# @bag_size = 30
# @items_now = 0
# Replace the line that says def intialize with that code...
#--------------------------------------------------------------------------
# Now for the functions:
# *To change the bag size use the Call RGSS Script and write
# $game_party.bag_size = The number you want
#
# *If you use the add items/weapons/armors method you can,
# if you show a 'gained item' message,
# use the \v[99] to show how many items you gained.
# For example, if we have 20 items in the bag already,
# and the max items you can have is 30:
#    <>Change Items: [Potion] + 15
#    <>Message: You got \v[99] potions!
# Then the message would say you got 10 potions.
#--------------------------------------------------------------------------

#==============================================================================
# Game_Party
#==============================================================================

class Game_Party  
def gain_item(item_id, n)
  if item_id == 33 # Change this to what the id of the 1st bag is
    $game_party.bag_size = 30 # Maximum number of items you want to have
  elsif item_id == 34 # Change this to what the id of the 2nd bag is
    $game_party.bag_size = 50 # Maximum number of items you want to have
  elsif item_id == 35 # Change this to what the id of the 3rd bag is
    $game_party.bag_size = 200 # Maximum number of items you want to have
# To add even more bag types copy the following code that is commented
# and paste it right above the following else. Also remove the # from the two lines
#elsif item_id == 36
#  $game_party.bag_size = number
# And so on....
  else
    if n < 0
      @add_number = n
    else
      item_bag(n)
    end
     if item_id > 0
       if n + @items_now > $game_party.bag_size and $data_items[item_id].element_set.include?(20)
         $scene = Scene_Item.new(true)
         $scene.remaining = n - @add_number
         @items[item_id] = [[item_number(item_id) + n, 0].max, 999].min
         @items_now += @add_number
       else
         @items[item_id] = [[item_number(item_id) + @add_number, 0].max, 999].min
         @items_now += @add_number
         $game_variables[99] = @add_number
       end
     end
   end
end
#--------------------------------------------------------------------------
def gain_weapon(weapon_id, n, equip = false)
   if equip
     @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
   else
     if n < 0
      @add_number = n
    else
      item_bag(n)
    end
     if weapon_id > 0
       @weapons[weapon_id] = [[weapon_number(weapon_id) + @add_number, 0].max, 99].min
       @items_now += @add_number
       $game_variables[99] = @add_number
     end
   end
end
#--------------------------------------------------------------------------
def gain_armor(armor_id, n, equip = false)
   if equip
      @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
   else
    if n < 0
      @add_number = n
    else
      item_bag(n)
    end
     if armor_id > 0
       @armors[armor_id] = [[armor_number(armor_id) + @add_number, 0].max, 999].min
       @items_now += @add_number
       $game_variables[99] = @add_number
     end
   end
end
#--------------------------------------------------------------------------
def lose_item(item_id, n)
   if item_id > 0
     gain_item(item_id, -n)
   end
end
#--------------------------------------------------------------------------
def lose_weapon(weapon_id, n)
   if weapon_id > 0
     gain_weapon(weapon_id, -n)
   end
end
#--------------------------------------------------------------------------
def lose_armor(armor_id, n)
   if armor_id > 0
     gain_armor(armor_id, -n)
   end
end
#--------------------------------------------------------------------------
def item_bag(n)
   @add_number = 0
   @number = n
   items_max = $game_party.bag_size
   for i in 1..@number
     if @items_now + i > items_max
       break
     else
       @add_number += 1
     end
   end
end
end


#==============================================================================
# Window_ItemAction
#==============================================================================

class Window_ItemAction < Window_Selectable
def initialize
   super(160, 128, 150, 130)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
   self.z = 400
   @index = 0
   @item_max = 3
   refresh
end
#--------------------------------------------------------------------------
def refresh
   self.contents.clear
   self.contents.draw_text(2, 0, 100, 32, "Use")
   self.contents.draw_text(2, 32, 100, 32, "Discard")
   self.contents.draw_text(2, 64, 100, 32, "Cancel")
end
#--------------------------------------------------------------------------
# ● カーソルの矩形更新
#--------------------------------------------------------------------------
def update_cursor_rect
   self.cursor_rect.set(0, @index*32, 120, 32)
end
end


#==============================================================================
# Window_ItemDrop
#==============================================================================

class Window_ItemDrop < Window_Selectable
   def initialize(max_number = 99)
   super(200, 128, 150, 68)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = $fontface
   self.contents.font.size = $fontsize
   self.z = 500
   @index = 1
   @max_number = max_number
   @number = 1
   refresh
end
#--------------------------------------------------------------------------
def refresh
   self.contents.clear
   self.contents.draw_text(0, 0, 100, 32, "Discard:")
   self.contents.draw_text(self.contents.text_size("Discard:").width + 12, 0, 32, 32, @number.to_s)
end
#--------------------------------------------------------------------------
def num
   return @number
end
def update
   if Input.repeat?(Input::UP)
     if @number+1 <= @max_number
       $game_system.se_play($data_system.decision_se)
       @number += 1
       refresh
     else
       $game_system.se_play($data_system.decision_se)
       @number = 1
       refresh      
     end
   end
   if Input.repeat?(Input::DOWN)
     if @number-1 >= 1
       $game_system.se_play($data_system.decision_se)
       @number -= 1
       refresh
     else
       $game_system.se_play($data_system.decision_se)
       @number = @max_number
       refresh
     end
   end
   if Input.repeat?(Input::RIGHT)
     if @number == @max_number
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     if @number+10 <= @max_number
       $game_system.se_play($data_system.decision_se)
       @number += 10
       refresh
     else
       $game_system.se_play($data_system.decision_se)
       @number = @max_number
       refresh
     end
   end
   if Input.repeat?(Input::LEFT)
     if @number == 1
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     if @number-10 > 1
       $game_system.se_play($data_system.decision_se)
       @number -= 10
       refresh
     else
       $game_system.se_play($data_system.decision_se)
       @number = 1
       refresh
     end
   end
end
end


#==============================================================================
# Window_ShopNumber
#==============================================================================

class Window_ShopNumber < Window_Base
#--------------------------------------------------------------------------
def initialize
   super(0, 128, 368, 352)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.name = $fontface  # "Shop" (Quantity) window font
   self.contents.font.size = $fontsize
   @item = nil
   @max = 1
   @price = 0
   @number = $game_party.items_now < $game_party.bag_size ? 1 : 0
end
#--------------------------------------------------------------------------
def set(item, max, price)
   @item = item
   @max_number = max
   @max = $game_party.items_now
   @price = price
   @number = $game_party.items_now < $game_party.bag_size ? 1 : 0
   refresh
end
#--------------------------------------------------------------------------
def number
   return @number
end
#--------------------------------------------------------------------------
def refresh
   self.contents.clear
     draw_item_name(@item, 4, 96)
     self.contents.font.color = normal_color
     self.contents.draw_text(272, 96, 32, 32, "×")
     self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
     self.cursor_rect.set(304, 96, 32, 32)
     domination = $data_system.words.gold
     cx = contents.text_size(domination).width
     total_price = @price * @number
     self.contents.font.color = normal_color
     self.contents.draw_text(4, 160, 328-cx-2, 32, total_price.to_s, 2)
     self.contents.font.color = system_color
     self.contents.draw_text(332-cx, 160, cx, 32, domination, 2)
   end
#--------------------------------------------------------------------------
def update
   super
   if self.active
     if Input.repeat?(Input::RIGHT) and @number + @max < $game_party.bag_size and @number < @max_number
       $game_system.se_play($data_system.cursor_se)
       @number += 1
       refresh
     end
     if Input.repeat?(Input::LEFT) and @number > 1
       $game_system.se_play($data_system.cursor_se)
       @number -= 1
       refresh
     end
     if Input.repeat?(Input::UP) and @number+10 + @max < $game_party.bag_size and @number < @max_number
       $game_system.se_play($data_system.cursor_se)
       @number = [@number + 10, @max].min
       refresh
     end
     if Input.repeat?(Input::DOWN) and @number > 1
       $game_system.se_play($data_system.cursor_se)
       @number = [@number - 10, 1].max
       refresh
     end
   end
end
end


#==============================================================================
# Scene_Item
#==============================================================================

class Scene_Item
attr_accessor :remaining
#--------------------------------------------------------------------------
def initialize(key_item = false)
   @key_item = key_item
   @remaining = 0
end
#--------------------------------------------------------------------------
def main
   @help_window = Window_Help.new
   @item_window = Window_Item.new
   @item_window.help_window = @help_window
   @target_window = Window_Target.new
   @target_window.visible = false
   @target_window.active = false
   @action_window = Window_ItemAction.new
   @action_window.visible = false
   @action_window.active = false
   @drop_items = Window_ItemDrop.new
   @drop_items.visible = false
   @drop_items.active = false
   Graphics.transition
   loop do
     Graphics.update
     Input.update
     update
     if $scene != self
       break
     end
   end
   Graphics.freeze
   @help_window.dispose
   @item_window.dispose
   @target_window.dispose
   @action_window.dispose
   @drop_items.dispose
end
def refresh
   @help_window.refresh
   @item_window.refresh
   @target_window.refresh
   @action_window.refresh
   @drop_items.refresh
end
#--------------------------------------------------------------------------
def update
   @help_window.update
   @word_item = @remaining <= 1 ? " item" : " items"
   if @item_window.active
     @item_window.update
     if @key_item then @help_window.set_text("You need to discard " + @remaining.to_s  + @word_item) end
     update_item
     return
   end
   if @action_window.active
     @action_window.update
     if @key_item then @help_window.set_text("You need to discard " + @remaining.to_s  + @word_item) end
     update_action
     return
   end
   if @drop_items.active
     @drop_items.update
     if @key_item then @help_window.set_text("You need to discard " + @remaining.to_s  + @word_item) end
     update_drop
     return
   end
   if @target_window.active
     @target_window.update
     if @key_item then @help_window.set_text("You need to discard " + @remaining.to_s  + @word_item) end
     update_target
     return
   end
end
#--------------------------------------------------------------------------
def update_item
   if Input.trigger?(Input::B) and @remaining <= 0
     $game_system.se_play($data_system.cancel_se)
     $scene = Scene_Menu.new(0)
     return
   end
   if Input.trigger?(Input::C)
     @item = @item_window.item
     $game_system.se_play($data_system.decision_se)
     @item_window.active = false
     @action_window.active = true
     @action_window.visible = true
     return
   end
end
def update_action
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @action_window.active = false
     @action_window.visible = false
     @item_window.active = true
     return
   end
   if Input.trigger?(Input::C)
     if @action_window.index == 0
       unless $game_party.item_can_use?(@item.id)
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       unless @item.is_a?(RPG::Item)
         $game_system.se_play($data_system.buzzer_se)
         return
       end
       $game_system.se_play($data_system.decision_se)
       if @item.scope >= 3
         @action_window.active = false
         @action_window.visible = false
         @target_window.x = (@item_window.index + 1) % 2 * 304
         @target_window.visible = true
         @target_window.active = true
         if @item.scope == 4 || @item.scope == 6
           @target_window.index = -1
         else
           @target_window.index = 0
         end
       else
         if @item.common_event_id > 0
           $game_temp.common_event_id = @item.common_event_id
           $game_system.se_play(@item.menu_se)
           if @item.consumable
             $game_party.lose_item(@item.id, 1)
             @item_window.draw_item(@item_window.index)
           end
           $scene = Scene_Map.new
           return
         end
       end
     elsif @action_window.index == 1
       if @item.is_a?(RPG::Item) and @item.element_set.include?(20)
           $game_system.se_play($data_system.buzzer_se)
           return
       else
         $game_system.se_play($data_system.decision_se)
         @action_window.active = false
         if @item.is_a?(RPG::Item)
           @drop_items = Window_ItemDrop.new($game_party.item_number(@item.id))
         elsif @item.is_a?(RPG::Armor)
           @drop_items = Window_ItemDrop.new($game_party.armor_number(@item.id))
         elsif @item.is_a?(RPG::Weapon)
           @drop_items = Window_ItemDrop.new($game_party.weapon_number(@item.id))
         end
         @drop_items.active = true
         @drop_items.visible = true
       end
     elsif @action_window.index == 2
       $game_system.se_play($data_system.cancel_se)
       @action_window.visible = false
       @action_window.active = false
       @item_window.active = true
     end
   end
end
def update_drop
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @drop_items.active = false
     @drop_items.visible = false
     @action_window.active = true
     return
   end
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.decision_se)
     if @item.is_a?(RPG::Item)
       $game_party.lose_item(@item.id, @drop_items.num)
     elsif @item.is_a?(RPG::Armor)
       $game_party.lose_armor(@item.id, @drop_items.num)
     elsif @item.is_a?(RPG::Weapon)
       $game_party.lose_weapon(@item.id, @drop_items.num)
     end
     if @remaining > 0
       if @remaining - @drop_items.num <= 0
         $scene = Scene_Map.new
       else
         @remaining -= @drop_items.num
       end
     end
       @item_window.refresh
       @drop_items.active = false
       @drop_items.visible = false
       @action_window.visible = false
       @item_window.active = true
   end
end
#--------------------------------------------------------------------------
def update_target
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     unless $game_party.item_can_use?(@item.id)
       @item_window.refresh
     end
     @item_window.active = true
     @target_window.visible = false
     @target_window.active = false
     return
   end
   if Input.trigger?(Input::C)
     if $game_party.item_number(@item.id) == 0
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     if @target_window.index == -1
       used = false
       for i in $game_party.actors
         used |= i.item_effect(@item)
       end
     end
     if @target_window.index >= 0
       target = $game_party.actors[@target_window.index]
       used = target.item_effect(@item)
     end
     if used
       $game_system.se_play(@item.menu_se)
       if @item.consumable
         $game_party.lose_item(@item.id, 1)
         @item_window.draw_item(@item_window.index)
       end
       @target_window.refresh
       if $game_party.all_dead?
         $scene = Scene_Gameover.new
         return
       end
       if @item.common_event_id > 0
         $game_temp.common_event_id = @item.common_event_id
         $scene = Scene_Map.new
         return
       end
     end
     unless used
       $game_system.se_play($data_system.buzzer_se)
     end
     return
   end
end
end


#==============================================================================
# Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
   def equip(equip_type, id, player_equip = false)
   case equip_type
   when 0
     if id == 0 or $game_party.weapon_number(id) > 0
         $game_party.gain_weapon(@weapon_id, 1, player_equip)
         @weapon_id = id
         $game_party.lose_weapon(id, 1)
     end
   when 1
     if id == 0 or $game_party.armor_number(id) > 0
       update_auto_state($data_armors[@armor1_id], $data_armors[id])
       $game_party.gain_armor(@armor1_id, 1, player_equip)
       @armor1_id = id
       $game_party.lose_armor(id, 1)
     end
   when 2
     if id == 0 or $game_party.armor_number(id) > 0
       update_auto_state($data_armors[@armor2_id], $data_armors[id])
       $game_party.gain_armor(@armor2_id, 1, player_equip)
       @armor2_id = id
       $game_party.lose_armor(id, 1)
     end
   when 3
     if id == 0 or $game_party.armor_number(id) > 0
       update_auto_state($data_armors[@armor3_id], $data_armors[id])
       $game_party.gain_armor(@armor3_id, 1, player_equip)
       @armor3_id = id
       $game_party.lose_armor(id, 1)
     end
   when 4  
     if id == 0 or $game_party.armor_number(id) > 0
       update_auto_state($data_armors[@armor4_id], $data_armors[id])
       $game_party.gain_armor(@armor4_id, 1, player_equip)
       @armor4_id = id
       $game_party.lose_armor(id, 1)
     end
   end
end
end


#==============================================================================
# Scene_Equip
#==============================================================================

class Scene_Equip
  def refresh
   @item_window1.visible = (@right_window.index == 0)
   @item_window2.visible = (@right_window.index == 1)
   @item_window3.visible = (@right_window.index == 2)
   @item_window4.visible = (@right_window.index == 3)
   @item_window5.visible = (@right_window.index == 4)
   item1 = @right_window.item
   case @right_window.index
   when 0
     @item_window = @item_window1
   when 1
     @item_window = @item_window2
   when 2
     @item_window = @item_window3
   when 3
     @item_window = @item_window4
   when 4
     @item_window = @item_window5
   end
   if @right_window.active
     @left_window.set_new_parameters(nil, nil, nil)
   end
   if @item_window.active
     item2 = @item_window.item
     last_hp = @actor.hp
     last_sp = @actor.sp
     @actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
     new_atk = @actor.atk
     new_pdef = @actor.pdef
     new_mdef = @actor.mdef
     @actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
     @actor.hp = last_hp
     @actor.sp = last_sp
     @left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
   end
end
#--------------------------------------------------------------------------
def update_item
   if Input.trigger?(Input::B)
     $game_system.se_play($data_system.cancel_se)
     @right_window.active = true
     @item_window.active = false
     @item_window.index = -1
     return
   end
   if Input.trigger?(Input::C)
     $game_system.se_play($data_system.equip_se)
     item = @item_window.item
     $game_party.equip_fix = true
     @actor.equip(@right_window.index, item == nil ? 0 : item.id, true)
     $game_party.equip_fix = false
     @right_window.active = true
     @item_window.active = false
     @item_window.index = -1
     @right_window.refresh
     @item_window.refresh
     return
   end
end
end


You should be able to use the script now... But I've also added some special features, those will be explained next.
*To change the bag size use the Call RGSS Script and write
Code:
$game_party.bag_size = The number you want


This doesn't work anymore... You need to use items instead :hmm:

*If you use the add items/weapons/armors method you can, if you show a 'gained item' message, use the \v[99] to show how many items you gained. For example, if we have 20 items in the bag already, and the max items you can have is 30:
Code:
<>Change Items: [Potion] + 15
<>Message: You got \v[99] potions!



Then the message would say you got 10 potions.

*If you want the player to be able to buy an upgraded bag do this:
First of all create the bags you want to use (they should be in the Items section).

Now remember the id's of them and go to the line that says
Code:
if item_id == 33 # Change this to what the id of the 1st bag is

Change 33 to what the id of the first bag was and do so with the following lines too, only that you write the id of the second, third etc.

Find this line
Code:
if @item == nil or @item.price > $game_party.gold

Under that you should see some code:
Code:
if (@item.id == 33 and $game_party.bag_size == 30) or
         (@item.id == 33 and $game_party.bag_size == 50) or
         (@item.id == 33 and $game_party.bag_size == 100)
         $game_system.se_play($data_system.buzzer_se)
         return
       elsif (@item.id == 34 and $game_party.bag_size == 50) or
         (@item.id == 34 and $game_party.bag_size == 100)
         $game_system.se_play($data_system.buzzer_se)
         return
       elsif @item.id == 35 and $game_party.bag_size == 100
         $game_system.se_play($data_system.buzzer_se)
         return
       end


You would possibly need to change some stuff in that code so I'll just explain what a few things mean in there:
Code:
@item.id = The id of the item, should be the id of the bag.
$game_party.bag_size = The maximum number of items you can have.


Oh.. I forgot one thing, if you have more or less than 3 bags do as followed:

This can be quite tricky, but I'll try to explain it...
Let's say we have 4 bags and want to edit the code so that works, then we would have to find this line "(@item.id == 33 and $game_party.bag_size == 100)" in the Scene_Shop script. And under that add
Code:
(@item.id == 33 and $game_party.bag_size == maximum items for 4th bag)


You may now ask, why?
It's quite simple. It's so that the player can't downgrade the bag (buy a bag with a smaller maximum).
If you understood that you should be able to understand what to do with the following code in Scene_Shop.

*You can now also discard items smile.gif
To set an item as a key-item, that can't be discarded, make a new attribute at id 20 and make the items use that attribute.
This new code also has the default Scene_Shop provided so you don't have to do the things I mentioned in the previous *.

*If you're bag is full and you gain some key-items you're prompted to discard the number that's necessseary for the key-items to fit

If you don't understand something just ask and I'll answer it


And that's about it... Hope you enjoy!

UPDATE: Now works with shops so that it looks good!
UPDATE2: You can now add a function so that the player can buy a bag upgrade!
UPDATE3: Now when you press an item a menu comes up asking what you'll do. The options are "Use", "Discard", "Cancel". And it actually works
UPDATE4: Bag full, prompt on key-items. Fixed a few bugs too.
UPDATE5: Added screenies, demo and fixed some bugs.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Fyre < Status Menu FyreXKnight 0 2,247 07-01-2008, 01:00 PM
Last Post: FyreXKnight
  Run Common Events in Menu GubiD 0 2,152 08-12-2007, 01:00 PM
Last Post: GubiD
  Monster drop more than one item. Hima 0 2,194 04-25-2007, 01:00 PM
Last Post: Hima
  GameOver Menu sasuke89 0 2,094 09-18-2006, 01:00 PM
Last Post: sasuke89
  GameOver Menu Script sasuke89 0 2,097 06-08-2006, 01:00 PM
Last Post: sasuke89
  Victory counter in menu garfunkle 0 2,165 01-05-2006, 01:00 PM
Last Post: garfunkle
  Gained item/gold window. Jimmie 0 2,150 08-28-2005, 01:00 PM
Last Post: Jimmie
  Ten items in equip menu! Jimmie 0 2,250 08-13-2005, 01:00 PM
Last Post: Jimmie
  Item Detail Script jackatrades 0 2,248 05-19-2005, 01:00 PM
Last Post: jackatrades



Users browsing this thread: