RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

drop item and bank limit script

Started by Djeff, October 19, 2009, 06:18:53 PM

0 Members and 1 Guest are viewing this topic.

Djeff

can anyone make me a drop item script and a bank item limit script ?
I am using the item limit and the item storage scripts of game_guy.
It should be nice if someone can make a drop item script : a edit in the menu so you can use or drop an item or something.
and if someone can edit this script from geme_guy so you can set item limits for the bank accounts.

[spoiler]
=begin
Item Storage Script
Author: game_guy
Date: May 1st, 2009

Introduction:
If you've ever played any of the Elder Scrolls series or Fallout series than of
course then you would have noticed the awesome item storage. This script does that

Features:

  • Store Items in Chests, Closets, etc.
  • Have seperate closets and chests
  • Easy to use
Instructions:
Use a simple script call to open the chest.
$scene = Scene_Chest.new(x)
x = the variable id that you want the chest or closet to store items and stuff in

thats all give proper credit.
=end
class Scene_Title
  alias re_main_link command_new_game
  def command_new_game
    $chest = Game_Chest.new
    re_main_link
  end
end
class Window_Chest_Item < Window_Selectable
  def initialize
    super(320, 64, 320, 416)
    @column_max = 1
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  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 $chest.item_number(i) > 0
        @data.push($data_items)
      end
    end
    unless $game_temp.in_battle
      for i in 1...$data_weapons.size
        if $chest.weapon_number(i) > 0
          @data.push($data_weapons)
        end
      end
      for i in 1...$data_armors.size
        if $chest.armor_number(i) > 0
          @data.push($data_armors)
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      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]
    case item
    when RPG::Item
      number = $chest.item_number(item.id)
    when RPG::Weapon
      number = $chest.weapon_number(item.id)
    when RPG::Armor
      number = $chest.armor_number(item.id)
    end
    x = 4 + index % @column_max * (288 + 32)
    y = index / @column_max * 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
end
class Window_Party_Item < Window_Selectable
  def initialize
    super(0, 64, 320, 416)
    @column_max = 1
    refresh
    self.index = 0
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  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)
      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)
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors)
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      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]
    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
    x = 4 + index % @column_max * (288 + 32)
    y = index / @column_max * 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
end
class Window_Chest_Choices < Window_Selectable
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 3
    @column_max = 3
    @commands = ["Store Items", "Take Items", "Exit"]
    self.z = 200
    refresh
    self.index = 0
  end
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  def draw_item(index)
    x = 4 + index * 215
    self.contents.draw_text(x, 0, 128, 32, @commands[index])
  end
end
class Game_Chest
  attr_reader   :actors                   # actors
  def initialize
    @actors = []
    @items = {}
    @weapons = {}
    @armors = {}
  end
  def refresh
    new_actors = []
    for i in 0...@actors.size
      if $data_actors[@actors.id] != nil
        new_actors.push($game_actors[@actors.id])
      end
    end
    @actors = new_actors
  end
  def item_number(item_id)
    return @items.include?(item_id) ? @items[item_id] : 0
  end
  def weapon_number(weapon_id)
    return @weapons.include?(weapon_id) ? @weapons[weapon_id] : 0
  end
  def armor_number(armor_id)
    return @armors.include?(armor_id) ? @armors[armor_id] : 0
  end
  def gain_item(item_id, n)
    if item_id > 0
      @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
    end
  end
  def gain_weapon(weapon_id, n)
    if weapon_id > 0
      @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
    end
  end
  def gain_armor(armor_id, n)
    if armor_id > 0
      @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
    end
  end
  def lose_item(item_id, n)
    gain_item(item_id, -n)
  end
  def lose_weapon(weapon_id, n)
    gain_weapon(weapon_id, -n)
  end
  def lose_armor(armor_id, n)
    gain_armor(armor_id, -n)
  end
  def item_can_use?(item_id)
    if item_number(item_id) == 0
      return false
    end
    occasion = $data_items[item_id].occasion
    if $game_temp.in_battle
      return (occasion == 0 or occasion == 1)
    end
    return (occasion == 0 or occasion == 2)
  end
end
class Scene_Chest
  def initialize(variable)
    @variable_id = variable
  end
  def main
    if $game_variables[@variable_id] != 0
      $chest = $game_variables[@variable_id]
    else
      $chest = Game_Chest.new
    end
    @help_window = Window_Help.new
    @help_window.visible = false
    @item_window = Window_Party_Item.new
    @chest_window = Window_Chest_Item.new
    @command_window = Window_Chest_Choices.new
    @item_window.help_window = @help_window
    @chest_window.help_window = @help_window
    @chest_window.active = false
    @item_window.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
    @chest_window.dispose
    @command_window.dispose
  end
  def update
    @help_window.update
    @item_window.update
    @chest_window.update
    @chest_window.refresh
    @item_window.refresh
    @command_window.update
    if @command_window.active
      update_command
      return
    end
    if @item_window.active
      update_item
      return
    end
    if @chest_window.active
      update_chest
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $game_variables[@variable_id] = $chest
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0  # buy
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @item_window.active = true
        @item_window.visible = true
        @help_window.visible = true
        @help_window.z = 2000
      when 1  # sell
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @chest_window.active = true
        @chest_window.visible = true
        @chest_window.refresh
        @help_window.visible = true
        @help_window.z = 2000
      when 2  # quit
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Map.new
      end
      return
    end
  end
  def update_item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @item_window.active = false
      @help_window.z = 0
      return
    end
    if Input.trigger?(Input::C)
      @item = @item_window.item
      case @item
      when RPG::Item
        $game_party.lose_item(@item.id, 1)
        $chest.gain_item(@item.id, 1)
      when RPG::Weapon
        $game_party.lose_weapon(@item.id, 1)
        $chest.gain_weapon(@item.id, 1)
      when RPG::Armor
        $game_party.lose_armor(@item.id, 1)
        $chest.gain_armor(@item.id, 1)
      end
    end
  end
  def update_chest
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @chest_window.active = false
      @help_window.z = 0
      return
    end
    if Input.trigger?(Input::C)
      @item = @chest_window.item
      case @item
      when RPG::Item
        $game_party.gain_item(@item.id, 1)
        $chest.lose_item(@item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(@item.id, 1)
        $chest.lose_weapon(@item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(@item.id, 1)
        $chest.lose_armor(@item.id, 1)
      end
    end
  end 
end
class Scene_Save < Scene_File
  def write_save_data(file)
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors
      characters.push([actor.character_name, actor.character_hue])
    end
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1
    $game_system.magic_number = $data_system.magic_number
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
    Marshal.dump($chest, file)
  end
end
class Scene_Load < Scene_File
  def read_save_data(file)
    characters = Marshal.load(file)
    Graphics.frame_count = Marshal.load(file)
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    $chest              = Marshal.load(file)
    if $game_system.magic_number != $data_system.magic_number
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    $game_party.refresh
  end
end
[/spoiler]
I guess the elements are all mine ! -> Working on Element Island < -