Multiparties script

I ported this multiparties script from VX to XP, can do things like FFVI, but also saving gold,
items,etc.

  1. #
  2. #    Ported to Xp: gerkrt,gerrtunk
  3. #   Created: modern algebra
  4. #   Idea to port: TheRealDeal
  5. #    By default, the original party is saved in $game_parties[0], so you may
  6. #    want to avoid overwriting $game_parties[0] and just work with 1,2,...
  7. #
  8. #    Also, be very careful when dealing with parties. Always remember what
  9. #    parties exist and where they are in $game_parties or else you may make a
  10. #    stupid error occur.
  11. #
  12. #        *EXAMPLE EVENT*
  13. #
  14. #      @>Change Items: [Potion], + 1
  15. #      @>Change Gold: + 50
  16. #      @>Script: p = $game_parties[1]
  17. #       :      : $game_party = p
  18. #       :      : $game_player.refresh
  19. #      @>Change Party Member: Add [Oscar], Initialize
  20. #      @>Change Weapons: [Bastard Sword], +1
  21. #      @>Change Gold: + 100
  22. #
  23. #    Assuming that $game_parties[1] did not previously exist, this event just
  24. #    switched your party to the party with index 1, and if you looked at your
  25. #    menu you would see that Oscar is in the party, you have 100 Gold, and a
  26. #    Bastard Sword. The potion and the other 50 Gold went to the initial party
  27. #
  28. #    Now, let's say Oscar later meets up with his party and rejoins. Then this
  29. #    event would do the trick:
  30. #
  31. #      @>Script: $game_parties.merge! (0, 1)
  32. #       :      : $game_party = $game_parties[0]
  33. #       :      : $game_player.refresh
  34. #
  35. #    And there, the two parties have been merged and everything that Oscar had
  36. #    obtained goes to the party.
  37. #==============================================================================
  38.  
  39. #==============================================================================
  40. # ** Game_Party
  41. #------------------------------------------------------------------------------
  42. #  Summary of Changes:
  43. #    new method - add_multiple_steps
  44. #==============================================================================
  45.  
  46. class Game_Party
  47.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48.   # * Add Multiple Steps
  49.   #    amount : the amount of steps to add
  50.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51.   def add_multiple_steps (amount)
  52.     @steps += amount
  53.   end
  54. end
  55.  
  56. #==============================================================================
  57. # ** Game_Parties
  58. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. #  This class handles Parties. It's a wrapper for the built-in class "Array."
  60. #  It is accessed by $game_parties
  61. #==============================================================================
  62.  
  63. class Game_Parties
  64.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65.   # * Object Initialization
  66.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67.   def initialize
  68.     @data = [$game_party]
  69.   end
  70.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  71.   # * Retrieve Party
  72.   #    id : the ID of the party
  73.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74.   def [] (id)
  75.     @data[id] = Game_Party.new if @data[id] == nil
  76.     return @data[id]
  77.   end
  78.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79.   # * Set Party
  80.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81.   def []= (id, party)
  82.     # Does nothing unless it is a party object
  83.     return unless party.class == Game_Party
  84.     @data[id] = party
  85.   end
  86.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87.   # * Merge
  88.   #    id_1 : the ID of the first party
  89.   #    id_2 : the ID of the second party
  90.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91.   def merge (id_1, id_2)
  92.     new_party = Game_Party.new
  93.     # Get old parties
  94.     op1 = self[id_1]
  95.     op2 = self[id_2]
  96.     # Gold
  97.     new_party.gain_gold (op1.gold + op2.gold)
  98.     # Members
  99.     (op1.members | op2.members).each { |actor| new_party.add_actor (actor.id) }
  100.     # Items, Weapons, and Armor
  101.     (op1.items | op2.items).each { |item|
  102.       new_party.gain_item (item, op1.item_number (item) +  op2.item_number (item))
  103.     }
  104.     # Steps
  105.     new_party.add_multiple_steps (op1.steps + op2.steps)
  106.     # Last Item
  107.     new_party.last_item_id = op1.last_item_id
  108.     # Last Actor
  109.     new_party.last_actor_index = op1.last_actor_index
  110.     # Last Target
  111.     new_party.last_target_index = op1.last_target_index
  112.     # Quests (if game includes my Quest Log)
  113.     begin
  114.       (op1.quests.list | op2.quests.list).each { |quest|
  115.         new_quest = new_party.quests[quest.id]
  116.         # Reveal Objectives
  117.         quest.revealed_objectives.each { |i| new_quest.reveal_objective (i) }
  118.         # Complete Objectives
  119.         quest.complete_objectives.each { |i| new_quest.complete_objective (i) }
  120.         # Fail Objectives
  121.         quest.failed_objectives.each { |i| new_quest.fail_objective (i) }
  122.         # Concealed?
  123.         new_quest.concealed = quest.concealed
  124.         # Reward Given?
  125.         new_quest.reward_given = quest.reward_given
  126.       }
  127.     rescue
  128.     end
  129.     return new_party
  130.   end
  131.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132.   # * Merge!
  133.   #    id_1 : the ID of the first party to which the second party is merged
  134.   #    id_2 : the ID of the second party that is deleted
  135.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136.   def merge! (id_1, id_2)
  137.     @data[id_1] = merge (id_1, id_2)
  138.     delete (id_2)
  139.   end
  140.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141.   # * Delete
  142.   #     id : the ID of the quest to be deleted
  143.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144.   def delete (id)
  145.     @data[id] = nil
  146.     # If this was the last in the array
  147.     if id == @data.size - 1
  148.       # Delete any nil elements that exist between this party and its successor
  149.       id -= 1
  150.       while @data[id] == nil
  151.         @data.delete (id)
  152.         id -= 1
  153.       end
  154.     end
  155.   end
  156. end
  157.  
  158. #==============================================================================
  159. # ** Scene_Title
  160. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. #  Summary of Changes:
  162. #    aliased method - create_game_objects
  163. #==============================================================================
  164.  
  165. class Scene_Title
  166.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.   # * Create Game Objects
  168.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169.   alias command_new_game_GP_alias command_new_game
  170.   def command_new_game
  171.     $game_parties      = Game_Parties.new
  172.     command_new_game_GP_alias
  173.   end
  174. end
  175.  
  176. #==============================================================================
  177. # ** Scene_Save
  178. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179. #  Summary of Changes:
  180. #    aliased methods -  write_save_data
  181. #==============================================================================
  182.  
  183. class Scene_Save
  184.  
  185.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186.   # * Write Save Data
  187.   #     file : write file object (opened)
  188.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189.   alias modalg_multiparty_wrt_sv_dta_6hye write_save_data
  190.   def write_save_data(file)
  191.     modalg_multiparty_wrt_sv_dta_6hye (file)
  192.     Marshal.dump($game_parties,        file)
  193.   end
  194. end
  195.  
  196. #==============================================================================
  197. # ** Scene_Load
  198. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  199. #  Summary of Changes:
  200. #    aliased methods - read_save_data
  201. #==============================================================================
  202.  
  203. class Scene_Load
  204.  
  205.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206.   # * Load Save Data
  207.   #     file : file object for reading (opened)
  208.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209.   alias modalg_multiparty_rd_sv_dat_2gte read_save_data
  210.   def read_save_data(file)
  211.     modalg_multiparty_rd_sv_dat_2gte (file)
  212.     $game_parties        = Marshal.load(file)
  213.   end
  214. end
  215.  
Expand to see the code.


Test this code well and tell me if anything is wrong.
Interesting, might help me with something in my game. Thanks!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75073