ร้านค้าสำหรับซื้อของหรือขายของ?แยกต่างหาก - Muge9thD -  07-08-2012
 
 
ร้านค้าสำหรับซื้อของหรือขายของ?แยกต่างหาก 
 
สคริปต์เขียนโดย : Mystic Phoenix 
ลิงค์ต้นฉบับ : http://www.irpgth.com/community/School/2035-Script-...%81 
 
 
รายละเอียด : 
มันคือสคริปต์เมนูสำหรับขายของ หรือซื้อของอย่างเดียว ซึ่งไม่ใช่สคริปแปลกใหม่อะไรหรอกครับ เป็นสคริปต์ที่ดัดแปลงจาก  
Scene_Shop ของเรานี่แหล่ะ 
สกรีนช๊อต : 
 
 
วิธีการใช้งาน :  
1.ถ้าต้องการเรียกเมนูขายของ เวลาจะเรียกก็เรียกสคริปต์ $scene = Scene_ShopSell.new 
 
2.ถ้าต้องการเรียกเมนูซื้อของ ไม่ต้องไปเรียกสคริป $scene = อะไรนะครับ ใช้ร่วมกับคำสั่งเรียกร้านขายของเลย  
ใช้เหมือนเดิมเหมือนอันเก่าทุกประการ 
 
 
โค๊ดสคริปต์ 
สำหรับร้านที่ใช้ ขายไอเทม 
Code: #============================================================================== 
# * Window_ShopCommand 
#------------------------------------------------------------------------------ 
# ?In the shop picture, it is the window which selects business matter. 
#============================================================================== 
 
class Window_ShopSellCommand < Window_Selectable 
  #-------------------------------------------------------------------------- 
  # - Object initialization 
  #-------------------------------------------------------------------------- 
  def initialize 
    super(0, 64, 480, 64) 
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.contents.font.name = $fontface 
    self.contents.font.size = $fontsize 
    @item_max = 2 
    @column_max = 2 
    @commands = ["Sell", "Cancel"] 
    refresh 
    self.index = 0 
  end 
  #-------------------------------------------------------------------------- 
  # - Refreshment 
  #-------------------------------------------------------------------------- 
  def refresh 
    self.contents.clear 
    for i in 0...@item_max 
      draw_item(i) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - Drawing of item 
  #     index : Item number 
  #-------------------------------------------------------------------------- 
  def draw_item(index) 
    x = 4 + index * 240 
    self.contents.draw_text(x, 0, 128, 32, @commands[index]) 
  end 
end 
 
 
#============================================================================== 
# * Scene_Shop 
#------------------------------------------------------------------------------ 
# ?It is the class which processes the shop picture. 
#============================================================================== 
 
class Scene_ShopSell 
  #-------------------------------------------------------------------------- 
  # - Main processing 
  #-------------------------------------------------------------------------- 
  def main 
      # Drawing up the help window 
    @help_window = Window_Help.new 
    # Drawing up the command window 
    @command_window = Window_ShopSellCommand.new 
    # Drawing up the Goldwyn dough 
    @gold_window = Window_Gold.new 
    @gold_window.x = 480 
    @gold_window.y = 64 
    # Drawing up the dummy window 
    @dummy_window = Window_Base.new(0, 128, 640, 352) 
    # Drawing up the sale window 
    @sell_window = Window_ShopSell.new 
    @sell_window.active = false 
    @sell_window.visible = false 
    @sell_window.help_window = @help_window 
    # Drawing up the quantity input window 
    @number_window = Window_ShopNumber.new 
    @number_window.active = false 
    @number_window.visible = false 
    # Drawing up the status window 
    @status_window = Window_ShopStatus.new 
    @status_window.visible = false 
    # Transition execution 
    Graphics.transition 
    # Main loop 
    loop do 
      # Renewing the game picture 
      Graphics.update 
      # Updating the information of input 
      Input.update 
      # Frame renewal 
      update 
      # When the picture changes, discontinuing the loop 
      if $scene != self 
        break 
      end 
    end 
    # Transition preparation 
    Graphics.freeze 
    # Releasing the window 
    @help_window.dispose 
    @command_window.dispose 
    @gold_window.dispose 
    @dummy_window.dispose 
    @sell_window.dispose 
        @number_window.dispose 
    @status_window.dispose 
  end 
  #-------------------------------------------------------------------------- 
  # - Frame renewal 
  #-------------------------------------------------------------------------- 
  def update 
    # Renewing the window 
    @help_window.update 
    @command_window.update 
    @gold_window.update 
    @dummy_window.update 
    @sell_window.update 
    @number_window.update 
    @status_window.update 
    # When the command window is active,: Update_command is called 
    if @command_window.active 
      update_command 
      return 
    end 
    # When the purchase window is active,: Update_sell is called 
    if @sell_window.active 
      update_sell 
      return 
    end 
    # When the quantity input window is active,: Update_number is called 
    if @number_window.active 
      update_number 
      return 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - When frame renewal (the command window is active) 
  #-------------------------------------------------------------------------- 
  def update_command 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # Change to map picture 
      $scene = Scene_Map.new 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # It diverges at cursor position of the command window 
      case @command_window.index 
      when 0  # It sells 
        # Performing decision SE 
        $game_system.se_play($data_system.decision_se) 
        # State of window to sale mode 
        @command_window.active = false 
        @dummy_window.visible = false 
        @sell_window.active = true 
        @sell_window.visible = true 
        @sell_window.refresh 
      when 1  # It stops 
        # Performing decision SE 
        $game_system.se_play($data_system.decision_se) 
        # Change to map picture 
        $scene = Scene_Map.new 
      end 
      return 
    end 
  end 
#-------------------------------------------------------------------------- 
  # - When frame renewal (the sale window is active) 
  #-------------------------------------------------------------------------- 
  def update_sell 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # State of window to early mode 
      @command_window.active = true 
      @dummy_window.visible = true 
      @sell_window.active = false 
      @sell_window.visible = false 
      @status_window.item = nil 
      # Eliminating the help text 
      @help_window.set_text("") 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # Acquiring the item 
      @item = @sell_window.item 
      # Setting the item of the status window 
      @status_window.item = @item 
      # When the item is invalid, or when price 0 (sale failure) is 
      if @item == nil or @item.price == 0 
        # Performing buzzer SE 
        $game_system.se_play($data_system.buzzer_se) 
        return 
      end 
      # Performing decision SE 
      $game_system.se_play($data_system.decision_se) 
      # Acquiring the frequency of possession of the item 
      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 
      # The frequency of possession of largest sale quantity = item 
      max = number 
      # State of window to quantity input mode 
      @sell_window.active = false 
      @sell_window.visible = false 
      @number_window.set(@item, max, @item.price / 2) 
      @number_window.active = true 
      @number_window.visible = true 
      @status_window.visible = true 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - When frame renewal (the quantity input window is active) 
  #-------------------------------------------------------------------------- 
  def update_number 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # Non setting the quantity input window to active invisibility 
      @number_window.active = false 
      @number_window.visible = false 
      # It diverges at cursor position of the command window 
      case @command_window.index 
      when 0  # It sell 
        # State of window to sale mode 
        @sell_window.active = true 
        @sell_window.visible = true 
        @status_window.visible = false 
        end 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # Performing shop SE 
      $game_system.se_play($data_system.shop_se) 
      # Non setting the quantity input window to active invisibility 
      @number_window.active = false 
      @number_window.visible = false 
      # It diverges at cursor position of the command window 
      case @command_window.index 
        when 0  # It sells 
        # Sale processing 
        $game_party.gain_gold(@number_window.number * (@item.price / 2)) 
        case @item 
        when RPG::Item 
          $game_party.lose_item(@item.id, @number_window.number) 
        when RPG::Weapon 
          $game_party.lose_weapon(@item.id, @number_window.number) 
        when RPG::Armor 
          $game_party.lose_armor(@item.id, @number_window.number) 
        end 
        # Refreshing each window 
        @gold_window.refresh 
        @sell_window.refresh 
        @status_window.refresh 
        # State of window to sale mode 
        @sell_window.active = true 
        @sell_window.visible = true 
        @status_window.visible = false 
      end 
      return 
    end 
  end 
end
  
สำหรับร้านที่ใช้ซื้อไอเทม 
Code: #============================================================================== 
# * Window_ShopCommand 
#------------------------------------------------------------------------------ 
# ?In the shop picture, it is the window which selects business matter. 
#============================================================================== 
 
class Window_ShopBuyCommand < Window_Selectable 
  #-------------------------------------------------------------------------- 
  # - Object initialization 
  #-------------------------------------------------------------------------- 
  def initialize 
    super(0, 64, 480, 64) 
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.contents.font.name = $fontface 
    self.contents.font.size = $fontsize 
    @item_max = 2 
    @column_max = 2 
    @commands = ["Buy", "Cancel"] 
    refresh 
    self.index = 0 
  end 
  #-------------------------------------------------------------------------- 
  # - Refreshment 
  #-------------------------------------------------------------------------- 
  def refresh 
    self.contents.clear 
    for i in 0...@item_max 
      draw_item(i) 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - Drawing of item 
  #     index : Item number 
  #-------------------------------------------------------------------------- 
  def draw_item(index) 
    x = 4 + index * 240 
    self.contents.draw_text(x, 0, 128, 32, @commands[index]) 
  end 
end 
 
 
#============================================================================== 
# * Scene_Shop 
#------------------------------------------------------------------------------ 
# ?It is the class which processes the shop picture. 
#============================================================================== 
 
class Scene_Shop 
  #-------------------------------------------------------------------------- 
  # - Main processing 
  #-------------------------------------------------------------------------- 
  def main 
    # Drawing up the help window 
    @help_window = Window_Help.new 
    # Drawing up the command window 
    @command_window = Window_ShopBuyCommand.new 
    # Drawing up the Goldwyn dough 
    @gold_window = Window_Gold.new 
    @gold_window.x = 480 
    @gold_window.y = 64 
    # Drawing up the dummy window 
    @dummy_window = Window_Base.new(0, 128, 640, 352) 
    # Drawing up the purchase window 
    @buy_window = Window_ShopBuy.new($game_temp.shop_goods) 
    @buy_window.active = false 
    @buy_window.visible = false 
    @buy_window.help_window = @help_window 
    # Drawing up the quantity input window 
    @number_window = Window_ShopNumber.new 
    @number_window.active = false 
    @number_window.visible = false 
    # Drawing up the status window 
    @status_window = Window_ShopStatus.new 
    @status_window.visible = false 
    # Transition execution 
    Graphics.transition 
    # Main loop 
    loop do 
      # Renewing the game picture 
      Graphics.update 
      # Updating the information of input 
      Input.update 
      # Frame renewal 
      update 
      # When the picture changes, discontinuing the loop 
      if $scene != self 
        break 
      end 
    end 
    # Transition preparation 
    Graphics.freeze 
    # Releasing the window 
    @help_window.dispose 
    @command_window.dispose 
    @gold_window.dispose 
    @dummy_window.dispose 
    @buy_window.dispose 
        @number_window.dispose 
    @status_window.dispose 
  end 
  #-------------------------------------------------------------------------- 
  # - Frame renewal 
  #-------------------------------------------------------------------------- 
  def update 
    # Renewing the window 
    @help_window.update 
    @command_window.update 
    @gold_window.update 
    @dummy_window.update 
    @buy_window.update 
    @number_window.update 
    @status_window.update 
    # When the command window is active,: Update_command is called 
    if @command_window.active 
      update_command 
      return 
    end 
    # When the purchase window is active,: Update_buy is called 
    if @buy_window.active 
      update_buy 
      return 
    end 
    # When the quantity input window is active,: Update_number is called 
    if @number_window.active 
      update_number 
      return 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - When frame renewal (the command window is active) 
  #-------------------------------------------------------------------------- 
  def update_command 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # Change to map picture 
      $scene = Scene_Map.new 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # It diverges at cursor position of the command window 
      case @command_window.index 
      when 0  # It purchases 
        # Performing decision SE 
        $game_system.se_play($data_system.decision_se) 
        # State of window to purchase mode 
        @command_window.active = false 
        @dummy_window.visible = false 
        @buy_window.active = true 
        @buy_window.visible = true 
        @buy_window.refresh 
        @status_window.visible = true 
      when 1  # It stops 
        # Performing decision SE 
        $game_system.se_play($data_system.decision_se) 
        # Change to map picture 
        $scene = Scene_Map.new 
      end 
      return 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - When frame renewal (the purchase window is active) 
  #-------------------------------------------------------------------------- 
  def update_buy 
    # Setting the item of the status window 
    @status_window.item = @buy_window.item 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # State of window to early mode 
      @command_window.active = true 
      @dummy_window.visible = true 
      @buy_window.active = false 
      @buy_window.visible = false 
      @status_window.visible = false 
      @status_window.item = nil 
      # Eliminating the help text 
      @help_window.set_text("") 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # Acquiring the item 
      @item = @buy_window.item 
      # When the item is invalid, or when price it is on from the money in hand 
      if @item == nil or @item.price > $game_party.gold 
        # Performing buzzer SE 
        $game_system.se_play($data_system.buzzer_se) 
        return 
      end 
      # Acquiring the frequency of possession of the item 
      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 
      # Already, when 99 places it has kept 
      if number == 99 
        # Performing buzzer SE 
        $game_system.se_play($data_system.buzzer_se) 
        return 
      end 
      # Performing decision SE 
      $game_system.se_play($data_system.decision_se) 
      # Calculating the maximum purchase possible quantity 
      max = @item.price == 0 ? 99 : $game_party.gold / @item.price 
      max = [max, 99 - number].min 
      # State of window to quantity input mode 
      @buy_window.active = false 
      @buy_window.visible = false 
      @number_window.set(@item, max, @item.price) 
      @number_window.active = true 
      @number_window.visible = true 
    end 
  end 
  #-------------------------------------------------------------------------- 
  # - When frame renewal (the quantity input window is active) 
  #-------------------------------------------------------------------------- 
  def update_number 
    # The B when button is pushed 
    if Input.trigger?(Input::B) 
      # Performing cancellation SE 
      $game_system.se_play($data_system.cancel_se) 
      # Non setting the quantity input window to active invisibility 
      @number_window.active = false 
      @number_window.visible = false 
      # It diverges at cursor position of the command window 
      case @command_window.index 
      when 0  # It purchases 
        # State of window to purchase mode 
        @buy_window.active = true 
        @buy_window.visible = true 
      end 
      return 
    end 
    # When C button is pushed 
    if Input.trigger?(Input::C) 
      # Performing shop SE 
      $game_system.se_play($data_system.shop_se) 
      # Non setting the quantity input window to active invisibility 
      @number_window.active = false 
      @number_window.visible = false 
      # It diverges at cursor position of the command window 
      case @command_window.index 
      when 0  # It purchases 
        # Purchase processing 
        $game_party.lose_gold(@number_window.number * @item.price) 
        case @item 
        when RPG::Item 
          $game_party.gain_item(@item.id, @number_window.number) 
        when RPG::Weapon 
          $game_party.gain_weapon(@item.id, @number_window.number) 
        when RPG::Armor 
          $game_party.gain_armor(@item.id, @number_window.number) 
        end 
        # Refreshing each window 
        @gold_window.refresh 
        @buy_window.refresh 
        @status_window.refresh 
        # State of window to purchase mode 
        @buy_window.active = true 
        @buy_window.visible = true 
      end 
      return 
    end 
  end 
end
  
 
 
 
 |