Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lite Containers
#1
"Lite" Containers
by Jimmie
Nov 3, 2006

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.


Code:
#==============================================================================
  # ** Lite Containers
  #------------------------------------------------------------------------------
  # Jimme Reashu / Jimmie
  # Version 1
  # Last updated: November 4th -06
  #==============================================================================
  
  # Turn these lines and the very last "end" into comments by adding "#"'s if you don't use the SDK
  #------------------------------------------------------------------------------
  SDK.log('Lite Containers', 'Jimme Reashu', 1, 'Nov. 4 -06')
  #--------------------------------------------------------------------------
  # Begin SDK Enabled Check
  #--------------------------------------------------------------------------
  if SDK.state('Lite Containers') == true
  #------------------------------------------------------------------------------
  
  
  #------------------------------------------------------------------------------
  # Addon to Game_Party BEGINS
  # This lets us check for number of items without specifying type.
  #------------------------------------------------------------------------------
# This is the maximum number of items the party can carry. Set to 0 for no limit.
MAX_ITEMS = 16
class Game_Party
  def number(item)
    case item
    when RPG::Item
      return item_number(item.id)
    when RPG::Weapon
      return weapon_number(item.id)
    when RPG::Armor
      return armor_number(item.id)
    end
  end
  
  def total_items
    @number = 0
    for i in 1..$data_items.size
      @number += item_number(i)
    end
    for i in 1...$data_weapons.size
      @number += weapon_number(i)
    end
    for i in 1...$data_armors.size
      @number += armor_number(i)
    end
    @number
  end
  
  def gain_item(item_id, n)
    if item_id > 0
      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
      if total_items > MAX_ITEMS && MAX_ITEMS != 0
        difference = @total_items - MAX_ITEMS
        lose_item(item_id, difference)
      end
    end
  end
  
  def gain_weapon(weapon_id, n)
    if weapon_id > 0
      @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
      if total_items > MAX_ITEMS && MAX_ITEMS != 0
        difference = @total_items - MAX_ITEMS
        lose_weapon(weapon_id, difference)
      end
    end
  end
  
  def gain_armor(armor_id, n)
    if armor_id > 0
      @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
      if total_items > MAX_ITEMS && MAX_ITEMS != 0
        difference = @total_items - MAX_ITEMS
        lose_armor(armor_id, difference)
      end
    end  
  end
end  
  #------------------------------------------------------------------------------
  # Addon to Game_Party ENDS
  #------------------------------------------------------------------------------

  
  #------------------------------------------------------------------------------
  # Container System Menu BEGINS
  # This is the menu that appears first of all, with Open/Close option
  #------------------------------------------------------------------------------
  
class Scene_ContainerMenu
  
  #------------------------------------------------------------------------------
  def main
    # This defines the map spriteset, so that events and the map will still be visible.
    @spriteset = Spriteset_Map.new
    
    # These commands are the ones you see when you activate a container.
    @commands = ['Open', 'Exit']
    
    # The command window is what you control. This is what shows the commands.
    @command_window = Window_Command.new(160, @commands)
    @command_window.y = ($game_player.screen_y - @command_window.height/2)
    @command_window.x = ($game_player.screen_x - 80)
    @command_window.index = 0
    @command_window.opacity = 160
    
    # The help window describes the commands in the command window.
    @help_window = Window_Help.new
    @help_window.opacity = 160
    
    # This fades out the map and then fades in the map together with the command window.
    # (The map fading is not visible, but it's there)
    Graphics.transition
    
    # This is the loop that updates graphics, keyboard input, the map and the command window.
    loop do
      Graphics.update
      Input.update
      update
      
      # If the scene changes, the loop stops.
      if $scene != self
        break
      end
    end
    
    # When the scene changes, the graphics freeze until the next scene is ready to take over.
    Graphics.freeze
    
    # All windows and the map sprites are "disposed", their memory slots are freed.
    @command_window.dispose
    @help_window.dispose
    @spriteset.dispose
    
  end
  
  #------------------------------------------------------------------------------
  # This is the method that updates all windows and the map.
  def update
    
    # These are the commands to update everything included in this scene.
    @command_window.update
    @help_window.update
    $game_map.update
    @spriteset.update
    
    # This calls the next method: update_command, which further controls what happens with the
    # when RMXP registers keyboard input.
    update_command
  end
  
  #------------------------------------------------------------------------------
  # This is the method that controls the scene based on input from the player.
  def update_command
    
    # If the player presses game-key B (Esc. or X by default), the following code is run:
    if Input.trigger?(Input::B)
      
      # Play the "cancel" sound set in the database
      $game_system.se_play($data_system.cancel_se)
      
      # Return to the map
      $scene = Scene_Map.new
      
      # Abort this method and return to the "update" method, which has reched its end,
      # meaning that it returns to the "Main" loop and the jumps to Scene_Map.
      return
    end     # Ends the "if"
    
    # If the player presses game-key C (Enter, Num-0, or C by default)
    if Input.trigger?(Input::C)
      
    # The "case" is basically the same things as a bunch of simple "if"'s.
    # See the following comments for what they do...
    case @commands[@command_window.index]
    
    # "If" @commands[@command_window.index] is 'Open'...
    when 'Open'
      # Go to Scene_ContainerItems and...
      $scene = Scene_ContainerItems.new
      # Play the "decision" or "confirm" sound in the database
      $game_system.se_play($data_system.decision_se)
      
    # But "if" it's 'Exit' instead...
    when 'Exit'
      # Go back to Scene_Map and...
      $scene = Scene_Map.new
      # Play the cancel sound.
      $game_system.se_play($data_system.cancel_se)
      
      
    end   # "Cases" are ended in the same way as "ifs"
    
  end     # Ends the "if"
  
    # This is what's shown in the help window, the mechanics are the same as above
    case @commands[@command_window.index]
    when 'Open'
      # Calls a method within the Window_Help class to change the text of the help window.
      @help_window.set_text('Open the container to manage items.',1)
    when 'Exit'
      # Calls a method within the Window_Help class to change the text of the help window.
      @help_window.set_text('Close this menu and return to the map.',1)
    end       # Ends the "case"
    return    # Returns to the "update" method.
  end         # Ends the method.
  #------------------------------------------------------------------------------
  
end           # Ends the class

  #------------------------------------------------------------------------------
  # Container System Menu ENDS
  #------------------------------------------------------------------------------
  
  
  
  #------------------------------------------------------------------------------
  # Container Items Menu BEGINS
  # This is the scene that controls the system as soon as Open
  # is chosen in the main menu.
  #------------------------------------------------------------------------------
  
class Scene_ContainerItems
  #--------------------------------------------------------------------------
  
  def main
    @action = 0   # This variable is used to keep track of what the player is doing.
                        # 0 = Container window active
                        # 1 = Item window active
                        # 2 = Action window active (Cont.)
                        # 3 = Action window active (Inv)
                        # 4 = Using from cont.
                        # 5 = Taking from cont.
                        # 6 = Tossing from cont.
                        # 7 = Using from inv.
                        # 8 = Giving from inv.
                        # 9 = Tossing from inv.
    
    # The help window is the same as before, it's used to describe the selection further.
    @help_window = Window_Help.new
    @help_window.opacity = 160
    
    # The window "@item_window" shows what items are in the container.
    @item_window = Window_ContainerItem.new
    # This sets what window will show details about the selection.
    # In this case, it's the just-defined window "@help_window"
    @item_window.help_window = @help_window
    # The opacity is 0 because we'll be fooling around with headers and stuff,
    # so we use dummy windows to show a border around everything instead of separate windows.
    @item_window.opacity = 0
    
    # The window "@small_window" got its name from the longer "Small Item Window".
    # It's based on the window "Window_Item" in the main menu, but it's been made smaller.
    @small_window = Window_ItemSmall.new
    @small_window.help_window = @help_window
    # "Active" is a variable often used when determining whether the window's cursor should follow
    # the input and things like that. Without it, you'd be selecting things in all windows at once...
    @small_window.active = false
    # The opacity is 0 for the same reason as above.
    @small_window.opacity = 0
    # This calls a method in the class "Window_ItemSmall". It removes the cursor without changing
    # the selection.
    @small_window.clear_cursor
    
    # This is the first dummy window I mentioned. It forms the background of "@item_window".
    @dummy1 = Window_Base.new(0,256,320,224)
    # The contents are what you actually draw stuff on. It has to be 32x32 smaller, or else the
    # "arrows" in the windowskin that indicate more content will be shown.
    @dummy1.contents = Bitmap.new(288,192)
    # A little transparency never hurts, especially since the map is updating in the background.
    @dummy1.opacity = 160
    
    # This window is basically the same as "@dummy1", only a bit to the right.
    @dummy2 = Window_Base.new(320,256,320,224)
    @dummy2.contents = Bitmap.new(288,192)
    @dummy2.opacity = 160
    
    # The target window is what you use when you select a target for items used in this scene.
    @target_window = Window_ContainerTarget.new
    # The target window should be invisible until we select an item to use...
    @target_window.visible = false
    # And should not follow input until then either.
    @target_window.active = false
    @target_window.opacity = 160
    # However, setting the position early never hurts.
    @target_window.y = 64
    
    # This is the same spriteset as in the previous Scene, it shows what's on the map.
    @spriteset = Spriteset_Map.new
    
    # These lines of code are needed so that people who still haven't bought the legal RMXP can
    # use the script. Remove the comments if you're one of them.
    # You'll also need to search the script for other instances (because there ARE more).
    #--------------------------------------------------------------------------
     #@dummy1.contents.font.name = $defaultfonttype
     #@dummy1.contents.font.size = $defaultfontsize
     #@dummy2.contents.font.name = $defaultfonttype
     #@dummy2.contents.font.size = $defaultfontsize
    #--------------------------------------------------------------------------
    
    # This calculates the width of the text, so that the lines can be drawn accordingly.
    w1 = @dummy1.contents.text_size('Container Items').width + 8
    w2 = @dummy2.contents.text_size('Party Items').width + 8
    # Draws the line, and then writes the text for dummy #1
    @dummy1.contents.fill_rect(Rect.new(0,26,w1,1),Color.new(255,255,255))
    @dummy1.contents.draw_text(4,0,288,32,'Container Items')
    # Same thing for # 2
    @dummy2.contents.fill_rect(Rect.new(0,26,w2,1),Color.new(255,255,255))
    @dummy2.contents.draw_text(4,0,288,32,'Party Items')
      
    # This loop is the same as the one in the previous scenes. Almost all scenes use this.
    # The only difference is what is disposed at the end.
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @dummy1.dispose
    @dummy2.dispose
    @help_window.dispose
    @item_window.dispose
    @target_window.dispose
    @small_window.dispose
    @spriteset.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @help_window.update
    @target_window.update
    @dummy1.update
    @dummy2.update
    $game_map.update
    @spriteset.update
    case @action
    when 0
      update_item
      return
    when 1
      update_small
      return
    when 2
      update_action
      return
    when 3
      update_action
      return
    when 4
      update_target
      return
    when 5
      update_trade
      return
    when 6
      update_toss
      return
    when 7
      update_target
      return
    when 8
      update_trade
      return
    when 9
      update_toss
      return
    end
    
    if @item_window.active
      update_item
      return
    end
    if @target_window.active
      update_target
      return
    end
    if @small_window.active
      update_small
      return
    end
    if @action_window.active
      update_action
      return
    end
    if @number_window != nil
      update_trade
      return
    end
    if @toss_window != nil
      update_toss
      return
    end
    
  end
  
  def update_dummy(height)
    @height = height
    return if @dummy3.disposed?
     unless @dummy3.height == @height
          @dummy3.height = height
          @dummy3.contents = Bitmap.new(128,@height-32)
          #@dummy3.contents.font.name = $defaultfonttype
      #@dummy3.contents.font.size = $defaultfontsize
      w3 = (128 - @dummy3.contents.text_size(@item.name).width - 32)/2
      @dummy3.contents.fill_rect(w3,26,128-(w3*2),1,Color.new(255,255,255))
      @dummy3.contents.blt(w3+4,4,RPG::Cache.icon(@item.icon_name),Rect.new(0,0,24,24),255)
      @dummy3.contents.draw_text(w3+32,0,128-(w3*2)-32,32,@item.name)
    end
  end
  
  #--------------------------------------------------------------------------
  def update_small
    @small_window.update
    
    if Input.dir4 == 4
      @small_window.clear_cursor
      @action = 0
      @item_window.active = true
      @small_window.active = false
      $game_system.se_play($data_system.cursor_se)
      return
    end
    
        if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_ContainerMenu.new
      return
    end
    if Input.trigger?(Input::C)
      @action = 3
      @item = @small_window.item
      @h = ((@item.is_a?(RPG::Item) and (@item.occasion == 0 or @item.occasion == 2)) ? 160 : 128)
      @action_window = Window_PControl.new(@item)
      @item_window.active = false
      @action_window.active = true
      @action_window.x = 240
      @action_window.y = 116
      @action_window.z = 110
      @action_window.opacity = 0
      @dummy3 = Window_Base.new(240,80,160,@h)
      @dummy3.contents = Bitmap.new(128,@h-32)
      #@dummy3.contents.font.name = $defaultfonttype
      #@dummy3.contents.font.size = $defaultfontsize
      @dummy3.opacity = 160
      @dummy3.z = 109
      w3 = (128 - @dummy3.contents.text_size(@item.name).width - 32)/2
      @dummy3.contents.fill_rect(w3,26,128-(w3*2),1,Color.new(255,255,255))
      @dummy3.contents.blt(w3+4,4,RPG::Cache.icon(@item.icon_name),Rect.new(0,0,24,24),255)
      @dummy3.contents.draw_text(w3+32,0,128-(w3*2)-32,32,@item.name)
    
      $game_system.se_play($data_system.decision_se)
    
      return
    end
  end
  
  def update_toss
    @number_window.update
    if Input.trigger?(Input::B)
      case @action
      when 6
        @action = 2
      when 9
        @action = 3
      end
      @number_window.dispose
      @number_window = nil
      @action_window.active = true
      @action_window.visible = true
      $game_system.se_play($data_system.cancel_se)
      return
    end
    if Input.trigger?(Input::C)
      
      case @number_window.index
      when 0 #Toss 1
        numb = $container.toss(@item,1)
        $game_system.se_play($data_system.decision_se)
        if numb == 1
          @number_window.dispose
          @number_window = nil
          @action_window.dispose
          @dummy3.dispose
          case @action
          when 6
            @action = 0
            @item_window.active = true
          when 9
            @action = 1
            @small_window.active = true
          end
          
        end
      when 1 #Toss All
        $container.toss(@item,99)
        $game_system.se_play($data_system.decision_se)
        @number_window.dispose
        @number_window = nil
        @action_window.dispose
        @dummy3.dispose
        case @action
          when 6
            @action = 0
            @item_window.active = true
          when 9
            @action = 1
            @small_window.active = true
          end
      when 2 #Back
        @number_window.dispose
        @number_window = nil
        case @action
          when 6
            @action = 2
          when 9
            @action = 3
          end
        @action_window.active = true
        @action_window.visible = true
        $game_system.se_play($data_system.cancel_se)
        return
      end
      @item_window.refresh
      @small_window.refresh
    end
  end
  
  def update_trade
    @number_window.update
    if Input.trigger?(Input::B)
      case @action
          when 5
            @action = 2
          when 8
            @action = 3
          end
      @number_window.dispose
      @number_window = nil
      @action_window.active = true
      @action_window.visible = true
      $game_system.se_play($data_system.cancel_se)
      return
    end
    if Input.trigger?(Input::C)
      
      case @number_window.index
      when 0 # 1
        case @action
          when 5
            numb = $container.to_party(@item,1)
          when 8
            numb = $container.from_party(@item,1)
          end
        if numb == false
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        
        $game_system.se_play($data_system.decision_se)
        if numb == 1
          @number_window.dispose
          @number_window = nil
          @action_window.dispose
          @dummy3.dispose
          case @action
          when 5
            @action = 0
            @item_window.active = true
          when 8
            @action = 1
            @small_window.active = true
          end
        end
      when 1 #Take All
        case @action
          when 5
            numb = $container.to_party(@item,99)
            if numb == false
          $game_system.se_play($data_system.buzzer_se)
          return
        end
          when 8
            $container.from_party(@item,99)
          end
        $game_system.se_play($data_system.decision_se)
        @number_window.dispose
        @number_window = nil
        @action_window.dispose
        @dummy3.dispose
        case @action
          when 5
            @action = 0
            @item_window.active = true
          when 8
            @action = 1
            @small_window.active = true
          end
      when 2 #Back
        @number_window.dispose
        @number_window = nil
        @action_window.active = true
        @action_window.visible = true
        case @action
          when 5
            @action = 2
          when 8
            @action = 3
          end
        $game_system.se_play($data_system.cancel_se)
        return
      end
      @item_window.refresh
      @small_window.refresh
    end
  end
  
    def update_action
      @action_window.update
      update_dummy(@h) unless @h == nil
      
      if Input.trigger?(Input::B)
        case @action
          when 2
            @action = 0
            @item_window.active = true
          when 3
            @action = 1
            @small_window.active = true
          end
      @action_window.dispose
      @dummy3.dispose
      $game_system.se_play($data_system.cancel_se)
      return
    end
    
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      ind = @action_window.index
      ind += 1 unless (@item.is_a?(RPG::Item) && (@item.occasion == 0 or @item.occasion == 2))
      case ind
      when 0 #USE item
        
        if @item.scope >= 3
          case @action
          when 2
            @action = 4
          when 3
            @action = 7
          end
          @action_window.visible = false
          update_dummy(64)
          @dummy3.y = 192
          @action_window.active = false
          @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
        when 1 #TAKE/GIVE item
          @action_window.active = false
          @action_window.visible = false
          case @action
          when 2
            @action = 5
          @number_window = Window_Take.new(@item)
          when 3
            @action = 8
            @number_window = Window_Give.new(@item)
          end
          @number_window.z = 111
          @number_window.x = 240
          @number_window.y  = 116
          @number_window.opacity = 0
          @number_window.active = true
          
          update_dummy(160)
        
        when 2 #TOSS item
          @action_window.active = false
          @action_window.visible = false
          case @action
          when 2
            @action = 6
          when 3
            @action = 9
          end
          @number_window = Window_Toss.new(@item)
          @number_window.z = 111
          @number_window.x = 240
          @number_window.y  = 116
          @number_window.opacity = 0
          @number_window.active = true
        update_dummy(160)
      end      
      
    end
    
  end
  

  
  
  def update_item
    @item_window.update
    
    if Input.dir4 == 6
      @item_window.clear_cursor
      @action = 1
      @item_window.active = false
      @small_window.active = true
      $game_system.se_play($data_system.cursor_se)
      return
    end
    
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_ContainerMenu.new
      return
    end
    if Input.trigger?(Input::C)
      @action = 2
      @item = @item_window.item
      @h = ((@item.is_a?(RPG::Item) and (@item.occasion == 0 or @item.occasion == 2)) ? 160 : 128)
      @action_window = Window_CControl.new(@item)
      @item_window.active = false
      @action_window.active = true
      @action_window.x = 240
      @action_window.y = 116
      @action_window.z = 110
      @action_window.opacity = 0
      @dummy3 = Window_Base.new(240,80,160,@h)
      @dummy3.contents = Bitmap.new(128,@h-32)
      #@dummy3.contents.font.name = $defaultfonttype
      #@dummy3.contents.font.size = $defaultfontsize
      @dummy3.opacity = 160
      @dummy3.z = 109
      w3 = (128 - @dummy3.contents.text_size(@item.name).width - 32)/2
      @dummy3.contents.fill_rect(w3,26,128-(w3*2),1,Color.new(255,255,255))
      @dummy3.contents.blt(w3+4,4,RPG::Cache.icon(@item.icon_name),Rect.new(0,0,24,24),255)
      @dummy3.contents.draw_text(w3+32,0,128-(w3*2)-32,32,@item.name)
    
      $game_system.se_play($data_system.decision_se)
    
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_target
    
    if $container.number(@item) == 0
      @action_window.dispose
      @dummy3.visible = false
      case @action
      when 4
        @action = 0
        @item_window.active = true
      when 7
        @action = 1
        @small_window.active = true
      end
      
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      unless $container.useable(@item.id)
        @item_window.refresh
      end
      case @action
      when 4
        @action = 2
      when 7
        @action = 3
      end
      @action_window.active = true
      @action_window.visible = true
      @target_window.visible = false
      @target_window.active = false
      update_dummy(160)
      @dummy3.y = 80
      return
    end
    if Input.trigger?(Input::C)
      unless $container.useable(@item)
        $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
          $container.remove(@item, 1)
          @item_window.refresh
        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
  #------------------------------------------------------------------------------
  # Container Item Menu ENDS
  #------------------------------------------------------------------------------

  
  #------------------------------------------------------------------------------
  # Container Item Window BEGINS
  # This window shows what's in the container.
  #------------------------------------------------------------------------------

class Window_ContainerItem < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(0, 288, 320, 192)
    @column_max = 1
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    @numbers = []
    if $container.items != nil
    $container.items.each{|a|@data.push($data_items[a[0]]);@numbers.push(a[1])}
  end
  if $container.weapons != nil
    $container.weapons.each{|a|@data.push($data_weapons[a[0]]);@numbers.push(a[1])}
    end
    if $container.armors != nil
    $container.armors.each{|a|@data.push($data_armors[a[0]]);@numbers.push(a[1])}
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      #self.contents.font.name = $defaultfonttype
      #self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    number = @numbers[index]
    if item.is_a?(RPG::Item) and (item.occasion == 0 or item.occasion == 2)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4
    y = index * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ':', 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? '' : self.item.description)
  end
  
    def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = self.width / @column_max - 32
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * 32 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 32)
  end
  
  def clear_cursor
    self.cursor_rect.empty
  end
  
end
  #------------------------------------------------------------------------------
  # Container Item Window ENDS
  #------------------------------------------------------------------------------

    #------------------------------------------------------------------------------
  # Party Item Window BEGINS
  #------------------------------------------------------------------------------
class Window_ItemSmall < Window_Selectable
  #--------------------------------------------------------------------------
  def initialize
    super(320, 288, 320, 192)
    @column_max = 1
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    unless $game_temp.in_battle
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0
          @data.push($data_weapons[i])
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors[i])
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
     #self.contents.font.name = $defaultfonttype
      #self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    y = index * 32
    rect = Rect.new(4, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(4, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(4 + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(4 + 240, y, 16, 32, ':', 1)
    self.contents.draw_text(4 + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? '' : self.item.description)
  end
  
  def clear_cursor
    self.cursor_rect.empty
  end
end

  #------------------------------------------------------------------------------
  # Party Item Window ENDS
  #------------------------------------------------------------------------------
  
  
    #------------------------------------------------------------------------------
  # Item Target Window BEGINS
  #------------------------------------------------------------------------------
class Window_ContainerTarget < Window_Base
  attr_accessor :index
  #--------------------------------------------------------------------------
  def initialize
    super(0, 256, 640, 128)
    self.contents = Bitmap.new(width - 32, height - 32)
    #self.contents.font.name = $defaultfonttype
    #self.contents.font.size = $defaultfontsize
    refresh
    @index = -1
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    off = ((608/$game_party.actors.size) - 120)/2
    for i in 0...$game_party.actors.size
      x = (608/$game_party.actors.size) * i
      y = 0
      actor = $game_party.actors[i]
      draw_actor_graphic(actor, x + off +20, y + 85)
      draw_actor_name(actor, x+off+10, y)
      hp_bar(actor,x+off+40,y+45,80,4)
      draw_actor_hp(actor, x+off+40, y + 21,80)
      sp_bar(actor,x+off+40,y+65,80,4)
      draw_actor_sp(actor, x+off+40, y + 41,80)
      draw_actor_state(actor,x+off+40,y+62,80)
    end
    dist = 608/$game_party.actors.size
    for i in 1...$game_party.actors.size
      self.contents.fill_rect(Rect.new(i * dist,0,2,96),Color.new(255,255,255))
      end
  end
  #--------------------------------------------------------------------------
  def update_cursor_rect
    
    x = ((608/$game_party.actors.size) * @index).round
    off = (((608/$game_party.actors.size) - 140)/2).round
    if @index < 0
      self.cursor_rect.empty
    else
      self.cursor_rect.set(x+off, 0, 140, 96)
    end
  end
  
  def update
    super
      if Input.trigger?(Input::RIGHT)
          $game_system.se_play($data_system.cursor_se)
          @index += 1
          @index %= $game_party.actors.size
      end
      if Input.trigger?(Input::LEFT)
          $game_system.se_play($data_system.cursor_se)
          @index -= 1
          @index += $game_party.actors.size
          @index %= $game_party.actors.size
      end
    if self.active and @help_window != nil
      update_help
    end
    update_cursor_rect
  end
end
  #------------------------------------------------------------------------------
  # Item Target Window ENDS
  #------------------------------------------------------------------------------
  
  
    #------------------------------------------------------------------------------
  # Small Windows BEGIN
  #------------------------------------------------------------------------------

class Window_CControl < Window_Command
  def initialize(item)
    if item.is_a?(RPG::Item)
      super(160,['Use','Take','Discard'])
    else
      super(160,['Take','Discard'])
    end
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(0, 32 * index, self.contents.width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index],1)
  end
end

class Window_PControl < Window_Command
  def initialize(item)
    if item.is_a?(RPG::Item)
      super(160,['Use','Deposit','Discard'])
    else
      super(160,['Deposit','Discard'])
    end
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(0, 32 * index, self.contents.width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index],1)
  end
end

class Window_Take < Window_Command
  def initialize(item)
      super(160,['Take 1','Take All','Go Back'])
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(0, 32 * index, self.contents.width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index],1)
  end
end

class Window_Give < Window_Command
  def initialize(item)
      super(160,['Deposit 1','Deposit All','Go Back'])
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(0, 32 * index, self.contents.width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index],1)
  end
end

class Window_Toss < Window_Command
  def initialize(item)
      super(160,['Discard 1','Discard All','Go Back'])
  end
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(0, 32 * index, self.contents.width, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index],1)
  end
end
  #------------------------------------------------------------------------------
  # Small Windows END
  #------------------------------------------------------------------------------
  
  
    #------------------------------------------------------------------------------
  # Window_Base Addon BEGINS
  #------------------------------------------------------------------------------

class Window_Base < Window
  
  def easy_bar(x,y,width,height,scolor,ecolor,c,m)
    
    if height >= 8
      #Draw fancy background
      self.contents.fill_rect(Rect.new(x,y,width,height),Color.new(0,0,0))
      self.contents.fill_rect(Rect.new(x+1,y+1,width-2,height-2),Color.new(255,255,255))
      self.contents.fill_rect(Rect.new(x+2,y+2,width-4,height-4),Color.new(128,128,128))
    elsif height >= 4
      #Draw simple background
      self.contents.fill_rect(Rect.new(x,y,width,height),Color.new(0,0,0))
    else
      #Draw shadow
      self.contents.fill_rect(Rect.new(x+3,y+2,width,height),Color.new(128,128,128))
    end
    
    
    if scolor == ecolor
      if height >= 8
        fill = c*(width-4)/m
        self.contents.fill_rect(Rect.new(x+2, y+2, fill, height-4), scolor)
      elsif height >= 4
        fill = c*(width-2)/m
        self.contents.fill_rect(Rect.new(x+1, y+1, fill, height-2), scolor)
      else
        fill = c*width/m
        self.contents.fill_rect(Rect.new(x,y,fill,height),scolor)
      end
    else
      if height >= 8
        fill = c*(width-4)/m
        difr = scolor.red - ecolor.red
        difg = scolor.green - ecolor.green
        difb = scolor.blue - ecolor.blue
        for i in 0...fill
          r = scolor.red - (difr/fill)*i
          g = scolor.green - (difg/fill)*i
          b = scolor.blue - (difb/fill)*i
          self.contents.fill_rect(Rect.new(x+i+2,y+2,1,height-4),Color.new(r,g,b))
        end
      elsif height >= 4
        fill = c*(width-2)/m
        difr = scolor.red - ecolor.red
        difg = scolor.green - ecolor.green
        difb = scolor.blue - ecolor.blue
        for i in 0...fill
          r = scolor.red - (difr/fill)*i
          g = scolor.green - (difg/fill)*i
          b = scolor.blue - (difb/fill)*i
          self.contents.fill_rect(Rect.new(x+i+1,y+1,1,height-2),Color.new(r,g,b))
        end
      else
        fill = c*width/m
        difr = scolor.red - ecolor.red
        difg = scolor.green - ecolor.green
        difb = scolor.blue - ecolor.blue
        for i in 0...fill
          r = scolor.red - (difr/fill)*i
          g = scolor.green - (difg/fill)*i
          b = scolor.blue - (difb/fill)*i
          self.contents.fill_rect(Rect.new(x+i,y,1,height),Color.new(r,g,b))
        end
      end
    end
  end
    
  def hp_bar(actor,x,y,width,height = 8)
    easy_bar(x,y,width,height,Color.new(255,120,0),Color.new(255,180,0),actor.hp,actor.maxhp)
  end
  
  def sp_bar(actor,x,y,width,height = 8)
    easy_bar(x,y,width,height,Color.new(50,0,200),Color.new(120,0,255),actor.sp,actor.maxsp)
  end
end

  #------------------------------------------------------------------------------
  # Window_Base Addon ENDS
  #------------------------------------------------------------------------------
  
  
    #------------------------------------------------------------------------------
  # Containers Class BEGINS
  #------------------------------------------------------------------------------

class Game_Containers
  attr_accessor :store
  def initialize
    @store = {}
  end
  def create(number=0, items=[], weapons=[], armors=[])
    @store[$game_map.map_id][number] = Game_Container.new(items, weapons, armors)
    $container = @store[$game_map.map_id][number]
    $scene = Scene_ContainerMenu.new
  end
  def load(number)
    $container = @store[$game_map.map_id][number]
    $scene = Scene_ContainerMenu.new
  end
end    

class Scene_Title
  alias jimmr_icre_command_new_game command_new_game
  def command_new_game
    $containers = Game_Containers.new
    jimmr_icre_command_new_game
    
  end
end

class Game_Map
  alias jimmr_icre_setup setup
  def setup(map_id)
    jimmr_icre_setup(map_id)
    if $containers.store[@map_id] == nil
    $containers.store[@map_id] = {}
    end
  end
end

  #------------------------------------------------------------------------------
  # Containers Class ENDS
  #------------------------------------------------------------------------------
  
  
    #------------------------------------------------------------------------------
  # Container Class BEGINS
  #------------------------------------------------------------------------------

class Game_Container
  attr_accessor :items, :weapons, :armors
  def initialize(items=[], weapons=[], armors=[])
    @items = items
    @weapons = weapons
    @armors = armors
  end
  
  def number(item)
    @item = item
    @number = 0
    case @item
    when RPG::Item
      self.items.each{|a|@number = a[1] if a[0] == @item.id}
    when RPG::Weapon
      self.weapons.each{|a|@number = a[1] if a[0] == @item.id}
    when RPG::Armor
      self.armors.each{|a|@number = a[1] if a[0] == @item.id}
    end
    return @number
  end
  
  def useable(item)
    @item = item
    case @item
    when RPG::Item
      @number = number(@item)
      return ((item.occasion == 0 or item.occasion == 2) && @number > 0)
    end
    false
  end
  
        
  
  def remove(item, number)
    @number = number
    @item = item
    case @item
    when RPG::Item
      self.items.each{|a|a[1] -= @number if a[0] == @item.id;self.items.delete(a) if a[1] == 0}
    when RPG::Weapon
      self.weapons.each{|a|a[1] -= @number if a[0] == @item.id;self.weapons.delete(a) if a[1] == 0}
    when RPG::Armor
      self.armors.each{|a|a[1] -= @number if a[0] == @item.id;self.armors.delete(a) if a[1] == 0}
    end
  end
  
  def add(item, number)
    @number = number
    @item = item
    @found = false
    case @item
    when RPG::Item
      self.items.each{|a|if a[0] == @item.id; a[1] += @number; @found =  true; end}
      self.items.push([@item.id,@number]) if @found == false
    when RPG::Weapon
      self.weapons.each{|a|if a[0] == @item.id; a[1] += @number; @found =  true; end}
      self.weapons.push([@item.id,@number]) if @found == false
    when RPG::Armor
      self.armors.each{|a|if a[0] == @item.id; a[1] += @number; @found =  true; end}
      self.armors.push([@item.id,@number]) if @found == false
    end
  end
  
  def toss(item,number)
    @item = item
    @cnumber = 0
    case @item
    when RPG::Item
      self.items.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [number,@cnumber].min
      remove(@item,@number)
    when RPG::Weapon
      self.weapons.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [number,@cnumber].min
      remove(@item,@number)
    when RPG::Armor
      self.armors.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [number,@cnumber].min
      remove(@item,@number)
    end
    return @cnumber
  end
  
  def to_party(item,number)
    @item = item
    @carry = [99 - $game_party.number(@item),MAX_ITEMS-$game_party.total_items].min
    return false if @carry == 0
    @tnumber = [number,@carry].min
    @cnumber = 0
    case @item
    when RPG::Item
      self.items.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      remove(@item,@number)
      $game_party.gain_item(@item.id,@number)
    when RPG::Weapon
      self.weapons.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      remove(@item,@number)
      $game_party.gain_weapon(@item.id,@number)
    when RPG::Armor
      self.armors.each{|a|@cnumber = a[1] if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      remove(@item,@number)
      $game_party.gain_armor(@item.id,@number)
    end
    return @cnumber
  end
  
  
    def from_party(item,number)
    @item = item
    @carry = $game_party.number(@item)
    @tnumber = [number,@carry].min
    @cnumber = 99
    case @item
    when RPG::Item
      self.items.each{|a|@cnumber = (99-a[1]) if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      add(@item,@number)
      $game_party.gain_item(@item.id,-@number)
    when RPG::Weapon
      self.weapons.each{|a|@cnumber = (99-a[1]) if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      add(@item,@number)
      $game_party.gain_weapon(@item.id,-@number)
    when RPG::Armor
      self.armors.each{|a|@cnumber = (99-a[1]) if a[0] == @item.id}
      @number = [@tnumber,@cnumber].min
      add(@item,@number)
      $game_party.gain_armor(@item.id,-@number)
    end
    return @carry
  end
  
end

  #------------------------------------------------------------------------------
  # Container Class ENDS
  #------------------------------------------------------------------------------
  
  #------------------------------------------------------------------------------
  # Selectable Window Addon BEGINS
  #------------------------------------------------------------------------------
  class Window_Selectable < Window_Base
    alias jimmr_lite_container_update update
    def update
      @index = [@index,@item_max-1].min
      jimmr_lite_container_update
    end
  end
  #--------------------------------------------------------------------------
  # End SDK Enabled Check
  #--------------------------------------------------------------------------
end


  class Scene_Save < Scene_File
    alias jimmr_lite_container_save_data write_save_data
    def write_save_data(file)
      jimmr_lite_container_save_data(file)
      Marshal.dump($containers, file) if $containers != nil
    end
  end
  class Scene_Load < Scene_File
    alias jimmr_lite_container_load_data read_save_data
    def read_save_data(file)
      jimmr_lite_container_load_data(file)
      $containers = Marshal.load(file)
    end
  end



Alright. The fruit of my work, so far. This "little snippet" of code will do the following:
  • The player can choose what items they want to take from containers.
  • The player can put items from their inventory into containers.
  • Why? Because there's an item limit.

But apart from that, the player can also:
  • Discard items both from the container and inventory.
  • Use items both from the container and inventory.

As an added plus, the map updates while in the menu, so decide quickly!
The only things you can easily change are purposely at the top.


Now, to call this baby...
Code:
$containers.create(ID,[[Item1,Number],[Item2,Number]], [[Weapon1,Number]], [[Armor1, Number]])

ID is the container's number. Each map has their own unique containers!
Yes, that means that you can't make "banks" (but you will be able to in the "non-Lite" version), but it also means that you won't have to keep track of how many containers are in all the other parts of the game.

Item1, Item2, Weapon1 & Armor1 are of course items in the database. For example, a potion would be 1.

Number is the number of that item you want in the container.

For example, if I want a container with 3 Potions, 1 High Potion, 1 Bronze Sword, 2 Mithril Spears, and a Bronze Shield, I'd use this call script:
Code:
$containers.create(ID,[[1,3],[2,1]],[[1,1],[8,2]],[[1,1]])

Another example, creating a container with 5 high potions and 2 high perfumes, but nothing else:
Code:
$containers.create(ID,[[2,5],[5,2]], [], [])

Now what's the ID for? Well, if you just go ahead and create a new container every time the player runs an event, the items would never end. Therefore, make use of local switches, and on the following page use this call script instead:
Code:
$containers.load(ID)


Remember, each map has its own unique container ID's.

Now, if you have a legal version of RMXP and use the SDK, there's nothing else to do.
If you use Postality Knights Edition, you need to search for all instances of "$defaultfont" and remove the comments on those lines.
If you don't use the SDK, put comments in front of the two first and the very last line of code.

That's all really. There should be no need for a demo, but here are some screenies!
Screenies!


Have fun!

~Jimmie
}




Users browsing this thread: