Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> 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
   
Kread-EX
post Mar 17 2010, 08:09 AM
Post #2


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




This doesn't seem to work. I used one of your examples to test it, but whenever I pay, nothing changes in the item menu afterwards.
Also, it would be better to rename this scene rather than the original Scene_Shop.

EDIT: nevermind, I managed to make it work. It's a little cryptic but it's a decent idea.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
woahfish
post Apr 20 2010, 10:18 AM
Post #3


Level 1
Group Icon

Group: Member
Posts: 9
Type: None
RM Skill: Intermediate




it's to, not too.


__________________________


who cut the cheese?
Go to the top of the page
 
+Quote Post
   
Xeyla
post Apr 20 2010, 03:30 PM
Post #4


Keeper of the RMVX FAQ
Group Icon

Group: Revolutionary
Posts: 706
Type: Mapper
RM Skill: Intermediate




When you post a script that is long, you should put it in spoiler tags.

Other then that, this is a neat script. I've often thought about doing this with my items, but never got around to it.


__________________________


QUOTE (Albino Parakeet @ Apr 1 2011, 05:46 PM) *
i need to know exactly how to put a penis inside someone's butt.
do you have the technical knowledge to tell me how?
QUOTE (Albino Parakeet @ Apr 2 2011, 01:20 PM) *
QUOTE (Shadyone @ Apr 2 2011, 06:29 AM) *
I see the keet likes anal.

im trying to get into it but people aren't answering my question
Go to the top of the page
 
+Quote Post
   
KevinWagner
post Oct 16 2010, 05:48 PM
Post #5


Level 4
Group Icon

Group: Member
Posts: 58
Type: Event Designer
RM Skill: Skilled




whenever I pay, nothing changes in the item menu afterwards.

QUOTE (Kread-EX @ Mar 17 2010, 09:09 AM) *
This doesn't seem to work. I used one of your examples to test it, but whenever I pay, nothing changes in the item menu afterwards.
Also, it would be better to rename this scene rather than the original Scene_Shop.

EDIT: nevermind, I managed to make it work. It's a little cryptic but it's a decent idea.

How did you manage to fix it? I have the same problem as you did

This post has been edited by Kread-EX: Oct 17 2010, 02:36 AM
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Oct 17 2010, 02:38 AM
Post #6


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




Please don't double post. Use the Edit button.

And I didn't fix it; I simply managed to understand how it worked.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
KevinWagner
post Oct 17 2010, 08:41 AM
Post #7


Level 4
Group Icon

Group: Member
Posts: 58
Type: Event Designer
RM Skill: Skilled




QUOTE (Kread-EX @ Oct 17 2010, 03:38 AM) *
Please don't double post. Use the Edit button.

And I didn't fix it; I simply managed to understand how it worked.

I didn't exactly double post, i had something else and edited it because i figured my problem.
But what did you do to fix your problem. Cause evidently we had the same misunderstanding.
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Oct 17 2010, 10:43 AM
Post #8


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




You did double post. I'm the one who merged the two.

Anyways, the key point is $enchant_range. Basically, it represents the number of items per item level. For instance, if you put $enchant_range = 3, it's considered that each 3 items, you reach a new 'item level'.
The best way to understand is to try all the examples he gave.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
KevinWagner
post Oct 17 2010, 11:26 AM
Post #9


Level 4
Group Icon

Group: Member
Posts: 58
Type: Event Designer
RM Skill: Skilled




QUOTE (Kread-EX @ Oct 17 2010, 11:43 AM) *
You did double post. I'm the one who merged the two.

Anyways, the key point is $enchant_range. Basically, it represents the number of items per item level. For instance, if you put $enchant_range = 3, it's considered that each 3 items, you reach a new 'item level'.
The best way to understand is to try all the examples he gave.


I understand that, so that doesn't fix any problem. This is my setup for the event, and if you look at the shop processing you can see how my weapons are in my database

[Enchant Shop Example
hidden stuff"]
@>Script: $enchant= true
@>Script:$enchant_limit=3
@>Script:$enchant_range=1
@>Shop Processing: Dagger
Iron Katana
[Steel Katana]
[[Master Katana]]
Iron Longsword
[Steel Longword]
Iron Axe
[Steel Axe]
[[Master Axe]]
etc...
@>Script: $enchant= false
@>
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Oct 17 2010, 11:58 AM
Post #10


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




Strangely enough, it seems that I did fix it last time but I simply forgot...

Well, anyway, in the Scene_Shop part of the script, there is that:
CODE
@index+= 49
Replace 49 by $enchant_range

I guess I did that last time and forgot about it. Sorry.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
KevinWagner
post Oct 17 2010, 12:32 PM
Post #11


Level 4
Group Icon

Group: Member
Posts: 58
Type: Event Designer
RM Skill: Skilled




QUOTE (Kread-EX @ Oct 17 2010, 12:58 PM) *
Strangely enough, it seems that I did fix it last time but I simply forgot...

Well, anyway, in the Scene_Shop part of the script, there is that:
CODE
@index+= 49
Replace 49 by $enchant_range

I guess I did that last time and forgot about it. Sorry.

Works great now! Thanks!
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: 21st May 2013 - 11:49 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker