Requesting gold withdrawal feature for IMP1's Storage Box script

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Hi, I'm using this storage box script by IMP1 for loot boxes, chests, looting the slain enemies, etc. Its a fantastic script which does a fantastic job, however, it lacks a little feature for me. Could please someone make that it will 'spawn' gold too, for players to loot from them. I don't want them to store gold there, just to loot. Of course, I will determine how much gold will spawn in them, just please someone make that feature into the script, or an addon.

Link to script
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
And how would the script know, if the player interacts with the object, whether they are trying to store something, or trying to loot?
 

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
The script currently looks like this: on the left side of the screen, is your inventory, on the right is the spawned items. The gold will behave like an 'item' in the storage box. If the player selects it and presses the action button, it will disappear from the storage box and increases the players gold for the amount. Lets say I put 50 gold into the storage box as a developer. The player open the 'drawer' (see the link of the picture), on the right side among other items will be an 'item'. which will only say 50 gold. If the player wants it, it weill disappear from there, but the player will have 50 more gold.

Picture of the storage screen
 

vFoggy

Veteran
Veteran
Joined
Nov 3, 2012
Messages
71
Reaction score
31
Primarily Uses
I wrote a script for the gold withdrawal that you need
Code:
# ==============================================================================
# This is an addon script for Storage Boxes v1.8 by IMP1
# Gives the ability to add gold to the boxes and (only) withdraw them.
# Gold is counted as one item in the box (meaning that 900 G will take 1/20 space)
# To add gold to a box use :gold as the item to be added, for example:
#   $game_boxes.box(2)[:gold] = 900   or
#   $game_boxes.add_item(:gold, 5, 3, :all)
# -------------------
# Script by: vFoggy
# ==============================================================================

module IMP1_Storage_Boxes
  # Sound played when gold is withdrawn
  GOLD_WITHDRAW_SOUND = {
    name: "Coin",
    volume: 100,
    pitch: 100
  }
 
  # Icon displayed for gold
  GOLD_ICON = 262
 
  # Help text displayed when on cursor is on gold (in boxes only)
  GOLD_ITEM_DESCRIPTION = "Used to buy items."
end

class Window_Base < Window
  alias fog_din_game_boxes draw_item_name
  def draw_item_name(item, x, y, enabled = true, width = 172)
    return unless item
    if item != :gold
      fog_din_game_boxes(item, x, y, enabled, width)
    else
      draw_icon(IMP1_Storage_Boxes::GOLD_ICON, x, y, enabled)
      change_color(normal_color, enabled)
      draw_text(x + 24, y, width, line_height, "Gold")
    end
  end
end

class Window_Help < Window_Base
  alias fog_si set_item
  def set_item(item)
    if item != :gold
      fog_si(item)
      return
    end
    set_text(item ? IMP1_Storage_Boxes::GOLD_ITEM_DESCRIPTION : "")
  end
end

class IMP1_Game_Boxes
  include IMP1_Storage_Boxes
 
  def fullness(box_id)
    i = 0
    box(box_id).each do |item, amount|
      if item == :gold
        i += 1
      else
        i += amount
      end
    end
    return i
  end
end

class Scene_ItemStorage < Scene_MenuBase
  alias fog_mi move_item
  def move_item
    item = @box_window.item
    if item != :gold
      fog_mi
      return
    end
    withdrawn = deposited = false
    if @box_window.active && can_move_item_to_inventory?(@box_window.item)
      all_gold = $game_boxes.item_number(:gold, @box_id)
      $game_boxes.remove_item(item, all_gold, @box_id)
      $game_party.gain_gold(all_gold)
      play_withdraw_sound(item)
      withdrawn = true
    end
    if !withdrawn
      Sound.play_buzzer
    end
    refresh
  end
 
  def play_withdraw_sound(item)
    se = IMP1_Storage_Boxes::WITHDRAW_SOUND
    if item == :gold
      se = IMP1_Storage_Boxes::GOLD_WITHDRAW_SOUND.dup
    elsif item.note.include?("<withdraw sound:")
      se = se.dup
      se[:name] = item.note.scan(/<withdraw sound: (.+)>/).flatten[0]
    end
    play_sound(se)
  end
end
 

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
WOW, vFoggy, you're awesome, it looks and works just like I wanted. I will be sure to give you credits.

Edit:
When used by the Item Sizes addon created by IMP1, it gives this error:

Script 'IMP1 item size' line 74: NoMethodError occured.
undefined method 'inv_size' for :gold:Symbol

it gives this error when I want to withdraw the gold from the box (select it a press the Enter key).
Could this be fixed?

Link to Item Sizes Addon
 
Last edited:

vFoggy

Veteran
Veteran
Joined
Nov 3, 2012
Messages
71
Reaction score
31
Primarily Uses
Had to edit IMP1's addon script. Replace it with the script below:
Code:
#==============================================================================
# Storage Boxes Addon: Item Sizes
#   by IMP1
#------------------------------------------------------------------------------
# THIS SCRIPT REQUIRES THE 'STORAGE BOXES' SCRIPT BY IMP1
#------------------------------------------------------------------------------
#   Compatability:
#
# Aliased Methods:
#   IMP1_Game_Boxes.fullness
#   IMP1_Game_Boxes.space_for
#   Scene_ItemStorage.can_move_item_to_inventory?
#   Window_BoxTitle.refresh
#
# New Methods/Fields:
#   Window_BoxTitle.draw_inventory_amount
#
# Overwritten Methods:
#   none.
#
#------------------------------------------------------------------------------
#   Version History:
# by vFoggy
# v1.4 [2017/10/05] : Added compatibility for gold withdrawal addon.
#
# by IMP1
# v1.3 [2015/06/27] : Use updates to base script.
# v1.2 [2014/11/16] : Fixed bug where inventory limit would not update.
# v1.1 [2014/11/15] : Added and displays the player inventory limit.
# v1.0 [2014/11/14] : Initial release.
#==============================================================================

#==============================================================================
# Game_Boxes
#==============================================================================
class IMP1_Game_Boxes
  #--------------------------------------------------------------------------
  # Returns the space in a box.
  #--------------------------------------------------------------------------
  # Changes:
  #   * Added condition, if item is :gold only 1 is added to the total size.
  #--------------------------------------------------------------------------
  alias :default_size_fullness :fullness unless $@
  def fullness(box_id)
    if $imported[:Theo_LimInventory]
      i = 0
      box(box_id).each do |item, amount|
        if item == :gold
          i += 1
        else
          i += item.inv_size * amount
        end
      end
      return i
    else
      return default_size_fullness(box_id)
    end
  end
  #--------------------------------------------------------------------------
  # Returns true if there is enough room for multiple items.
  #--------------------------------------------------------------------------
  # Changes:
  #   * Added condition, if the item is :gold the amount is set to 1 (gold
  #     counted as 1 in boxes).
  #--------------------------------------------------------------------------
  alias :default_size_space :space_for unless $@
  def space_for(item, amount, box)
    if $imported[:Theo_LimInventory]
      if item == :gold
        amount = 1
      else
        amount *= item.inv_size
      end
    end
    return default_size_space(item, amount, box)
  end
 
end # IMP1_Game_Boxes

#==============================================================================
# Scene_ItemStorage
#==============================================================================
class Scene_ItemStorage
  #--------------------------------------------------------------------------
  # Returns true if there is enough room in the player's inventory.
  #--------------------------------------------------------------------------
  # Changes (For gold withdrawal addon):
  #   * Added variable item_size that stores the size of the item. If it is
  #     :gold its size is set 0.
  #--------------------------------------------------------------------------
  alias :default_can_move? :can_move_item_to_inventory? unless $@
  def can_move_item_to_inventory?(item)
    return false if !default_can_move?(item)
    space_in_inventory = true
    if $imported[:Theo_LimInventory]
      item_size = item == :gold ? 0 : item.inv_size
      space_in_inventory =
          $game_party.total_inv_size + item_size < $game_party.inv_max
    end
    return space_in_inventory
  end
 
end # Scene_ItemStorage

#==============================================================================
# Window_BoxTitle
#==============================================================================
class Window_BoxTitle
  #--------------------------------------------------------------------------
  # Draws the contents.
  #--------------------------------------------------------------------------
  alias :non_limited_inventory_refresh :refresh unless $@
  def refresh(*args)
    non_limited_inventory_refresh(*args)
    if is_inventory_title?
      draw_inventory_amount
    end
  end
  #--------------------------------------------------------------------------
  # Displays how full the inventory is.
  #--------------------------------------------------------------------------
  def draw_inventory_amount
    if $imported[:Theo_LimInventory]
      text = "#{$game_party.total_inv_size}/#{$game_party.inv_max}"
      draw_text(0, 0, (Graphics.width/2)-32, line_height, text, 2)
    end
  end
 
end # Window_BoxTitle
 

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Yes, it works now as intended, thank you again vFoggy, you're awesome. I will be sure to credit you.
 

Harosata

Dramatic Lightning's BFF
Veteran
Joined
Aug 20, 2015
Messages
246
Reaction score
70
First Language
English
Primarily Uses
RMVXA
Just came from working on his gold scripts from another topic. I figured I'd post here because he wants to alter the gold in Foggy's gold withdrawal script (or IMP's Storage Box). As his gold is now in Gold/Silver/Copper standards, it seems his goal for the gold is to display gold in the box like:
Gold: 12
Silver: 1
Copper: 19

instead of
Gold: 120119 (or 12g1s19c)

---

For now, here's a small addon to show the GSC gold in one line, just in case none of us manage to split gold up to three times.

Code:
#Addon: Convert Gold to GSC standard
class Window_ItemStorageRight  < Window_ItemList
  def draw_item_name(item, x, y, enabled = true, width = 172)
    return unless item
    if item != :gold
      draw_icon(item.icon_index, x, y, enabled)
      change_color(normal_color, enabled)
      draw_text(x + 24, y, width, line_height, item.name)
    end
  end
 
  def draw_item_number(rect, item)
    if item != :gold
      draw_text(rect, sprintf(":%2d", $game_boxes.item_number(item, @box_id)), 2)
    else
      draw_currency_value($game_boxes.item_number(item, @box_id), "", rect.x, rect.y, rect.width)
    end
  end
end
 

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
There's a small issue with this change, Harosata, as this removes the color coding from the names of items if they had one. Like if someone wants to use Vlue's randomization script, the generated item names will all be white, not colored.

Link to Vlue Randomization


EDIT: I managed to fix it myself by commenting out a few lines, where it changes the colors (lines 2-10)


EDIT 2 : I found a little bug with this addon: When your inventory is full, you cannot take gold from the storage. Could this be fixed?
 
Last edited:

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
I found a little bug with this addon: When your inventory is full, you cannot take gold from the storage. Could this be fixed?
 

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Anyone willing to help me fix the gold bug?
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
Haven't tested it, but you could try to add this below IMP1's scripts:

Code:
# ---------------------------------------------------------------------------
# Scene_ItemStorage *Modified*
#   Fix for gold withdrawal / item pickup with limited inventory size
# ---------------------------------------------------------------------------
class Scene_ItemStorage

  # Modified Method from IMP1's "Item Sizes" script
  # (including vFoggy's gold withdrawal)
  # - Gold should no longer regard inventory size at all
  # - Picking up an item may completely fill inventory
  def can_move_item_to_inventory?(item)
    return false unless default_can_move?(item)
    return true  unless $imported[:Theo_LimInventory]
    return true  if item == :gold
    return $game_party.total_inv_size + item.inv_size <= $game_party.inv_max
  end
end
 
Last edited:

tomkomaster

Veteran
Veteran
Joined
Sep 19, 2015
Messages
151
Reaction score
8
First Language
English
Primarily Uses
RMVXA
Wow, again, Another Fen, you're awesome. This works.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top