[XP] Scene_Shop Item Counter

Started by Wecoc, January 11, 2013, 03:45:05 pm

Previous topic - Next topic

Wecoc

January 11, 2013, 03:45:05 pm Last Edit: July 11, 2021, 12:28:30 pm by Wecoc
Scene_Shop Item Counter
Authors: Wecoc
Version: 1.0
Type: Shop AddOn
Key Term: Custom Shop System

Introduction

With that easy script, you will be able to control how many items you will buy (or sell), without going to a counter window.
The new multiplier number shown on the same window as the items list, will be managed now with -> and <-

Features

  • Works on Buy Window and Sell Window
  • Price string is multiplied automatically.

Screenshots

Spoiler: ShowHide




Demo

Nope for this type of script.

Script

Spoiler: ShowHide

#==============================================================================
# ** [XP] Castlevania Shop Item Counter v 1.1
#------------------------------------------------------------------------------
# Autor: Wecoc (no requiere créditos)
#==============================================================================

#==============================================================================
# ** Window_ShopBuy
#==============================================================================

class Window_ShopBuy < Window_Selectable
  #--------------------------------------------------------------------------
  attr_accessor :shop_multipliers
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias castle_multi_ini initialize unless $@
  def initialize(shop_goods)
    @shop_multipliers = Array.new(shop_goods.size, 1)
    castle_multi_ini(shop_goods)
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    multi = @shop_multipliers[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
    price = item.price * multi
    if price <= $game_party.gold and number < 99
      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 - 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 + 160, y, 88, 32, multi.to_s, 2)
    self.contents.draw_text(x + 240, y, 88, 32, price.to_s, 2)
  end
end

#==============================================================================
# ** Scene_Shop
#==============================================================================

class Scene_Shop
  #--------------------------------------------------------------------------
  # * Frame Update (when buy window is active)
  #--------------------------------------------------------------------------
  def update_buy
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.active = true
      @dummy_window.visible = true
      @buy_window.active = false
      @buy_window.visible = false
      @status_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
      return
    end
    if Input.repeat?(Input::RIGHT)
      item = @buy_window.item
      return if item == nil
      multi = @buy_window.shop_multipliers[@buy_window.index]
      return if multi == 99 or item.price * (multi + 1) > $game_party.gold
      $game_system.se_play($data_system.cursor_se)
      @buy_window.shop_multipliers[@buy_window.index] += 1
      @buy_window.draw_item(@buy_window.index)
    end
    if Input.repeat?(Input::LEFT)
      item = @buy_window.item
      return if item == nil
      multi = @buy_window.shop_multipliers[@buy_window.index]
      return if multi == 1
      $game_system.se_play($data_system.cursor_se)
      @buy_window.shop_multipliers[@buy_window.index] -= 1
      @buy_window.draw_item(@buy_window.index)
    end
    if Input.trigger?(Input::C)
      @item = @buy_window.item
      if @item == nil
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      multi = @buy_window.shop_multipliers[@buy_window.index]
      price = @item.price * multi
      if price > $game_party.gold
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      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 number == 99
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.shop_se)
      $game_party.lose_gold(price)
      case @item
      when RPG::Item
        $game_party.gain_item(@item.id, multi)
      when RPG::Weapon
        $game_party.gain_weapon(@item.id, multi)
      when RPG::Armor
        $game_party.gain_armor(@item.id, multi)
      end
      @buy_window.shop_multipliers[@buy_window.index] = 1
      @gold_window.refresh
      @buy_window.refresh
      @status_window.refresh
    end
  end
end


Instructions

Just post above main.

Compatibility

Probably it will not fit well with custom shop systems.

Credits and Thanks

  • Wecoc

Author's Notes

Please report any bugs/issues.