Advertisement
roninator2

Actor inventory Gold addon

Dec 18th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.44 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3.  Title: Actor Inventory - Gold
  4.  Mod: Roninator2
  5.  Latest Revision Date: Mar 29, 2022
  6. --------------------------------------------------------------------------------
  7.  ** Change log
  8.  Mar 29, 2022
  9.    - Removed improper reference
  10.  Mar 28, 2022
  11.    - Fixed lose gold error and added Battle gold/item fix
  12.  Mar 27, 2022
  13.    - Fixed lose gold and added Menu gold fix
  14.  Mar 23, 2022
  15.    - Initial release
  16. --------------------------------------------------------------------------------
  17.  ** Terms of Use
  18.  * Follow Tsukihime's original terms of use
  19. --------------------------------------------------------------------------------
  20.  ** Description
  21.  
  22.  This script is an add on to Hime's Actor Inventory script
  23.  
  24.  You will need to use script calls to add gold to members.
  25.  
  26.  This script does not provide any scenes or windows so you will need to
  27.  install other scripts that will provide those. This script also does not
  28.  provide a way to exchange items between actors.
  29.  
  30. --------------------------------------------------------------------------------
  31.  ** Required
  32.  
  33.  Core - Inventory
  34.  (http://himeworks.wordpress.com/2013/07/27/core-inventory/)
  35.  Actor Inventory
  36.  Shop Inventory
  37.  
  38. --------------------------------------------------------------------------------
  39.  ** Installation
  40.  
  41.  Place this script below Shop Inventory and above Main
  42.  All custom menus should be placed below the actor inventory scenes.
  43.  
  44. --------------------------------------------------------------------------------
  45.  ** Usage
  46.  
  47.  The following script calls are available:
  48.  
  49.    gain_gold(amount, actor_id)
  50.    lose_gold(amount, actor_id)
  51.  
  52.  Where `amount` is the amount of you want to add/remove, and
  53.  `actor_id` is the actor that you want to add to or remove from.
  54.  
  55.  Option to show the player name in the shop. Change setting below
  56.  to turn it on or off.
  57.  
  58. #===============================================================================
  59. =end
  60.  
  61. module R2_Gold_Shop_Actor
  62.  
  63.   Show_Name = true
  64.   Gold_Actors = 4
  65. end
  66.  
  67. $imported = {} if $imported.nil?
  68. $imported["TH_ActorInventory_Gold"] = true
  69. #===============================================================================
  70. # ** Rest of script
  71. #===============================================================================
  72.  
  73. class Game_Interpreter
  74.   def gain_gold(amount, actor_id)
  75.     $game_actors[actor_id].gain_gold(amount)
  76.   end
  77.   def lose_gold(amount, actor_id)
  78.     $game_actors[actor_id].lose_gold(amount)
  79.   end
  80. end
  81.  
  82. class Game_ActorInventory < Game_Inventory
  83.   attr_accessor :gold
  84.   alias r2_actor_inventory_gold_addon initialize
  85.   def initialize(actor)
  86.     r2_actor_inventory_gold_addon(actor)
  87.     @gold = 0
  88.   end
  89.   def gain_gold(amount)
  90.     @gold += amount
  91.   end
  92. end
  93.  
  94. class Game_Actor < Game_Battler
  95.   def inventory_gold
  96.     @inventory.gold
  97.   end
  98.   def gain_gold(amount)
  99.     @inventory.gain_gold(amount)
  100.   end
  101.   def lose_gold(amount)
  102.     @inventory.gold -= amount
  103.   end
  104. end
  105.  
  106. class Scene_Shop < Scene_MenuBase
  107.   alias :r2_actor_inventory_gold_start :start
  108.   def start
  109.     r2_actor_inventory_gold_start
  110.     create_dummy_actor_window if R2_Gold_Shop_Actor::Show_Name
  111.   end
  112.   def do_buy(number)
  113.     $game_actors[@actor.id].lose_gold(number * buying_price)
  114.     @actor.gain_item(@item, number)
  115.   end
  116.   def do_sell(number)
  117.     $game_actors[@actor.id].gain_gold(number * selling_price)
  118.     @actor.lose_item(@item, number)
  119.   end
  120.   def create_dummy_actor_window
  121.     x = @gold_window.x
  122.     y = @gold_window.y - @gold_window.height + 10
  123.     w = @gold_window.width
  124.     h = @gold_window.height - 10
  125.     @dummy_actor_window = Window_ActorStatus.new(x, y, w, h)
  126.     @dummy_actor_window.viewport = @viewport
  127.     @dummy_actor_window.actor = @actor
  128.   end
  129.   alias :r2_actor_gold_create_gold_window :create_gold_window
  130.   def create_gold_window
  131.     r2_actor_gold_create_gold_window
  132.     @gold_window.actor = $game_party.leader
  133.   end
  134.   alias :r2_actor_inventory_create_command_window :create_command_window
  135.   def create_command_window
  136.     r2_actor_inventory_create_command_window
  137.     @command_window.set_handler(:pagedown, method(:next_com_actor))
  138.     @command_window.set_handler(:pageup,   method(:prev_com_actor))
  139.   end
  140.   alias :r2_actor_inventory_create_category_window :create_category_window
  141.   def create_category_window
  142.     r2_actor_inventory_create_category_window
  143.     @category_window.set_handler(:pagedown, method(:next_cat_actor))
  144.     @category_window.set_handler(:pageup,   method(:prev_cat_actor))
  145.   end
  146.   def on_actor_command_change
  147.     @gold_window.actor = @actor
  148.     @gold_window.refresh
  149.     @dummy_actor_window.actor = @actor if R2_Gold_Shop_Actor::Show_Name
  150.     @dummy_actor_window.refresh if R2_Gold_Shop_Actor::Show_Name
  151.     @status_window.actor = @actor
  152.     @command_window.activate
  153.   end
  154.   def on_actor_category_change
  155.     @gold_window.actor = @actor
  156.     @gold_window.refresh
  157.     @dummy_actor_window.actor = @actor if R2_Gold_Shop_Actor::Show_Name
  158.     @dummy_actor_window.refresh if R2_Gold_Shop_Actor::Show_Name
  159.     @status_window.actor = @actor
  160.     @sell_window.actor = @actor
  161.     @sell_window.refresh
  162.     @category_window.activate
  163.   end
  164.   alias :r2_on_actor_change_gold  :on_actor_change
  165.   def on_actor_change
  166.     @gold_window.actor = @actor
  167.     @gold_window.refresh
  168.     @dummy_actor_window.actor = @actor if R2_Gold_Shop_Actor::Show_Name
  169.     @dummy_actor_window.refresh if R2_Gold_Shop_Actor::Show_Name
  170.     r2_on_actor_change_gold
  171.     @buy_window.money = money
  172.     @buy_window.refresh
  173.     @sell_window.refresh
  174.   end
  175.   def next_com_actor
  176.     @actor = $game_party.menu_actor_next
  177.     on_actor_command_change
  178.   end
  179.   def prev_com_actor
  180.     @actor = $game_party.menu_actor_prev
  181.     on_actor_command_change
  182.   end
  183.   def next_cat_actor
  184.     @actor = $game_party.menu_actor_next
  185.     on_actor_category_change
  186.   end
  187.   def prev_cat_actor
  188.     @actor = $game_party.menu_actor_prev
  189.     on_actor_category_change
  190.   end
  191. end
  192.  
  193. class Window_Gold < Window_Base
  194.   def initialize
  195.     super(0, 0, window_width, fitting_height(1))
  196.   end
  197.   def value
  198.     $game_actors[@actor.id].inventory_gold
  199.   end
  200.   def actor=(actor)
  201.     return if @actor == actor
  202.     @actor = actor
  203.     refresh
  204.   end
  205. end
  206.  
  207. class Window_ActorStatus < Window_Base
  208.   def initialize(x, y, width, height)
  209.     super(x, y, width, height)
  210.     @item = nil
  211.     @page_index = 0
  212.   end
  213.   def actor=(actor)
  214.     return if @actor == actor
  215.     @actor = actor
  216.     refresh
  217.   end
  218.   def refresh
  219.     contents.clear
  220.     draw_actor_info
  221.   end
  222.   def draw_actor_info
  223.     change_color(normal_color)
  224.     draw_text(0, 0, 160, line_height, @actor.name, 1)
  225.   end
  226.   def line_height
  227.     return 24
  228.   end
  229.   def standard_padding
  230.     return 5
  231.   end
  232. end
  233.  
  234. class Scene_Menu < Scene_MenuBase
  235.   def create_gold_window
  236.     @gold_window = Window_MenuGold.new
  237.     @gold_window.x = 0
  238.     @gold_window.y = Graphics.height - @gold_window.height
  239.   end
  240. end
  241.  
  242. class Window_MenuGold < Window_Base
  243.   def initialize
  244.     super(0, 0, window_width, fitting_height(R2_Gold_Shop_Actor::Gold_Actors))
  245.     refresh
  246.   end
  247.   def window_width
  248.     return 160
  249.   end
  250.   def standard_padding
  251.     return 5
  252.   end
  253.   def refresh
  254.     contents.clear
  255.     @memb = R2_Gold_Shop_Actor::Gold_Actors
  256.     for i in 0..@memb - 1
  257.       next if $game_party.members[i].nil?
  258.       id = $game_actors[$game_party.members[i].id].id
  259.       actor = $game_actors[id]
  260.       change_color(normal_color)
  261.       draw_text(0, line_height * i, 160, line_height, actor.name, 0)
  262.       draw_currency_value(value(id), currency_unit, 4, line_height * i, contents.width - 8)
  263.     end
  264.   end
  265.   def value(id)
  266.     $game_actors[id].inventory_gold
  267.   end
  268.   def currency_unit
  269.     Vocab::currency_unit
  270.   end
  271.   def open
  272.     refresh
  273.     super
  274.   end
  275. end
  276.  
  277. module BattleManager
  278.   def self.gain_gold
  279.     if $game_troop.gold_total > 0
  280.       div = $game_party.battle_members.size
  281.       funds = ($game_troop.gold_total / div).to_i
  282.       text = sprintf(Vocab::ObtainGold, funds)
  283.       $game_message.add('\.' + text)
  284.       $game_party.battle_members.each do |actor|
  285.         actor.gain_gold(funds)
  286.       end
  287.     end
  288.     wait_for_message
  289.   end
  290.   def self.gain_drop_items
  291.     div = $game_party.battle_members.size
  292.     $game_troop.make_drop_items.each do |item|
  293.       act = rand(div)
  294.       $game_party.battle_members[act].gain_item(item, 1)
  295.       $game_message.add(sprintf(Vocab::ObtainItem, item.name))
  296.     end
  297.     wait_for_message
  298.   end
  299. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement