Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Realistic Shop

MeisMe's Realistic Shop
Changing the shop face FOREVER


Introduction
A while ago, I wanted a shop with taxes, discounts, even a shopping cart. Well, now I can and so can you!

Instructions
Nothing could be simpler! Just copy and paste the whole script into a new section above 'Main'. Edit the @tax variable to the tax rate that YOU want for your game. When a time comes where a shop has a discount, or a different ate at which it buys or sells goods, just use the 'Script...' function and change them.
EG. $game_temp.buy_rate = 110 # Shop sells you goods at 110% of the database price.
When you are ready to make your purchase, press RIGHT, and select 'Finalize Purchase'. if you cannot afford the selected goods, select 'No' or hit ESC.


Code:
#==============================================================================
#  ** MeisMe's Realistic Shop
#------------------------------------------------------------------------------
#  Created by MeisMe
#  Buxfix by Daniel
#  August 8, 2006
#  Version 2
#==============================================================================


class Game_Temp
  attr_accessor :buy_rate
  attr_accessor :sell_rate
  attr_accessor :discount
  attr_accessor :tax
  attr_accessor :cart_item
  attr_accessor :cart_weapon
  attr_accessor :cart_armor
  attr_accessor :shop_type
  alias mim_shop_old_initialize initialize
  def initialize
    mim_shop_old_initialize
    @buy_rate = 100
    @sell_rate = 50
    @discount = 0
    @tax = 7
    clear_cart
    @shop_type = 0
  end
  def clear_cart
    @cart_item = {}
    @cart_weapon = {}
    @cart_armor = {}
  end
  def cart_cleared?
    if (@cart_item == {} && @cart_weapon == {} && @cart_armor == {})
      return true
    end
    return false
  end
  def item_number(item_id)
    return @cart_item.include?(item_id) ? @cart_item[item_id] : 0
  end
  def weapon_number(weapon_id)
    return @cart_weapon.include?(weapon_id) ? @cart_weapon[weapon_id] : 0
  end
  def armor_number(armor_id)
    return @cart_armor.include?(armor_id) ? @cart_armor[armor_id] : 0
  end
  def gain_item(item_id, n)
    if item_id > 0
      @cart_item[item_id] = [[item_number(item_id) + n, 0].max, 99].min
    end
  end
  def gain_weapon(weapon_id, n)
    if weapon_id > 0
      @cart_weapon[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
    end
  end
  def gain_armor(armor_id, n)
    if armor_id > 0
      @cart_armor[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
    end
  end
  def gain_items
    for i in 1..$data_items.size
      if item_number(i) > 0
        $game_party.gain_item(i, item_number(i))
      end
    end
    for i in 1..$data_weapons.size
      if weapon_number(i) > 0
        $game_party.gain_weapon(i, weapon_number(i))
      end
    end
    for i in 1..$data_armors.size
      if armor_number(i) > 0
        $game_party.gain_armor(i, armor_number(i))
      end
    end
  end
end
#==============================================================================
class Window_ShopCommand < Window_Selectable
  def initialize
    super(0, 64, 480, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item_max = 3
    @column_max = 3
    @commands = ["Buy", "Sell", "Exit"]
    refresh
    self.index = 0
  end
  def refresh
    self.contents.clear
    if $game_temp.shop_type == 0
      for i in 0...@item_max
      draw_item(i)
      end
    end
    if $game_temp.shop_type == 1
      self.contents.draw_text(4, 0, 324, 32, "You can only buy at this shop.")
      self.index = -1
      update_cursor_rect
    end
    if $game_temp.shop_type == 2
      self.contents.draw_text(4, 0, 324, 32, "You can only sell at this shop.")
      self.index = -1
      update_cursor_rect
    end
  end
  def draw_item(index)
    x = 4 + index * 160
    self.contents.draw_text(x, 0, 128, 32, @commands[index])
  end
  def update_cursor_rect
    if $game_temp.shop_type == 0
      super
    end
    if $game_temp.shop_type == 1 || $game_temp.shop_type == 2
      self.cursor_rect.empty
    end
  end
end
#==============================================================================
class Window_ShopBuyBG < Window_Base
  def initialize
    super(0, 128, 320, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 128, 32, 'Item Name')
    self.contents.draw_text(4, 0, 284, 32, 'Marked Price', 2)
  end
end
#==============================================================================
class Window_ShopBuy < Window_Selectable
  def initialize(shop_goods)
    super(0, 160, 320, 320)
    @shop_goods = shop_goods
    refresh
    self.index = 0
    self.opacity = 0
  end
  def item
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for goods_item in @shop_goods
      case goods_item[0]
      when 0
        item = $data_items[goods_item[1]]
      when 1
        item = $data_weapons[goods_item[1]]
      when 2
        item = $data_armors[goods_item[1]]
      end
      if item != nil
        @data.push(item)
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @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) +
        $game_temp.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id) +
        $game_temp.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id) +
        $game_temp.armor_number(item.id)
    end
    price = [[item.price * $game_temp.buy_rate / 100, 9999999].min, 0].max
    if number >= 99
      self.contents.font.color = disabled_color
    else
      self.contents.font.color = normal_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 + 192, y, 88, 32, price.to_s, 2)
  end
end
#==============================================================================
class Window_ShopNumber < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 128, 320, 352)
    self.contents = Bitmap.new(width - 32, height - 32)
    @item = nil
    @max = 1
    @price = 0
    @number = 1
  end
  #--------------------------------------------------------------------------
  # * Set Items, Max Quantity, and Price
  #--------------------------------------------------------------------------
  def set(item, max, price)
    @item = item
    @max = max
    @price = price
    @number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # * Set Inputted Quantity
  #--------------------------------------------------------------------------
  def number
    return @number
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_item_name(@item, 4, 96)
    self.contents.font.color = normal_color
    self.contents.draw_text(236, 96, 32, 32, "Ãâ€â€
 
Fixed an error on my behalf. I forgot to refresh the gold window after you purchase your goods. I urge everyone to re-paste the script into their project.
 
Double post, I know. However, I fixed another bug in which the weapons purchased would not be added to the inventory. Once again, please re-past the script into your game. Hopefully this is the last one :)
 
The final version is now out, which means I fixed the glitches, and made it so you can remove exact items from the cart.

Enjoy :)
 
Good Job Meisme

1) Why did you add all of those new methods to Game_Temp they would have fit better in Scene_Shop ;)

but other than that the script is coded pretty well
 
I like the whole checkout thing....its a pretty awesome idea, but im not sure I like the taxes, It just doesnt seem right for an rpg in my game. But nonetheless, this is an awesome script! Well done.
 
A very nice script... I'm not sure on how taxes fit into the 17th century of Japan's history, but I'll find that out ^_^

A suggestion would be to set the cart window active by pressing A, not the right key... I did that and it works nice, I didn't like the way you handled it... I don't know how this is going to work in 'normal' games compared to mine, which uses A/Shift in nearly every menu window ^_^

Congrats on that script, I'll definately use this, with crediting myself only for the edits :P j/k
 
You can change all the values of the shop: the buy/sell rate, the discount and the tax.
Code:
$game_temp.buy_rate = 100 # How much the shop charges per item
$game_temp.sell_rate = 50 # How uch the shop will give you for an item
$game_temp.discount = 0 # The discount rate, subtracted after the goods are added up
$game_temp.tax = 7 # The tax rate, added after the discount has been subtracted
$game_temp.shop_type # 0=Buy/sell 1=Buy only 2=Sell only
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top