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.

Add options to shop processing?

Tindy

Sponsor

This might just be a simple matter of adding skill names to items, but...

Where in what script would I be able to add options to shop processing? I want to make skill shops and by default it gives you "Item," "Weapon," and "Armor." I've searched through the scripts (but I'm a MAJOR beginner) and all I could figure out was that possibly adding Skill (or whatever and all the accoutrements) to

Code:
      # Get items in possession count

      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
in Scene_Shop. But then I figured, no, that wouldn't quite work, because that's just getting the item, not selecting it.

Do I just need a whole new script for this? I'd rather just add-on to existing scripts, but I'll do what I have to.
 
You're right. That part just checks if the item is a weapon, armor or a normal item.
Note that
-you won't be able to set your store via event. (you can add only item/weapon/armor. it's how rmxp is built).
- you'll need to set the shop's skills some other way.
- skills don't have a price in the database. Use an array of prices for each skill.

Try using a custom scene_shop(erase the case @item, and make it teach skill instead of adding item) and a custom Window_ShopBuy which has skills inside @data. Since skills also have name, description and icon, you should have no problems. Just change the item.price part, to read the price from your array, and erase the case @item.
 

Tindy

Sponsor

Could you elaborate on that a bit? I'm still super new to scripting. I found a skill shop script, but it also has no instructions on usage, and it's super long (and to me, quite complicated).
 
You selected a tough script to start with.. Here's how I would have done it.
I left comments explaining what I changed. Ask me if something is not clear.
Code:
 

class Game_Temp

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

  # * set this every time you call for a skill shop

  #    use a script command in an event. for example:

  #     $game_temp.shop_skills = [1,2,23]

  #     $scene = Scene_ShopSkill.new

  #

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

  attr_accessor :shop_skills                  # array of skill id numbers.

end

 

 

class Window_BuySkill < Window_ShopBuy

  # windows are usually used inside a scene, 

  # which is responsible to update, create, and dispose it.

  # this window will be used in Scene_ShopSkill .

  def refresh

    if self.contents != nil

      self.contents.dispose

      self.contents = nil

    end

    @data = []

    # shop goods is an array. each item in it has the form [x,y]

    # x : item's kind (item/weapon/armor)..... shop_goods[i][0] 

    # y : item id.  .......................... shop_goods[i][1]

    for goods_item in @shop_goods

      # goods_items hols data for one item(or skill) in the shop.

      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]]

      when 3

        # if item is a skill, get the skill from the data base.

        # goods_item[1] = skill id

        item = $data_skills[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]

    # Disabled, as it is related to item/weapon/armor

=begin

    # Get items in possession

    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 price is less than money in possession, and amount in possession is

    # not 99, then set to normal text color. Otherwise set to disabled color

    if item.price <= $game_party.gold and number < 99

      self.contents.font.color = normal_color

    else

      self.contents.font.color = disabled_color

    end

=end

    # Edit here to give each skill a price. The price of skill #1 would be in @price[1], etc.

    # Edit @price in Scene_ShopSkill too.

    @price = Array.new

    for i in 0...$data_skills.size

      @price.push(100)

    end

    @item_price = @price[item.id]

    self.contents.font.color = normal_color # edit

    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 + 240, y, 88, 32, @item_price.to_s, 2)

  end

  

end

 

class Scene_ShopSkill < Scene_Shop

  

  def main

    # Make help window

    @help_window = Window_Help.new

    # Make command window

    @command_window = Window_ShopCommand.new

    # Make gold window

    @gold_window = Window_Gold.new

    @gold_window.x = 480

    @gold_window.y = 64

    # Make dummy window

    @dummy_window = Window_Base.new(0, 128, 640, 352)

    # Make buy window

    # ------------------ my edit ------------------------------

    # load the skills from $game_temp

    skills = $game_temp.shop_skills               

    shop_skills = Array.new

    # 3 means: skill

    for i in 0...skills.size

       shop_skills[i] = [3,skills[i]]

    end

    @price = Array.new

    for i in 0...$data_skills.size

      @price.push(900)

    end

    @buy_window = Window_BuySkill.new(shop_skills) #was $game_temp.shop_goods

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

    @buy_window.active = false

    @buy_window.visible = false

    @buy_window.help_window = @help_window

    # Make sell window

    @sell_window = Window_ShopSell.new

    @sell_window.active = false

    @sell_window.visible = false

    @sell_window.help_window = @help_window

    # Make quantity input window

    @number_window = Window_ShopNumber.new

    @number_window.active = false

    @number_window.visible = false

    

    # -- Disabled, as it is related to item/weapon/armor --

    # Make status window

    #@status_window = Window_ShopStatus.new  # new

    #@status_window.visible = false          # new

    # Execute transition

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @help_window.dispose

    @command_window.dispose

    @gold_window.dispose

    @dummy_window.dispose

    @buy_window.dispose

    @sell_window.dispose

    @number_window.dispose

    #@status_window.dispose

  end

  

    def update

    # Update windows

    @help_window.update

    @command_window.update

    @gold_window.update

    @dummy_window.update

    @buy_window.update

    @sell_window.update

    @number_window.update

    #@status_window.update

    # If command window is active: call update_command

    if @command_window.active

      update_command

      return

    end

    # If buy window is active: call update_buy

    if @buy_window.active

      update_buy

      return

    end

    # If sell window is active: call update_sell

    if @sell_window.active

      update_sell

      return

    end

    # If quantity input window is active: call update_number

    if @number_window.active

      update_number

      return

    end

    # ------- edit ---------------

    # we created a new window, and we're responsible to update it. 

    if @command_window2.active

      @command_window2.update

      update_actor_select  # a new method

    end

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

  end

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

  # * Frame Update (when command window is active)

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

  def update_command

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Play cancel SE

      $game_system.se_play($data_system.cancel_se)

      # Switch to map screen

      $scene = Scene_Map.new

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Branch by command window cursor position

      case @command_window.index

      when 0  # buy

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Change windows to buy mode

        @command_window.active = false

        @dummy_window.visible = false

        @buy_window.active = true

        @buy_window.visible = true

        @buy_window.refresh

        #@status_window.visible = true  # Diabled

      when 1  # sell

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Change windows to sell mode

        @command_window.active = false

        @dummy_window.visible = false

        @sell_window.active = true

        @sell_window.visible = true

        @sell_window.refresh

      when 2  # quit

        # Play decision SE

        $game_system.se_play($data_system.decision_se)

        # Switch to map screen

        $scene = Scene_Map.new

      end

      return

    end

  end

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

  # * Frame Update (when buy window is active)

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

  def update_buy

    # Set status window item

    #@status_window.item = @buy_window.item

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Play cancel SE

      $game_system.se_play($data_system.cancel_se)

      # Change windows to initial 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

      # Erase help text

      @help_window.set_text("")

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Get item

      @item = @buy_window.item

      @item_price = @price[@item.id]

      # If item is invalid, or price is higher than money possessed

      if @item == nil or @item_price > $game_party.gold

        # Play buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

=begin

      # Get items in possession count

      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 99 items are already in possession

      if number == 99

        # Play buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

=end

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

      # Calculate maximum amount possible to buy

      # --- edit. buy 1 skill at a time. max=1 ---

      #max = @item_price == 0 ? 99 : $game_party.gold / @item_price # price was @item.price

      #max = [max, 1].max  # edit

      max = 1

      # Change windows 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

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

  # * Frame Update (when sell window is active)

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

  def update_sell

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Play cancel SE

      $game_system.se_play($data_system.cancel_se)

      # Change windows to initial mode

      @command_window.active = true

      @dummy_window.visible = true

      @sell_window.active = false

      @sell_window.visible = false

      #@status_window.item = nil

      # Erase help text

      @help_window.set_text("")

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Get item

      @item = @sell_window.item

      # Set status window item

      #@status_window.item = @item

      # If item is invalid, or item price is 0 (unable to sell)

      if @item == nil or @item_price == 0

        # Play buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

      # Play decision SE

      $game_system.se_play($data_system.decision_se)

=begin

      # Get items in possession count

      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

      # Maximum quanitity to sell = number of items in possession

      max = number

=end

      @item_price = @price[@item.id]

      # --- edit. buy 1 skill at a time. max=1 ---

      #max = @item_price == 0 ? 99 : $game_party.gold / @item_price # price was @item.price

      #max = [max, 1].max  # edit

      max = 1

      # Change windows 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

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

  # * Frame Update (when quantity input window is active)

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

  def update_number

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Play cancel SE

      $game_system.se_play($data_system.cancel_se)

      # Set quantity input window to inactive / invisible

      @number_window.active = false

      @number_window.visible = false

      # Branch by command window cursor position

      case @command_window.index

      when 0  # buy

        # Change windows to buy mode

        @buy_window.active = true

        @buy_window.visible = true

      when 1  # sell

        # Change windows to sell mode

        @sell_window.active = true

        @sell_window.visible = true

        #@status_window.visible = false

      end

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Play shop SE

      $game_system.se_play($data_system.shop_se)

      # Set quantity input window to inactive / invisible

      @number_window.active = false

      @number_window.visible = false

      # Branch by command window cursor position

      case @command_window.index

      when 0  # buy

        # Buy process

=begin

        $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

=end

        # teach skill

        teach_skill(@item.id)

        # Refresh each window

        #@gold_window.refresh

        #@buy_window.refresh

        #@status_window.refresh

        # Change windows to buy mode

        #@buy_window.active = true

        #@buy_window.visible = true

      when 1  # sell

        # Sell process

        $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

        # Refresh each window

        @gold_window.refresh

        @sell_window.refresh

        #@status_window.refresh

        # Change windows to sell mode

        @sell_window.active = true

        @sell_window.visible = true

        #@status_window.visible = false

      end

      return

    end

  end

  

  # new method: start selection of an actor.

  def teach_skill(id)

    @buy_window.active = false

    @number_window.active = false

    @command_window.active = false

    @sell_window.active = false

    list = Array.new

    for ac in $game_party.actors

      list.push(ac.name)

    end

    # create a new menu. list holds the commands. 272 is the menu width.

    @command_window2 = Window_Command.new(272, list)

    @command_window2.x =368

    @command_window2.y =128

    @command_window2.index = 0

    @command_window2.active = true

  end

  

  # this method will determine what to do when a certain 

  # menu command is selected. 

  # We want to teach our skill (@item) to the selected actor.

  def update_actor_select

    if Input.trigger?(Input::C)

      # Play shop SE

      $game_system.se_play($data_system.shop_se)

      # Set quantity input window to inactive / invisible

      @number_window.active = false

      @number_window.visible = false

      # Branch by command window cursor position

      index = @command_window2.index

      actor = $game_actors[$game_party.actors[index].id]

      actor.learn_skill(@item.id)

      @command_window2.dispose

      $game_party.lose_gold(@number_window.number * @item_price)

      @gold_window.refresh

      @buy_window.refresh

      @buy_window.active = true

      @buy_window.visible = true

    end

 

  end

  

end #class

 

 
 

Tindy

Sponsor

It works! :D Thank you! I actually had to go through another script to figure out how to use this one (because that one kept error'ing at me D<) but now it works! Thank you! :D

EDIT: Ok, now a question. How do I edit prices? It says
Code:
    # Edit here to give each skill a price. The price of skill #1 would be in @price[1], etc.

    # Edit @price in Scene_ShopSkill too.

    @price = Array.new

    for i in 0...$data_skills.size

      @price.push(100)

    end

And I've got that, somewhere after the #EDIT HERE's and before the END is where, I assume, @price[1] = (60) or whatever would go, but is there an exact place to stick it?
 
The array has 'default' price: 100 for all skills. Change the number in the loop to the default price you want.
After the loop, do something like:
@price[1] = 60
@price[5] = 80
etc
This gives skills 1 and 5 a non- default price.
 

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