Advertisement
mrbubble

Party Guests

Jun 25th, 2012
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.86 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Party Guests ++                                            v1.1 (7/13/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble
  6. #--------------------------------------------------------------------------
  7. # This script allows you to have actors as guests in the party
  8. # similarly to various console RPGs. A custom window is added to the
  9. # menu that displays current guests in the party.
  10. #
  11. # Party guests do not require special tags in their noteboxes. They are
  12. # simply actors put into a "guests" group within the party which is
  13. # seperate from any of your battle or reserve members. Because of
  14. # this, guests are not eligible to be chosen for battle at all.
  15. #
  16. # Since guests are just glorified actors, names, face graphics,
  17. # sprite graphics, etc. are defined in the Actors tab in the database
  18. # like normal. Those settings are then used in various display windows
  19. # related to guests.
  20. #
  21. # Guests provide no special effects to the party. However, other existing
  22. # scripts can provide effects if desired.
  23. #
  24. # If an actor is already in the main party and is placed into the
  25. # guest group, the actor will automatically be removed from the
  26. # main party. The same is true vice versa.
  27. #--------------------------------------------------------------------------
  28. #   ++ Changelog ++
  29. #--------------------------------------------------------------------------
  30. # v1.1 : Fixed guest_in_party? Script Call.
  31. #      : Changed instance variable name for Guest ID array. (7/13/2012)
  32. # v1.0 : Initial release. (6/25/2012)
  33. #--------------------------------------------------------------------------
  34. #   ++ Installation ++
  35. #--------------------------------------------------------------------------
  36. # Install this script in the Materials section in your project's
  37. # script editor.
  38. #--------------------------------------------------------------------------
  39. #   ++ Script Calls ++
  40. #--------------------------------------------------------------------------
  41. # The following script calls are meant to be used in "Script..."
  42. # event commands found under Tab 3 when creating a new event.
  43. #
  44. # add_guest(actor_id)
  45. #   Adds an actor to the party guest group. If the actor is already in the
  46. #   main party, the actor will automatically be removed from the main
  47. #   party before being added to the guest group.
  48. #  
  49. # remove_guest(actor_id)
  50. #   Removes the actor from the guest group.
  51. #
  52. # remove_all_guests
  53. #   Removes all actors from the guest group.
  54. #
  55. #--------------------------------------------------------------------------
  56. #   ++ Conditional Branch Script Calls ++
  57. #--------------------------------------------------------------------------
  58. # The following script calls are meant to be used in Conditional
  59. # Branch event commands within the Tab 4 "Script" box.
  60. # Each of these script calls will turn the given Game Switch ON
  61. # or OFF, where ON is true and OFF is false.
  62. #  
  63. # guest_in_party?(actor_id)
  64. #   Checks whether the given actor is a guest in the party.
  65. #
  66. #--------------------------------------------------------------------------
  67. #   ++ Compatibility ++
  68. #--------------------------------------------------------------------------
  69. # This script aliases the following default VXA methods:
  70. #
  71. #     Game_Party#initialize
  72. #     Game_Party#add_actor
  73. #
  74. # There are no default method overwrites.
  75. #
  76. # Requests for compatibility with other scripts are welcome.
  77. #--------------------------------------------------------------------------
  78. #   ++ Terms and Conditions ++
  79. #--------------------------------------------------------------------------
  80. # Please do not repost this script elsewhere without permission.
  81. # Free for non-commercial use. For commercial use, contact me first.
  82. #
  83. # Newest versions of this script can be found at
  84. #                                           http://mrbubblewand.wordpress.com/
  85. #==============================================================================
  86.  
  87. $imported = {} if $imported.nil?
  88. $imported["BubsPartyGuests"] = true
  89.  
  90. #==========================================================================
  91. # ++ START OF USER CUSTOMIZATION MODULE ++
  92. #==========================================================================
  93. module Bubs
  94.   #==========================================================================
  95.   # ++ Party Guests Settings
  96.   #==========================================================================
  97.   module PartyGuests
  98.    
  99.   #--------------------------------------------------------------------------
  100.   #   Guest Limit
  101.   #--------------------------------------------------------------------------
  102.   # The maximum number of guests that can accompany the party.
  103.   #   !! Use caution when adding too many guests to the party since
  104.   #   !! the Guests window in the menu is not currently suited to handle
  105.   #   !! a large amount of guests to display.
  106.   MAX_GUESTS = 2
  107.  
  108.   #--------------------------------------------------------------------------
  109.   #   Guest Window Label Text
  110.   #--------------------------------------------------------------------------
  111.   GUEST_WINDOW_TEXT = "Guests"
  112.   #--------------------------------------------------------------------------
  113.   #   Guest Window Display Style
  114.   #--------------------------------------------------------------------------
  115.   # Determines the style in which Guests are shown in the Guests window
  116.   # 0 : Show Guest face portraits
  117.   # 1 : Show Guest map sprites
  118.   GUEST_WINDOW_STYLE = 0
  119.   #--------------------------------------------------------------------------
  120.   #   Hide Guest Window When No Guests
  121.   #--------------------------------------------------------------------------
  122.   # true  : The Guest window will be hidden when there are no guests
  123.   # false : The Guest window will still be visible when there are no guests
  124.   HIDE_WINDOW_WHEN_NO_GUESTS = false
  125.  
  126.   end # module PartyGuests
  127. end # module Bubs
  128.  
  129. #==========================================================================
  130. # ++ END OF USER CUSTOMIZATION MODULE ++
  131. #==========================================================================
  132.  
  133.  
  134.  
  135. #==========================================================================
  136. # ++ Game_Party
  137. #==========================================================================
  138. class Game_Party < Game_Unit
  139.   attr_accessor :guest_ids
  140.   #--------------------------------------------------------------------------
  141.   # alias : initialize
  142.   #--------------------------------------------------------------------------
  143.   alias initialize_bubs_party_guests initialize
  144.   def initialize
  145.     initialize_bubs_party_guests # alias
  146.    
  147.     @guest_ids = []
  148.   end
  149.    
  150.   #--------------------------------------------------------------------------
  151.   # new method : guests
  152.   #--------------------------------------------------------------------------
  153.   def guests
  154.     @guest_ids.collect {|id| $game_actors[id] }
  155.   end
  156.  
  157.   #--------------------------------------------------------------------------
  158.   # new method : party_guests
  159.   #--------------------------------------------------------------------------
  160.   def party_guests
  161.     @guest_ids
  162.   end
  163.  
  164.   #--------------------------------------------------------------------------
  165.   # new method : add_guest
  166.   #--------------------------------------------------------------------------
  167.   def add_guest(actor_id)
  168.     return if @guest_ids.size >= max_guests
  169.     return if @guest_ids.include?(actor_id)
  170.    
  171.     remove_actor(actor_id)
  172.     @guest_ids.push(actor_id)
  173.     $game_player.refresh
  174.     $game_map.need_refresh = true
  175.   end
  176.  
  177.   #--------------------------------------------------------------------------
  178.   # new method : remove_guest
  179.   #--------------------------------------------------------------------------
  180.   def remove_guest(actor_id)
  181.     @guest_ids.delete(actor_id)
  182.     $game_player.refresh
  183.     $game_map.need_refresh = true
  184.   end
  185.  
  186.   #--------------------------------------------------------------------------
  187.   # alias : add_actor
  188.   #--------------------------------------------------------------------------
  189.   alias add_actor_bubs_party_guests add_actor
  190.   def add_actor(actor_id)
  191.     remove_guest(actor_id)
  192.     add_actor_bubs_party_guests(actor_id) # alias
  193.   end
  194.  
  195.   #--------------------------------------------------------------------------
  196.   # new method : max_guests
  197.   #--------------------------------------------------------------------------
  198.   def max_guests
  199.     return Bubs::PartyGuests::MAX_GUESTS
  200.   end
  201. end # class Game_Party
  202.  
  203.  
  204. #==========================================================================
  205. # ++ Window_PartyGuests
  206. #==========================================================================
  207. class Window_PartyGuests < Window_Base
  208.   #--------------------------------------------------------------------------
  209.   # * Object Initialization
  210.   #--------------------------------------------------------------------------
  211.   def initialize
  212.     super(0, 0, window_width, window_height)
  213.     refresh
  214.   end
  215.  
  216.   #--------------------------------------------------------------------------
  217.   # window_width
  218.   #--------------------------------------------------------------------------
  219.   def window_width
  220.     return 160
  221.   end
  222.  
  223.   #--------------------------------------------------------------------------
  224.   # height
  225.   #--------------------------------------------------------------------------
  226.   def window_height
  227.     fitting_height(guest_window_height)
  228.   end
  229.  
  230.   #--------------------------------------------------------------------------
  231.   # new method : guest_window_height
  232.   #--------------------------------------------------------------------------
  233.   def guest_window_height
  234.     fh = 1
  235.     case Bubs::PartyGuests::GUEST_WINDOW_STYLE
  236.     when 0
  237.       fh = 1 + ($game_party.guest_ids.size * 2)
  238.     when 1
  239.       fh = $game_party.guest_ids.empty? ? 1 : 3
  240.     end
  241.   end
  242.  
  243.   #--------------------------------------------------------------------------
  244.   # refresh
  245.   #--------------------------------------------------------------------------
  246.   def refresh
  247.     contents.clear
  248.     draw_party_guest_text
  249.     draw_party_guests
  250.   end
  251.  
  252.   #--------------------------------------------------------------------------
  253.   # new method : draw_party_guests
  254.   #--------------------------------------------------------------------------
  255.   def draw_party_guests
  256.     case Bubs::PartyGuests::GUEST_WINDOW_STYLE
  257.     when 0
  258.       draw_party_guest_faces
  259.     when 1
  260.       draw_party_guest_graphics
  261.     end
  262.   end
  263.  
  264.   #--------------------------------------------------------------------------
  265.   # new method : draw_party_guest_faces
  266.   #--------------------------------------------------------------------------
  267.   def draw_party_guest_faces
  268.     $game_party.guests.each_with_index { |actor, i|
  269.       draw_actor_half_face(actor, 20, 48 * i + line_height)
  270.     }
  271.   end
  272.  
  273.   #--------------------------------------------------------------------------
  274.   # new method : draw_party_guest_graphic
  275.   #--------------------------------------------------------------------------
  276.   def draw_party_guest_graphics
  277.     $game_party.guests.each_with_index { |actor, i|
  278.       draw_actor_graphic(actor, 32 * i + 20, 24 * 3)
  279.     }
  280.   end
  281.  
  282.   #--------------------------------------------------------------------------
  283.   # new method : draw_party_guest_text
  284.   #--------------------------------------------------------------------------
  285.   def draw_party_guest_text
  286.     change_color(system_color)
  287.     draw_text(0, 0, 160, line_height, Bubs::PartyGuests::GUEST_WINDOW_TEXT)
  288.   end
  289.  
  290.   #--------------------------------------------------------------------------
  291.   # new method : draw_actor_half_face
  292.   #--------------------------------------------------------------------------
  293.   def draw_actor_half_face(actor, x, y, enabled = true)
  294.     draw_half_face(actor.face_name, actor.face_index, x, y, enabled)
  295.   end
  296.  
  297.   #--------------------------------------------------------------------------
  298.   # new method : draw_half_face
  299.   #--------------------------------------------------------------------------
  300.   def draw_half_face(face_name, face_index, x, y, enabled = true)
  301.     bitmap = Cache.face(face_name)
  302.     rect = Rect.new(face_index % 4 * 96, face_index / 4 * 96 + 32, 96, 46)
  303.     contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
  304.     bitmap.dispose
  305.   end
  306.  
  307.   #--------------------------------------------------------------------------
  308.   # open
  309.   #--------------------------------------------------------------------------
  310.   def open
  311.     refresh
  312.     super
  313.   end
  314. end # class Window_PartyGuests
  315.  
  316.  
  317. #==========================================================================
  318. # ++ Scene_Menu
  319. #==========================================================================
  320. class Scene_Menu < Scene_MenuBase
  321.   #--------------------------------------------------------------------------
  322.   # alias : start
  323.   #--------------------------------------------------------------------------
  324.   alias start_bubs_party_guests start
  325.   def start
  326.     start_bubs_party_guests # alias
  327.    
  328.     create_guest_window
  329.   end
  330.  
  331.   #--------------------------------------------------------------------------
  332.   # new method : create_guest_window
  333.   #--------------------------------------------------------------------------
  334.   def create_guest_window
  335.     return if $game_party.guests.empty? && Bubs::PartyGuests::HIDE_WINDOW_WHEN_NO_GUESTS
  336.    
  337.     @guest_window = Window_PartyGuests.new
  338.     @guest_window.x = 0
  339.     @guest_window.y = Graphics.height - @gold_window.height - @guest_window.height
  340.   end
  341. end # class Scene_Menu
  342.  
  343. #==========================================================================
  344. # ++ Game_Actor
  345. #==========================================================================
  346. class Game_Actor < Game_Battler
  347.   #--------------------------------------------------------------------------
  348.   # new method : guest?
  349.   #--------------------------------------------------------------------------
  350.   def guest?
  351.     $game_party.guest_ids.include?(@actor_id)
  352.   end
  353. end # class Game_Actor
  354.  
  355. #==========================================================================
  356. # ++ Game_BattlerBase
  357. #==========================================================================
  358. class Game_BattlerBase
  359.   #--------------------------------------------------------------------------
  360.   # new method : guest?
  361.   #--------------------------------------------------------------------------
  362.   def guest?
  363.     return false
  364.   end
  365. end # class Game_BattlerBase
  366.  
  367.  
  368. #==========================================================================
  369. # ++ Game_Interpreter
  370. #==========================================================================
  371. class Game_Interpreter
  372.   #--------------------------------------------------------------------------
  373.   # new method : remove_all_guests
  374.   #--------------------------------------------------------------------------
  375.   def remove_all_guests
  376.     $game_party.guest_ids.clear
  377.   end
  378.   alias remove_all_guest remove_all_guests
  379.  
  380.   #--------------------------------------------------------------------------
  381.   # new method : add_guest
  382.   #--------------------------------------------------------------------------
  383.   def add_guest(actor_id)
  384.     $game_party.add_guest(actor_id)
  385.   end
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # new method : remove_guest
  389.   #--------------------------------------------------------------------------
  390.   def remove_guest(actor_id)
  391.     $game_party.remove_guest(actor_id)
  392.   end
  393.  
  394.   #--------------------------------------------------------------------------
  395.   # new method : guest_in_party?
  396.   #--------------------------------------------------------------------------
  397.   def guest_in_party?(actor_id)
  398.     $game_party.guest_ids.include?(actor_id)
  399.   end
  400.   alias has_guest? guest_in_party?
  401.   alias have_guest? guest_in_party?
  402. end # class Game_Interpreter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement