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.

A problem about shopping

Hi guys,
In the shop scene, How can I put the items according to the prices (from low to high price downwards) instead of the items' ID?

Is there any way to do it?
 
Of course there is! :scruff:

Paste this above Main. If you don't want the "Sell" window sorted by price, just delete the bottom section from "class Window_ShopSell" to the end.

Code:
 

class Window_ShopBuy

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     shop_goods : goods

  #--------------------------------------------------------------------------

  def initialize(shop_goods)

    super(0, 128, 368, 352)

    @shop_goods = []

    #rearrange by price    *** BREW

    for i in 0..10000

      for item in shop_goods

        case item[0]

        when 0 #item

          if $data_items[item[1]].price == i

            @shop_goods.push(item)

          end

        when 1 #weapon

          if $data_weapons[item[1]].price == i

            @shop_goods.push(item)

          end           

        when 2 #armor

          if $data_armors[item[1]].price == i

            @shop_goods.push(item)

          end           

        end

      end

    end

    refresh

    self.index = 0

  end

end

 

class Window_ShopSell

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    if self.contents != nil

      self.contents.dispose

      self.contents = nil

    end

    sell_data = []

    for i in 1...$data_items.size

      if $game_party.item_number(i) > 0

        sell_data.push($data_items[i])

      end

    end

    for i in 1...$data_weapons.size

      if $game_party.weapon_number(i) > 0

        sell_data.push($data_weapons[i])

      end

    end

    for i in 1...$data_armors.size

      if $game_party.armor_number(i) > 0

        sell_data.push($data_armors[i])

      end

    end

    #rearrange by price    *** BREW

    @data = []

    for i in 0..10000

      for item in sell_data

        if item.price == i

          @data.push(item)

        end

      end

    end

    # If item count is not 0, make a bitmap 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

end

 
 

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