Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Upgrade Shop Script, A new kind of shop in which you can upgrade items too new ones
-dah0rst-
post Mar 17 2010, 07:55 AM
Post #1


Level 11
Group Icon

Group: Revolutionary
Posts: 174
Type: Scripter
RM Skill: Advanced




This little script is the first scripot I made for RPGVX- it's not very special, most things are just edits from the original script- but it gives you the opportunity too build a shop in which you can upgrade items too better ones in exchange for gold.
Example: You have a 'rusty long sword' and want to go too a blacksmith too sharpen it. So you go too him, pay the price for the sword and you will gain an 'sharpened long sword' in exchance.
Other Example: You want too have an cursed bow. So you go too a witch too enchant it. And... you get one in exchange for your bow.
And so on... ^^

Here it is, description you'll find below. Please rename Scene_Shop, or there will be bugs.

new Scene_Shop:

CODE
#==============================================================================
# ** This is new Scene_Shop- please rename the old one
#------------------------------------------------------------------------------
#  This class performs shop screen processing and enchant shop.
#  $enchant= true/false -> if true, then you proced enchant shop instead of re-
#  gular shop
#  $limit= integer-> the maximum of enchant levels an iitem could have
#  $range= integer-> the distance between item and enchanted item in items list
#
#  Free script by dah0rst, 16. March 2010
#  Please list me in your credits, thx!
#==============================================================================

class Scene_Shop < Scene_Base
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    create_command_window
    @game_party = Game_Party.new
    @help_window = Window_Help.new
    @gold_window = Window_Gold.new(384, 56)
    @dummy_window = Window_Base.new(0, 112, 544, 304)
if $enchant==true
  then
    @buy_window = Window_ItemList.new(0, 112,304,304)
  else
    @buy_window = Window_ShopBuy.new(0, 112)
  end
    @buy_window.active = false
    @buy_window.visible = false
    @buy_window.help_window = @help_window
    @sell_window = Window_ShopSell.new(0, 112, 544, 304)
    @sell_window.active = false
    @sell_window.visible = false
    @sell_window.help_window = @help_window
    @number_window = Window_ShopNumber.new(0, 112)
    @number_window.active = false
    @number_window.visible = false
    @status_window = Window_ShopStatus.new(304, 112)
    @status_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    dispose_command_window
    @help_window.dispose
    @gold_window.dispose
    @dummy_window.dispose
    @buy_window.dispose
    @sell_window.dispose
    @number_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @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.active
      update_command_selection
    elsif @buy_window.active
      update_buy_selection
    elsif @sell_window.active
      update_sell_selection
    elsif @number_window.active
      update_number_input
    end
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    s1 = Vocab::ShopBuy
    s2 = Vocab::ShopSell
    s3 = Vocab::ShopCancel
    @command_window = Window_Command.new(384, [s1, s2, s3], 3)
    @command_window.y = 56
    if $game_temp.shop_purchase_only
      @command_window.draw_item(1, false)
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose of Command Window
  #--------------------------------------------------------------------------
  def dispose_command_window
    @command_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Command Selection
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      case @command_window.index
      when 0  # buy
        Sound.play_decision
        @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  # sell
        if $game_temp.shop_purchase_only
          Sound.play_buzzer
        else
          Sound.play_decision
          @command_window.active = false
          @dummy_window.visible = false
          @sell_window.active = true
          @sell_window.visible = true
          @sell_window.refresh
        end
      when 2  # Quit
        Sound.play_decision
        $scene = Scene_Map.new
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update Buy Item Selection
  #--------------------------------------------------------------------------
  def update_buy_selection
    @status_window.item = @buy_window.item
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @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.trigger?(Input::C)
      @item = @buy_window.item
      number = $game_party.item_number(@item)
      if @item == nil or @item.price > $game_party.gold or number == 99
        Sound.play_buzzer
      else
        Sound.play_decision
        if enchant=false then
        max = @item.price == 0 ? 99 : $game_party.gold / @item.price
        max = [max, 99 - number].min
               @buy_window.active = false
        @buy_window.visible = false
        @number_window.set(@item, max, @item.price)
        @number_window.active = true
        @number_window.visible = true
      else
        max = 1
        decide_number_input
      end


      
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update Sell Item Selection
  #--------------------------------------------------------------------------
  def update_sell_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @command_window.active = true
      @dummy_window.visible = true
      @sell_window.active = false
      @sell_window.visible = false
      @status_window.item = nil
      @help_window.set_text("")
    elsif Input.trigger?(Input::C)
      @item = @sell_window.item
      @status_window.item = @item
      if @item == nil or @item.price == 0
        Sound.play_buzzer
      else
        Sound.play_decision
        max = $game_party.item_number(@item)
        @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
  end
  #--------------------------------------------------------------------------
  # * Update Number Input
  #--------------------------------------------------------------------------
  def update_number_input
    if Input.trigger?(Input::B)
      cancel_number_input
    elsif Input.trigger?(Input::C)
      decide_number_input
    end
  end
  #--------------------------------------------------------------------------
  # * Cancel Number Input
  #--------------------------------------------------------------------------
  def cancel_number_input
    Sound.play_cancel
    @number_window.active = false
    @number_window.visible = false
    case @command_window.index
    when 0  # Buy
      @buy_window.active = true
      @buy_window.visible = true
    when 1  # Sell
      @sell_window.active = true
      @sell_window.visible = true
      @status_window.visible = false
    end
  end
  #--------------------------------------------------------------------------
  # * Confirm Number Input
  #--------------------------------------------------------------------------
  def decide_number_input

    @number_window.active = false
    @number_window.visible = false
    case @command_window.index
    when 0  # Buy
      
    if $enchant==true
      then
      @buy_window.refresh
      @item = @buy_window.item
      @item.id = @buy_window.item.id
      @index = @buy_window.item.id
      


      if @item.id<(($enchant_range+1)*($enchant_limit-1)) then
        $game_party.gain_item($data_weapons[@index],-@number_window.number,false)
        @item.id += $enchant_range
        @index+=49
        $game_party.gain_item($data_weapons[@index],  @number_window.number,false)
        $game_party.lose_gold(@number_window.number * @item.price)
        @buy_window.refresh
        Sound.play_shop
        @item.id -= $enchant_range
        else
        Sound.play_buzzer
      end
      
      else

        $game_party.gain_item(@item, @number_window.number)
        $game_party.lose_gold(@number_window.number * @item.price)
        Sound.play_shop
      end
      @gold_window.refresh
      @buy_window.refresh
      @status_window.refresh
      @buy_window.active = true
      @buy_window.visible = true
    when 1  # sell
      $game_party.gain_gold(@number_window.number * (@item.price / 2))
      $game_party.lose_item(@item, @number_window.number)
      @gold_window.refresh
      @sell_window.refresh
      @status_window.refresh
      @sell_window.active = true
      @sell_window.visible = true
      @status_window.visible = false
    end
  end
end


And also Window_ItemList

CODE
#==============================================================================
# ** Window_ItemList
#------------------------------------------------------------------------------
#  Belongs too enchant shop
#==============================================================================

class Window_ItemList < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @column_max = 1
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end

  def index2
    return self.index
  end
  #--------------------------------------------------------------------------
  # * Whether or not to include in item list
  #     item : item
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item == nil
    if $game_temp.in_battle
      return false unless item.is_a?(RPG::Weapon)
    end
    return true
  end

  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    for item in $game_party.items
    if item.is_a?(RPG::Weapon)
      next unless include?(item)
      @data.push(item)
      if item.is_a?(RPG::Weapon) and item.id == $game_party.last_item_id
        self.index = @data.size - 1
      end
    end
    @data.push(nil) if include?(nil)
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    if item != nil
      number = $game_party.item_number(item)
      rect.width -= 4
      draw_item_name(item, rect.x, rect.y)
      self.contents.draw_text(rect, item.price, 2)
    end
  end
  #--------------------------------------------------------------------------
  # * Update Help Text
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(item == nil ? "" : item.description)
  end
end


Too use the script, you have to build the weapons in data base, and also their better versions. The better Versions are always a fixed number of slots under the base item, like this: (better versions are marked [], just to show)

001:Club
002:Sword
003:Bow
004:[Ogre's Club]
005:[Icy Sword]
006:[Cursed Bow]

The script is started with the "Shop Processing" event- you only have to write "$enchant=true" before and "$enchant=false behind it (with the call script event). There are no bugs on the normal shop event.

There are also some variables too customize the script. Best too write them into the first event of the game, or into the "Main" script, or before every shop (by the "call script" event)

$enchant_range=xy (xy is a number between 1 and 1000)
This says, how many slots of base items you have. Here are 2 examples:

$enchant_range=4
001:Club
002:Sword
003:Bow
004:Staff
005:[Ogre's Club]
006:[Icy Sword]
007:[Cursed Bow]
008:[Mystic Staff]

$enchant_range=2
001:Club
002:Sword
003:[Ogre's Club]
004:[Icy Sword]

I hope you understand the system.

$enchant_limit=xy
This says, how many upgrades you can achieve for one weapon. for example, with $enchant_limit=2 you can upgrade one time, like in the examples above. But you could also, with $enchant_limit=3 do something like this: normal weapon -> sharp weapon -> master weapon

Example: (3rd level items are marked [[]], just too show)

$enchant_range=2
$enchant_limit=3
001:Club
002:Sword
003:[Heavy Club]
004:[Sharp Sword]
005:[[Very Heavy Club]]
006:[[Masterful Sword]]

Pls send me comments about the script, thx


__________________________
You want Next Gen graphic algorithms in RPG VX? Ask the horst :P


But don't expect this in real time ;)
Go to the top of the page
 
+Quote Post
   



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 08:52 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker