neonblack

Dual Party v1.0

Aug 20th, 2012
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###--------------------------------------------------------------------------###
  2. #  Dual Party script                                                           #
  3. #  Version 1.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #  Requested by: xXx| - Kilim - | [420[MLG]]|xXx                               #
  9. #                                                                              #
  10. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  11. #  3.0 Unported License. To view a copy of this license, visit                 #
  12. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  13. #  Permissions beyond the scope of this license are available at               #
  14. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  15. #                                                                              #
  16. #      Contact:                                                                #
  17. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  18. ###--------------------------------------------------------------------------###
  19.  
  20. ###--------------------------------------------------------------------------###
  21. #      Revision information:                                                   #
  22. #  V1.0 - 8.20.2012                                                            #
  23. #   Wrote and debugged main script                                             #
  24. ###--------------------------------------------------------------------------###
  25.  
  26. ###--------------------------------------------------------------------------###
  27. #      Instructions:                                                           #
  28. #  Place this script in the "Materials" section of the scripts above main.     #
  29. #  This script allows you to have several parties with their own items and     #
  30. #  members.  Note that the first party will be the default created party       #
  31. #  all other parties have no members or items by default.                      #
  32. #                                                                              #
  33. #   switch_party(x)  - Switch the currently active party where "x" is the      #
  34. #                      party number.  The default party is part 0, so if you   #
  35. #                      have 3 parties, they would be parties 0, 1, and 2.      #
  36. #   merge_party(x)  - Combine party "x" with the currectly active party.       #
  37. #                     Adds the items, gold, and members of party "x" to the    #
  38. #                     current party and then empties party "x".                #
  39. ###--------------------------------------------------------------------------###
  40.  
  41. ###--------------------------------------------------------------------------###
  42. module CP         # Do not edit                                                #
  43. module DUAL_PARTY #  these lines.                                              #
  44. #                                                                              #
  45. ###-----                                                                -----###
  46. # Default number of parties to have.                                           #
  47. PARTIES = 2 # Default = 2                                                      #
  48. ###--------------------------------------------------------------------------###
  49.  
  50.  
  51. ###--------------------------------------------------------------------------###
  52. #  The following lines are the actual core code of the script.  While you are  #
  53. #  certainly invited to look, modifying it may result in undesirable results.  #
  54. #  Modify at your own risk!                                                    #
  55. ###--------------------------------------------------------------------------###
  56.  
  57.  
  58. end
  59. end
  60.  
  61. module DataManager
  62.   class << self  ## Alias the create objects spot.
  63.     alias cp_dual_party create_game_objects
  64.     alias cp_dual_loading extract_save_contents
  65.   end
  66.  
  67.   def self.create_game_objects
  68.     cp_dual_party  ## Sets up parts to store the new parties.
  69.     $game_all_parties   = Party_Storage.new
  70.     $game_party         = $game_all_parties.active_party
  71.   end
  72.  
  73.   def self.make_save_contents
  74.     contents = {}
  75.     contents[:system]        = $game_system
  76.     contents[:timer]         = $game_timer
  77.     contents[:message]       = $game_message
  78.     contents[:switches]      = $game_switches
  79.     contents[:variables]     = $game_variables
  80.     contents[:self_switches] = $game_self_switches
  81.     contents[:actors]        = $game_actors
  82.     contents[:party]         = $game_party
  83.     contents[:troop]         = $game_troop
  84.     contents[:map]           = $game_map
  85.     contents[:player]        = $game_player
  86.    
  87.     ## Added.
  88.     contents[:parties]       = $game_all_parties
  89.     contents
  90.   end
  91.  
  92.   def self.extract_save_contents(contents)
  93.     cp_dual_loading(contents)  ## Load the parties container.
  94.     $game_all_parties   = contents[:parties]
  95.   end
  96. end
  97.  
  98. class Game_Interpreter
  99.   def switch_party(num)  ## Switch the parties.
  100.     $game_all_parties.switch_party(num)
  101.     $game_party = $game_all_parties.active_party
  102.     $game_player.refresh
  103.     $game_map.need_refresh = true
  104.   end
  105.  
  106.   def merge_party(num)
  107.     $game_all_parties.merge_party(num)
  108.     $game_player.refresh
  109.     $game_map.need_refresh = true
  110.   end
  111. end
  112.  
  113. class Party_Storage
  114.   attr_reader :active
  115.  
  116.   def initialize
  117.     @groups = []  ## Sets up the default containers.
  118.     @active = 0
  119.     create_all_groups
  120.   end
  121.  
  122.   def create_all_groups
  123.     number.times do  ## Creates all the default parties.
  124.       @groups.push(Game_Party.new)
  125.     end
  126.   end
  127.  
  128.   def active_party  ## Gets the active party.
  129.     @groups[@active]
  130.   end
  131.  
  132.   def switch_party(num)
  133.     @active = num  ## Change the party to the user defined party.
  134.     @active = 0 if @active < 0
  135.     while (@active > 0 && @groups[@active].nil?)
  136.       @active -= 1
  137.     end
  138.   end
  139.  
  140.   def merge_party(num)
  141.     return if @groups[num].nil?
  142.     return if num == @active
  143.     unless @groups[num].items.nil? || @groups[num].items.empty?
  144.       @groups[num].items.each do |k|
  145.         i = @groups[num].item_number(k)
  146.         @groups[@active].gain_item(k, i)
  147.       end
  148.     end
  149.     unless @groups[num].weapons.nil? || @groups[num].weapons.empty?
  150.       @groups[num].weapons.each do |k|
  151.         i = @groups[num].item_number(k)
  152.         @groups[@active].gain_item(k, i)
  153.       end
  154.     end
  155.     unless @groups[num].armors.nil? || @groups[num].armors.empty?
  156.       @groups[num].armors.each do |k|
  157.         i = @groups[num].item_number(k)
  158.         @groups[@active].gain_item(k, i)
  159.       end
  160.     end
  161.     unless @groups[num].members.nil? || @groups[num].members.empty?
  162.       @groups[num].members.each do |actor|
  163.         @groups[@active].add_actor(actor.id)
  164.       end
  165.     end
  166.     @groups[@active].gain_gold(@groups[num].gold)
  167.     @groups[num].reset_party
  168.   end
  169.  
  170.   def number  ## Get the default number of parties.
  171.     CP::DUAL_PARTY::PARTIES
  172.   end
  173. end
  174.  
  175. class Game_Party < Game_Unit
  176.   def reset_party
  177.     @items = {}
  178.     @weapons = {}
  179.     @armors = {}
  180.     @actors = []
  181.     @gold = 0
  182.   end
  183. end
  184.  
  185.  
  186. ###--------------------------------------------------------------------------###
  187. #  End of script.                                                              #
  188. ###--------------------------------------------------------------------------###
RAW Paste Data