Guest User

Modified Currency Script

a guest
Aug 17th, 2021
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===========================================================================
  2. #    Author:        Calestian
  3. #    Name:          Multiple Currencies
  4. #    Created:       02-08-2015
  5. #    Version:       1.2
  6. #    Revisions by:  Matt Gowens
  7. #---------------------------------------------------------------------------
  8. #                       VERSION HISTORY
  9. #
  10. #    v1.0 - Initial Release
  11. #    v1.1 - Bug fix: gain_gold and lose_gold argument fix
  12. #    v1.1 - Editited by Matt Gowens
  13. #             Code Cleanup, made script more modular, added some
  14. #             additional annotations
  15. #---------------------------------------------------------------------------
  16. #                       DESCRIPTION
  17. #    
  18. #    User can set more than one different currencies.
  19. #
  20. #    There is a new Menu tab displaying all set currencies.
  21. #
  22. #    Shops can use only one currency.
  23. #
  24. #    Note: It is possible to set different shops to use different currencies.
  25. #---------------------------------------------------------------------------
  26. #                       LICENSE INFO
  27. #
  28. #    Free for commercial & non-commerical use as long as credit is given to
  29. #    Calestian.
  30. #---------------------------------------------------------------------------
  31. #                       How to Use
  32. #
  33. #    - Change Currencies in the module below to enter the icons and
  34. #      the starting value of each currency.
  35. #
  36. #    - To apply a currency to a shop, in the event window, before
  37. #      Shop Processing, add a scripted command (Advanced Tab):
  38. #      currency(Currency_ID)
  39. #
  40. #    - To apply a currency gain or lose, in the event window, add
  41. #      a scripted command (Advanced Tab):
  42. #      add_currency(amount, Currency_ID) to apply a currency gain
  43. #      add_currency(-amount, Currency_ID) to apply a currency loss
  44. #===========================================================================
  45. #   Additional Notes:
  46. # For conditional branches, use:
  47. #      $game_party.currency[CurrencyID]
  48. #
  49. #     Ex:   if  $game_party.currency[CurrencyID] > 35 then
  50. #              do something
  51. #           end
  52. #
  53. #
  54. #   If there is something you would like to see added or changed, let me know
  55. #  
  56. #
  57. # Full Credits go to Calestian for the framework and IP of this Script.
  58. #===========================================================================
  59. # *** Editable Region
  60. #===========================================================================
  61. module Clstn_Currencies
  62.  
  63.   Currencies = {
  64.     #CurrencyID => [IconID, Starting Amount]
  65.     0 => [216, 0],
  66.     1 => [217, 0],
  67.     2 => [218, 0]
  68.    
  69.   }
  70.  
  71.   Vocab_Menu = "Currency" #Name of tab in Menu
  72.  
  73.  
  74.   #Use RGB Colors
  75.   #When Currency menu is open, this is the color of the title
  76.   ColorTitle = [245,222,20] #Gold
  77.  
  78.  
  79. end
  80. #===========================================================================
  81. # *** End of Editable Region
  82. #===========================================================================
  83.    
  84. #===========================================================================
  85. # *** Class Window_MenuCommand
  86. #===========================================================================
  87. class Window_MenuCommand < Window_Command
  88.  
  89.   #-------------------------------------------------------------------------
  90.   # * Aliased Methods
  91.   #-------------------------------------------------------------------------
  92.   alias :clstn_add_main_commands_0003 add_main_commands
  93.  
  94.   #-------------------------------------------------------------------------
  95.   # * Method: add_main_commands
  96.   #-------------------------------------------------------------------------
  97.   def add_main_commands
  98.     clstn_add_main_commands_0003
  99.     add_command(Clstn_Currencies::Vocab_Menu,  :currencies,   main_commands_enabled)
  100.     #^Edit
  101.   end
  102.  
  103. end
  104.  
  105. #===========================================================================
  106. # ** Class Scene_Menu
  107. #===========================================================================
  108. class Scene_Menu < Scene_MenuBase
  109.  
  110.   #--------------------------------------------------------------------------
  111.   # * Start
  112.   #--------------------------------------------------------------------------
  113.   def start
  114.     super
  115.     create_command_window
  116.     create_status_window
  117.   end
  118.  
  119.   #-------------------------------------------------------------------------
  120.   # * Aliased Methods
  121.   #-------------------------------------------------------------------------
  122.   alias :clstn_create_command_window_0004 :create_command_window
  123.   alias :clstn_on_personal_ok_0008 :on_personal_ok
  124.  
  125.   #-------------------------------------------------------------------------
  126.   # * Method: create_command_window
  127.   #-------------------------------------------------------------------------
  128.   def create_command_window
  129.     clstn_create_command_window_0004
  130.     @command_window.set_handler(:currencies, method(:command_currencies))
  131.   end
  132.  
  133.    #-------------------------------------------------------------------------
  134.    # * Method: on_personal_ok
  135.    #-------------------------------------------------------------------------
  136.    def on_personal_ok
  137.     case @command_window.current_symbol
  138.     when :currencies
  139.       SceneManager.call(Scene_Currencies)
  140.     end
  141.     clstn_on_personal_ok_0008
  142.    end
  143.  
  144.    #-------------------------------------------------------------------------
  145.    # * Method: command_currencies
  146.    #-------------------------------------------------------------------------
  147.    def command_currencies
  148.       SceneManager.call(Scene_Currencies)
  149.    end
  150.  
  151. end
  152.  
  153. #===========================================================================
  154. # ** Class Scene_Currencies
  155. #===========================================================================
  156. class Scene_Currencies < Scene_MenuBase
  157.  
  158.   #-------------------------------------------------------------------------
  159.   # * Start
  160.   #-------------------------------------------------------------------------
  161.   def start
  162.     super
  163.     create_currencies_window
  164.   end
  165.  
  166.   #-------------------------------------------------------------------------
  167.   # * Method: create_currencies_window
  168.   #-------------------------------------------------------------------------
  169.   def create_currencies_window
  170.     @currencies_window = Window_Currencies.new
  171.     @currencies_window.viewport = @viewport
  172.     @currencies_window.set_handler(:cancel, method(:return_scene))
  173.     @currencies_window.activate
  174.   end
  175.  
  176. end
  177.  
  178. #===========================================================================
  179. # ** Class Window_Currencies
  180. #===========================================================================
  181. class Window_Currencies < Window_Selectable
  182.  
  183.   #-------------------------------------------------------------------------
  184.   # * Initialize
  185.   #-------------------------------------------------------------------------
  186.   def initialize
  187.     super(395,0,149,(Clstn_Currencies::Currencies.length + 1) * 36) #Edit
  188.     refresh
  189.   end
  190.  
  191.   #-------------------------------------------------------------------------
  192.   # * Method: value
  193.   #-------------------------------------------------------------------------
  194.   def value(currency_index = $game_temp.currency_index)
  195.     if currency_index == 0
  196.       $game_party.gold
  197.     else
  198.       $game_party.currency[currency_index]
  199.     end
  200.   end
  201.  
  202.   #-------------------------------------------------------------------------
  203.   # * Method: refresh
  204.   #-------------------------------------------------------------------------
  205.   def refresh
  206.     contents.clear
  207.     ct = Clstn_Currencies::ColorTitle #Edit
  208.     self.contents.font.color = Color.new(ct[0], ct[1], ct[2]) #Edit
  209.     draw_text(23, -4, 100, 30,Clstn_Currencies::Vocab_Menu) #Edit
  210.     draw_horz_line(0, 6)
  211.     draw_horz_line(3, 6)
  212.     i = 0
  213.     Clstn_Currencies::Currencies.each_value { |hash|
  214.         icon_index = hash[0]
  215.         draw_horz_line(37 + (32 * i), 0)
  216.         currency_unit = draw_icon(icon_index, 100, 32 + (32 * i))
  217.       draw_currency_value(value(i), currency_unit, -19, 33 + (32 * i), contents.width - 8)
  218.       i += 1
  219.     }
  220.   end
  221.  
  222.   #-------------------------------------------------------------------------
  223.   # * Method: draw_horz_line
  224.   #-------------------------------------------------------------------------
  225.   def draw_horz_line(dy, color)
  226.     color = text_color(color)
  227.     line_y = dy + line_height - 4
  228.     contents.fill_rect(4, line_y, contents_width - 8, 3, Font.default_out_color)
  229.     contents.fill_rect(5, line_y + 1, contents_width - 10, 1, color)
  230.   end
  231.  
  232. end
  233. #===========================================================================
  234. # ** Class Window_Gold
  235. #===========================================================================
  236. class Window_Gold < Window_Base
  237.  
  238.   #--------------------------------------------------------------------------
  239.   # * Refresh
  240.   #--------------------------------------------------------------------------
  241.   def refresh
  242.     draw_currency_value(value($game_temp.currency_index), currency_unit($game_temp.currency_index), -10, 0, contents.width - 8)
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # * Get Party Gold
  246.   #--------------------------------------------------------------------------
  247.   def value(currency_index = $game_temp.currency_index)
  248.     if currency_index == 0
  249.       $game_party.gold
  250.     else
  251.       $game_party.currency[currency_index]
  252.     end
  253.   end  
  254.   #--------------------------------------------------------------------------
  255.   # Get Currency Unit
  256.   #--------------------------------------------------------------------------
  257.   def currency_unit(currency_index = $game_temp.currency_index)
  258.       icon_index = Clstn_Currencies::Currencies[currency_index][0]
  259.       currency_unit = draw_icon(icon_index, 115, -1)
  260.   end
  261.  
  262. end
  263.  
  264. #===========================================================================
  265. # ** Class Game_Party
  266. #===========================================================================
  267. class Window_ShopNumber < Window_Selectable
  268.  
  269.   #-------------------------------------------------------------------------
  270.   # * Method: draw_total_price
  271.   #-------------------------------------------------------------------------
  272.   def draw_total_price
  273.     width = contents_width - 8
  274.     icon_index = Clstn_Currencies::Currencies[$game_temp.currency_index][0]
  275.     icon = draw_icon(icon_index, 255, 143)
  276.     draw_currency_value(@price * @number, icon, -15, price_y, width)
  277.   end
  278.  
  279. end
  280. #===========================================================================
  281. # ** Class Game_Party
  282. #===========================================================================
  283. class Game_Party < Game_Unit
  284.   attr_accessor :currency
  285.  
  286.   #-------------------------------------------------------------------------
  287.   # * Initialize
  288.   #-------------------------------------------------------------------------
  289.   def initialize
  290.     @currency = []
  291.     @gold = Clstn_Currencies::Currencies[0][1]
  292.     (Clstn_Currencies::Currencies.length).times { |i|   #Edit
  293.       if i == 0
  294.         @currency[i] = @gold
  295.       else
  296.         @currency[i] = Clstn_Currencies::Currencies[i][1]
  297.       end
  298.     }
  299.     @steps = 0
  300.     @last_item = Game_BaseItem.new
  301.     @menu_actor_id = 0
  302.     @target_actor_id = 0
  303.     @actors = []
  304.     init_all_items
  305.   end
  306.  
  307.   #-------------------------------------------------------------------------
  308.   # * Method: gain_gold
  309.   #-------------------------------------------------------------------------
  310.   def gain_gold(amount, currency_index = $game_temp.currency_index)
  311.     if currency_index != 0
  312.       @currency[currency_index] = [[@currency[currency_index] + amount, 0].max, max_gold].min
  313.     else
  314.       @gold = [[@gold + amount, 0].max, max_gold].min
  315.     end
  316.   end
  317.  
  318.   #-------------------------------------------------------------------------
  319.   # * Method: lose_gold
  320.   #-------------------------------------------------------------------------
  321.   def lose_gold(amount, currency_index = $game_temp.currency_index)
  322.       gain_gold(-amount, currency_index)
  323.   end
  324.  
  325. end
  326.  
  327. #===========================================================================
  328. # ** Class Game_Temp
  329. #===========================================================================
  330. class Game_Temp
  331.   attr_accessor :currency_index
  332.  
  333.   #--------------------------------------------------------------------------
  334.   # * Aliased Methods
  335.   #--------------------------------------------------------------------------
  336.   alias :clstn_initialize_0005 initialize
  337.  
  338.   #--------------------------------------------------------------------------
  339.   # * Initialize
  340.   #--------------------------------------------------------------------------
  341.   def initialize
  342.     @currency_index = 0
  343.     clstn_initialize_0005
  344.   end
  345.  
  346. end
  347.  
  348. #===========================================================================
  349. # ** Class Game_Temp
  350. #===========================================================================
  351. class Game_Interpreter
  352.  
  353.   #--------------------------------------------------------------------------
  354.   # * Method: add_currency
  355.   #--------------------------------------------------------------------------
  356.   def add_currency(amount, currency_index)
  357.     $game_party.gain_gold(amount, currency_index)
  358.   end
  359.  
  360.   #--------------------------------------------------------------------------
  361.   # * Method: currency
  362.   #--------------------------------------------------------------------------
  363.   def currency(currency_index)
  364.     $game_temp.currency_index = currency_index
  365.   end
  366.  
  367. end
RAW Paste Data