Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Jragyn on May 28, 2010, 01:23:31 am

Title: [XP] J::BUY/SELL price modifier via variables!
Post by: Jragyn on May 28, 2010, 01:23:31 am
J::BUY/SELL via variables!
Authors: Jragyn
Version: 1.0
Type: Shop Pricing Add-on
Key Term: Custom Shop System



Introduction

This is almost not a script in the sense its just a mini J::MODULE and some variable fun.
It allows for the maker to create a sorta-sense of 'dynamic' pricing in-game.


Features




Screenshots

Spoiler: ShowHide
(http://i47.tinypic.com/30v13yw.png)

This probably means more than any in-game screenshot does.


Demo

If a demo is reeeeeally necessary, I will make one.
Otherwise, its pretty much plug'n'play.


Script

This does best underneath Scene_Shop, but above Main.
Spoiler: ShowHide
=begin
____________________________
| J::BUY/SELL via variables! |
| Author: Jragyn             |
| Inspiration: Yanfly(wong)  |
|____________________________|

 This script allows the maker to edit buying and selling prices globally
 via the use of ingame variables.

 Just change the variables indicated by:
 BUY = ##  and  SELL = ##
 while ingame, and the prices will be impacted in a percentual manner.    
--------------------------------------------------------------------------------  
 ie:
   change the variable value of BUY ingame to 70,
     and items will have a new pricetag of 70% its database price.
   
   change the variable value of SELL ingame to 100,
     and items you sell will be sold for their full price in the database.
--------------------------------------------------------------------------------
 The default pricing as suggested by RMXP is you buy at 100% of an items
 database price, and you sell it back for half-price. If you want to change
 this, just alter the value of the Variables designated below.


Lastly, I give credit to Yanfly. He created a script that replicates this effect
for RMVX, and now I present my version of it for RMXP.
 
v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
::Aliased   [Scene_Title] ----- command_new_game
::Overwrote [Scene_Shop] ------ update_buy & update_sell & update_number
::Overwrote [Window_Shopbuy] -- draw_item
v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
=end

module J
#========================================#
# BUY = Variable ## in the database.     #
# DEFAULT_BUY = The default buy pricing  #
                                        #
 BUY  = 11                              #
 DEFAULT_BUY = 100                      #
#========================================#
# SELL = Variable ## in the database.    #
# DEFAULT_BUY = The default sell pricing #
                                        #
 SELL = 12                              #
 DEFAULT_SELL = 50                      #
#========================================#
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
#                                                                              #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Scene_Title
 alias purple_uber_sonic_goose command_new_game
 def command_new_game
   purple_uber_sonic_goose
#==============================================#
# These are the default prices that            #
# are setup upon a new game.                   #
#==============================================#
   $game_variables[J::BUY]  = J::DEFAULT_BUY  #
   $game_variables[J::SELL] = J::DEFAULT_SELL #
#==============================================#
 end
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
#                                                                              #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Window_ShopBuy < Window_Selectable
 #--------------------------------------------------------------------------
 # * Draw Item
 #     index : item number
 #  altered 1 line to allow for price alterations.
 #--------------------------------------------------------------------------
 def draw_item(index)
   item = @data[index]
   # 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_variables[J::BUY]) / 100) <= $game_party.gold and number < 99
     self.contents.font.color = normal_color
   else
     self.contents.font.color = disabled_color
   end
   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 * $game_variables[J::BUY]) / 100).to_s, 2)
 end
end
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
#                                                                              #
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
class Scene_Shop
 #--------------------------------------------------------------------------
 # * Frame Update (when buy window is active)
 #  altered 3 lines to allow for price alterations.
 #--------------------------------------------------------------------------
 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
     # If item is invalid, or price is higher than money possessed
     if @item == nil or ((@item.price * $game_variables[J::BUY]) / 100) > $game_party.gold
       # Play buzzer SE
       $game_system.se_play($data_system.buzzer_se)
       return
     end
     # 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
     # Play decision SE
     $game_system.se_play($data_system.decision_se)
     # Calculate maximum amount possible to buy
     max = ((@item.price * $game_variables[J::BUY]) / 100) == 0 ? 99 : $game_party.gold / ((@item.price * $game_variables[J::BUY]) / 100)
     max = [max, 99 - number].min
     # Change windows to quantity input mode
     @buy_window.active = false
     @buy_window.visible = false
     @number_window.set(@item, max, ((@item.price * $game_variables[J::BUY]) / 100))
     @number_window.active = true
     @number_window.visible = true
   end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (when sell window is active)
 #  altered 2 lines to allow for price alterations.
 #--------------------------------------------------------------------------
 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 * $game_variables[J::SELL]) / 100) == 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)
     # 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
     # Change windows to quantity input mode
     @sell_window.active = false
     @sell_window.visible = false
     @number_window.set(@item, max, ((@item.price * $game_variables[J::SELL]) / 100))
     @number_window.active = true
     @number_window.visible = true
     @status_window.visible = true
   end
 end
 #--------------------------------------------------------------------------
 # * Frame Update (when quantity input window is active)
 #  altered 2 lines to allow for price alterations.
 #--------------------------------------------------------------------------
 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
       $game_party.lose_gold(@number_window.number * ((@item.price * $game_variables[J::BUY]) / 100))
       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
       # 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 * $game_variables[J::SELL]) / 100))
       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
end



Instructions

The instructions are pretty self explanatory.
Pick the variables, and edit them as necessary to manipulate pricing.


Compatibility

The pieces that have been re-written or aliased are listed in the script.
I can't imagine it being incompatible with too many things, short of maybe a custom shop menu.
It was put together in interest of being functional with Falcon's Tax Script (http://forum.chaos-project.com/index.php/topic,1807.0.html).
So hurray!

Oh, and its built to function in the default Scene_Shop, so if you change or mess with that,
this script may lose its functionality. Just tell me though and I can edit your Scene_Shop, if ya like.


Credits and Thanks




Author's Notes
Title: Re: [XP] J::BUY/SELL via variables!
Post by: Shining Riku on May 28, 2010, 12:46:11 pm
I'm so using this!  :D

Keep up the awesome work alright?
Title: Re: [XP] J::BUY/SELL via variables!
Post by: Fantasist on May 28, 2010, 01:09:47 pm
Nice script, J ^_^ Though, the way I'd have done it is like this:



module RPG
  class Item
   
    def price
      if $game_variables
        return @price * $game_variables[J::FACTOR] / 100
      end
      return @price
    end

  end
end


That would remove the need to change all those methods in shop scenes and what not to increase compatibility with CMSes.
Oh, wait! That wouldn't allow for different rates for buying and selling, so I'd have dumped it again, lol!

Anyway, *levels up*

PS: Maybe it's just me, but it took me a while to figure out what this script does. You should probably name it "J::BUY/SELL Percentagevia variables!" or something :)
Title: Re: [XP] J::BUY/SELL via variables!
Post by: Shining Riku on May 28, 2010, 02:54:52 pm
I'm gonna use this script to put merchants in my game that rip people off cuz they're mean.

And i'll be nice and hide some guys that buy stuff back for full price lol
Title: Re: [XP] J::BUY/SELL via variables!
Post by: CountVlad on May 28, 2010, 04:56:49 pm
Awesome script! Thanks! :D
Title: Re: [XP] J::BUY/SELL price modifier via variables!
Post by: Jragyn on May 29, 2010, 12:04:57 am
@Fantasist: Hah, I originally did make it like that, modifying price via RPG::EQUIP, but I needed to modify selling prices as well, so I just dove right into the main heart of Scene_shop to make it werrrrrrrk. :D

@Shining Riku: That was one of the original reasons I crafted this script, was for ****bag merchants jerkin' the player around. Genius minds think alike ^.^


So umm, dearest moderators, I've seen other people have their names change throughout time, can I have a name-change to? I like 'J' just fine.


--J