estriole

EST - PRICE FORMULA

Oct 12th, 2013
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.82 KB | None | 0 0
  1. =begin
  2.  ■ Information      ╒═════════════════════════════════════════════════════════╛
  3.  EST - PRICE FORMULA
  4.  by Estriole
  5.  v.1.1
  6.  
  7.  ■ Changelog        ╒═════════════════════════════════════════════════════════╛
  8.  v1.0 2013.10.13     >     Initial Release
  9.  v1.1 2013.10.24     >     Add shop sell formula feature so you can custom each shop how
  10.                            much the shop will pay for the item (ex: 10x original price, etc)
  11.                            
  12.  ■ Introduction     ╒═════════════════════════════════════════════════════════╛
  13.    This script make us able to create formula for item / equip price. for example
  14.  item like seltzer from star ocean where it become more expensive as the game time
  15.  increases
  16.  
  17.  ■ Requirement     ╒═════════════════════════════════════════════════════════╛
  18.    Just RPG MAKER VX ACE program :D
  19.  
  20.  ■ How to Use     ╒═════════════════════════════════════════════════════════╛
  21.  1) to set buying price formula (affect selling too but divided by two if you
  22.  don't set the shop sell formula)
  23.  put this notetags to your item/armor/weapon:
  24.  <price_formula>
  25.  your price formula here
  26.  </price_formula>
  27.  the formula need to be valid ruby that return number.
  28.  there's also a shortcut variable that i set for you:
  29.       s = $game_switches
  30.       v = $game_variables
  31.       p = $game_party
  32.       a = $game_actors
  33.       gs = $game_system
  34.       pt = $game_system.playtime
  35.       bc = $game_system.battle_count
  36.       sc = $game_system.save_count
  37.       i = the item itself (for checking type or id)
  38.       @price = default price in database
  39.  so if you want to make item real price is 100 but become 1000000 if switch 99 is on
  40.  <price_formula>
  41.  s[99] ? 1000000 : 100
  42.  </price_formula>
  43.  or if you confuse on above technique
  44.  <price_formula>
  45.  if s[99] == true
  46.    1000000
  47.  else
  48.    100
  49.  end
  50.  </price_formula>  
  51.  
  52.  2) new feature *** shop sell formula ***
  53.  with this feature you can custom each shop sell formula.
  54.  ex: trading shop pay full price of the item
  55.  while normal shop pay only 10% of the price value.
  56.  there's two way to use the feature.
  57.  a) direct usage... script call BEFORE calling a shop:
  58.  
  59.  @a = "your formula in string here"
  60.  $game_temp.sell_formula = @a
  61.  
  62.  formula is ruby command that return number. there's some variable help too for this:
  63.     s = $game_switches
  64.     v = $game_variables
  65.     p = $game_party
  66.     a = $game_actors
  67.     gs = $game_system
  68.     pt = $game_system.playtime
  69.     bc = $game_system.battle_count
  70.     sc = $game_system.save_count
  71.     i = @item (used to check the kind of item or item id perhaps. ex: weapon shop pay less for armor and potion)
  72.     price = item price affected by formula you set in number 1 above
  73.     o_price = item original price set in database
  74.  after the shop scene closed it will reset the shop formula (using default sell formula).
  75.  so if you want to call normal shop just don't use the script call above.
  76.  
  77.  some example usage: Script call:
  78.  @a = "
  79.  case p.leader.name
  80.  when 'Estriole'
  81.    price
  82.  when 'Tsukihime'
  83.    price / sc
  84.  when 'Victor'  
  85.    o_price
  86.  else
  87.    o_price / 10
  88.  end "
  89.  then script call again:
  90.  $game_temp.sell_formula = @a
  91.  
  92.  (i use @ so it can pass on to next script call. but you might want to use
  93.  Tsukihime large script call script too if your formula is really long)
  94.  
  95.  above formula means. if party leader name is 'Estriole' then the selling formula is
  96.  price that affected by formula you set in notetags
  97.  if party leader name is 'Tsukihime' then the selling formula is
  98.  price that affected by formula you set in notetags divided by save count
  99.  if party leader name is 'Victor' then the selling formula is
  100.  original price you set in database  
  101.  other than that then the selling formula is
  102.  original price you set in database divided by 10
  103.  
  104.  WARNING: the formula is in string so you might need to use ' if you want to
  105.  compare with string.
  106.  
  107.  b) pre-write formula in this script first and reference it in script call
  108.  write your shop type and formula in the S_F hash below.
  109.  and later script call BEFORE calling your shop:
  110.  $game_temp.sell_formula = S_F[yourhashkey]
  111.  
  112. =end
  113.  
  114.  
  115. module ESTRIOLE
  116.   module PRICE_FORMULA
  117.     # assign switch to activate the formula price. if that switch off then use default price
  118.     ACTIVATE_SWITCH = 10   # change to 0 to always activate
  119.     # start condition of the switch above. true means it will on at start of the game.
  120.     START_SWITCH = true
  121.   end
  122.   module SELL_FORMULA
  123.     S_F = {
  124.     "trade" => "price",
  125.     "normal" => "o_price / 2",
  126.     "rich man" => "price * 2",
  127.     }
  128.   end
  129. end
  130.  
  131. class Game_Interpreter
  132.   include ESTRIOLE::SELL_FORMULA
  133. end
  134.  
  135. class Game_Switches
  136.   include ESTRIOLE::PRICE_FORMULA
  137.   alias est_price_formula_switch_initialize initialize
  138.   def initialize
  139.     est_price_formula_switch_initialize
  140.     @data[ACTIVATE_SWITCH] = START_SWITCH if ACTIVATE_SWITCH != 0
  141.   end
  142. end
  143.  
  144. class Game_Temp
  145.   def sell_formula
  146.     @sell_formula
  147.   end
  148.   def sell_formula=(formula = nil)
  149.     return if @sell_formula == formula
  150.     @sell_formula = formula
  151.   end
  152. end
  153.  
  154. class Scene_Shop < Scene_MenuBase
  155.   alias est_sell_formula_sell_price selling_price
  156.   def selling_price
  157.     s = $game_switches
  158.     v = $game_variables
  159.     p = $game_party
  160.     a = $game_actors
  161.     gs = $game_system
  162.     pt = $game_system.playtime
  163.     bc = $game_system.battle_count
  164.     sc = $game_system.save_count
  165.     i = @item
  166.     price = @item.price
  167.     o_price = @item.orig_price
  168.     return eval($game_temp.sell_formula) if $game_temp.sell_formula
  169.     est_sell_formula_sell_price
  170.   end
  171.   alias est_sell_formula_terminate terminate
  172.   def terminate
  173.     $game_temp.sell_formula = nil
  174.     est_sell_formula_terminate
  175.   end
  176. end
  177.  
  178. class RPG::EquipItem < RPG::BaseItem
  179.   include ESTRIOLE::PRICE_FORMULA
  180.     def price
  181.       return @price if ACTIVATE_SWITCH != 0 && !$game_switches[ACTIVATE_SWITCH]
  182.       return @price rescue 0 if !note[/<price_formula?>(?:[^<]|<[^\/])*<\/price_formula?>/i]
  183.       grab = note[/<price_formula?>(?:[^<]|<[^\/])*<\/price_formula?>/i].scan(/(?:!<price_formula?>|(.*)\r)/)
  184.       grab.delete_at(0)    
  185.       noteargs = grab.join("\r\n")    
  186.       s = $game_switches
  187.       v = $game_variables
  188.       p = $game_party
  189.       a = $game_actors
  190.       gs = $game_system
  191.       pt = $game_system.playtime
  192.       bc = $game_system.battle_count
  193.       sc = $game_system.save_count
  194.       i = self
  195.       return price = eval(noteargs) rescue @price rescue 0
  196.     end
  197.     def orig_price
  198.       @price
  199.     end
  200. end
  201. class RPG::Item < RPG::UsableItem
  202.  include ESTRIOLE::PRICE_FORMULA
  203.     def price
  204.       return @price if ACTIVATE_SWITCH != 0 && !$game_switches[ACTIVATE_SWITCH]
  205.       return @price rescue 0 if !note[/<price_formula?>(?:[^<]|<[^\/])*<\/price_formula?>/i]
  206.       grab = note[/<price_formula?>(?:[^<]|<[^\/])*<\/price_formula?>/i].scan(/(?:!<price_formula?>|(.*)\r)/)
  207.       grab.delete_at(0)    
  208.       noteargs = grab.join("\r\n")    
  209.       s = $game_switches
  210.       v = $game_variables
  211.       p = $game_party
  212.       a = $game_actors
  213.       gs = $game_system
  214.       pt = $game_system.playtime
  215.       bc = $game_system.battle_count
  216.       sc = $game_system.save_count
  217.       i = self
  218.       return price = eval(noteargs) rescue @price rescue 0
  219.     end
  220.     def orig_price
  221.       @price
  222.     end
  223. end
Advertisement
Add Comment
Please, Sign In to add comment