The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: gerkrt on July 14, 2011, 06:23:22 PM

Title: Multiparties script
Post by: gerkrt on July 14, 2011, 06:23:22 PM
I ported this multiparties script from VX to XP, can do things like FFVI, but also saving gold,
items,etc.

Code: text [Select]
#
#    Ported to Xp: gerkrt,gerrtunk
#   Created: modern algebra
#   Idea to port: TheRealDeal
#    By default, the original party is saved in $game_parties[0], so you may
#    want to avoid overwriting $game_parties[0] and just work with 1,2,...
#
#    Also, be very careful when dealing with parties. Always remember what
#    parties exist and where they are in $game_parties or else you may make a
#    stupid error occur.
#
#        *EXAMPLE EVENT*
#
#      @>Change Items: [Potion], + 1
#      @>Change Gold: + 50
#      @>Script: p = $game_parties[1]
#       :      : $game_party = p
#       :      : $game_player.refresh
#      @>Change Party Member: Add [Oscar], Initialize
#      @>Change Weapons: [Bastard Sword], +1
#      @>Change Gold: + 100
#
#    Assuming that $game_parties[1] did not previously exist, this event just
#    switched your party to the party with index 1, and if you looked at your
#    menu you would see that Oscar is in the party, you have 100 Gold, and a
#    Bastard Sword. The potion and the other 50 Gold went to the initial party
#
#    Now, let's say Oscar later meets up with his party and rejoins. Then this
#    event would do the trick:
#
#      @>Script: $game_parties.merge! (0, 1)
#       :      : $game_party = $game_parties[0]
#       :      : $game_player.refresh
#
#    And there, the two parties have been merged and everything that Oscar had
#    obtained goes to the party.
#==============================================================================
 
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  Summary of Changes:
#    new method - add_multiple_steps
#==============================================================================
 
class Game_Party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Add Multiple Steps
  #    amount : the amount of steps to add
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def add_multiple_steps (amount)
    @steps += amount
  end
end
 
#==============================================================================
# ** Game_Parties
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  This class handles Parties. It's a wrapper for the built-in class "Array."
#  It is accessed by $game_parties
#==============================================================================
 
class Game_Parties
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def initialize
    @data = [$game_party]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Retrieve Party
  #    id : the ID of the party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def [] (id)
    @data[id] = Game_Party.new if @data[id] == nil
    return @data[id]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def []= (id, party)
    # Does nothing unless it is a party object
    return unless party.class == Game_Party
    @data[id] = party
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Merge
  #    id_1 : the ID of the first party
  #    id_2 : the ID of the second party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def merge (id_1, id_2)
    new_party = Game_Party.new
    # Get old parties
    op1 = self[id_1]
    op2 = self[id_2]
    # Gold
    new_party.gain_gold (op1.gold + op2.gold)
    # Members
    (op1.members | op2.members).each { |actor| new_party.add_actor (actor.id) }
    # Items, Weapons, and Armor
    (op1.items | op2.items).each { |item|
      new_party.gain_item (item, op1.item_number (item) +  op2.item_number (item))
    }
    # Steps
    new_party.add_multiple_steps (op1.steps + op2.steps)
    # Last Item
    new_party.last_item_id = op1.last_item_id
    # Last Actor
    new_party.last_actor_index = op1.last_actor_index
    # Last Target
    new_party.last_target_index = op1.last_target_index
    # Quests (if game includes my Quest Log)
    begin
      (op1.quests.list | op2.quests.list).each { |quest|
        new_quest = new_party.quests[quest.id]
        # Reveal Objectives
        quest.revealed_objectives.each { |i| new_quest.reveal_objective (i) }
        # Complete Objectives
        quest.complete_objectives.each { |i| new_quest.complete_objective (i) }
        # Fail Objectives
        quest.failed_objectives.each { |i| new_quest.fail_objective (i) }
        # Concealed?
        new_quest.concealed = quest.concealed
        # Reward Given?
        new_quest.reward_given = quest.reward_given
      }
    rescue
    end
    return new_party
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Merge!
  #    id_1 : the ID of the first party to which the second party is merged
  #    id_2 : the ID of the second party that is deleted
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def merge! (id_1, id_2)
    @data[id_1] = merge (id_1, id_2)
    delete (id_2)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Delete
  #     id : the ID of the quest to be deleted
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def delete (id)
    @data[id] = nil
    # If this was the last in the array
    if id == @data.size - 1
      # Delete any nil elements that exist between this party and its successor
      id -= 1
      while @data[id] == nil
        @data.delete (id)
        id -= 1
      end
    end
  end
end
 
#==============================================================================
# ** Scene_Title
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - create_game_objects
#==============================================================================
 
class Scene_Title
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Create Game Objects
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias command_new_game_GP_alias command_new_game
  def command_new_game
    $game_parties      = Game_Parties.new
    command_new_game_GP_alias
  end
end
 
#==============================================================================
# ** Scene_Save
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods -  write_save_data
#==============================================================================
 
class Scene_Save
 
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Write Save Data
  #     file : write file object (opened)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_multiparty_wrt_sv_dta_6hye write_save_data
  def write_save_data(file)
    modalg_multiparty_wrt_sv_dta_6hye (file)
    Marshal.dump($game_parties,        file)
  end
end
 
#==============================================================================
# ** Scene_Load
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods - read_save_data
#==============================================================================
 
class Scene_Load
 
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Load Save Data
  #     file : file object for reading (opened)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_multiparty_rd_sv_dat_2gte read_save_data
  def read_save_data(file)
    modalg_multiparty_rd_sv_dat_2gte (file)
    $game_parties        = Marshal.load(file)
  end
end
 


Test this code well and tell me if anything is wrong.
Title: Re: Multiparties script
Post by: modern algebra on July 14, 2011, 07:27:39 PM
Looks good gekrt! Nice stuff :)
Title: Re: Multiparties script
Post by: pacdiggity on July 15, 2011, 01:05:21 AM
I think you can remove the part in the merge method that refers to the Quest Log, because it's a script for VX O.o
Title: Re: Multiparties script
Post by: Twb6543 on July 26, 2011, 09:51:49 AM
Made a small fix for the script on the Chaos-project topic, reposting it here.

Spoiler for:
Code: [Select]
#==============================================================================
#  Multiple Parties Xp
#  Version: 1.0b
#  Date: July 26, 2011
#  Ported by: gerkrt, gerrtunk
#  Small Fix by: Twb6543
#  Idea to port: TheRealDeal
#  Link:
#  http://forum.chaos-project.com/index.php/topic,10097
#
#  Original Author: modern algebra (rmrk.net)
#  Link to Original VX version:
#  http://rmrk.net/index.php/topic,25710.0.html
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Description:
#    This script allows you to maintain multiple parties (separate item lists, steps,
#    everything) and allows you to merge them at will. Primarily useful for a
#    game where parties split up or a game where you can have separate parties
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    Place this script under ? Materials in the Script Editor.
#    There are several codes to keep in mind:
#
#      $game_parties[id]                :accesses the party located in that index.
#                                       :creates it if it does not yet exist.
#      $game_parties[id] = X            :Sets the party to X. It MUST be a  
#                                       :Game_Party object
#      p = $game_parties.merge(id1,id2) :merges two parties and saves them in p
#      $game_parties.merge! (id1, id2)  :merges two parties and saves them in
#                                       :$game_parties[id1] and deletes $game_parties[id2]
#      $game_parties.delete (id)        :Deletes $game_parties[id]
#
#    In order to switch the current party, just do this:
#
#      $game_party = $game_parties[id]
#      $game_player.refresh
#
#    By default, the original party is saved in $game_parties[0], so you may
#    want to avoid overwriting $game_parties[0] and just work with 1,2,...
#
#    Also, be very careful when dealing with parties. Always remember what
#    parties exist and where they are in $game_parties or else you may make a
#    stupid error occur.
#
#        *EXAMPLE EVENT*
#
#      @>Change Items: [Potion], + 1
#      @>Change Gold: + 50
#      @>Script: p = $game_parties[1]
#       :      : $game_party = p
#       :      : $game_player.refresh
#      @>Change Party Member: Add [Oscar], Initialize
#      @>Change Weapons: [Bastard Sword], +1
#      @>Change Gold: + 100
#
#    Assuming that $game_parties[1] did not previously exist, this event just
#    switched your party to the party with index 1, and if you looked at your
#    menu you would see that Oscar is in the party, you have 100 Gold, and a
#    Bastard Sword. The potion and the other 50 Gold went to the initial party
#
#    Now, let's say Oscar later meets up with his party and rejoins. Then this
#    event would do the trick:
#
#      @>Script: $game_parties.merge! (0, 1)
#       :      : $game_party = $game_parties[0]
#       :      : $game_player.refresh
#
#    And there, the two parties have been merged and everything that Oscar had
#    obtained goes to the party.
#==============================================================================
 
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  Summary of Changes:
#    new method - add_multiple_steps
#==============================================================================
 
class Game_Party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Add Multiple Steps
  #    amount : the amount of steps to add
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def add_multiple_steps (amount)
    @steps += amount
  end
  
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # Adds a function from VX so the script works in XP
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def items
    result = []
    for i in @items.keys.sort
      result.push($data_items[i]) if @items[i] > 0
    end
    for i in @weapons.keys.sort
      result.push($data_weapons[i]) if @weapons[i] > 0
    end
    for i in @armors.keys.sort
      result.push($data_armors[i]) if @armors[i] > 0
    end
    return result
  end
  
end
 
#==============================================================================
# ** Game_Parties
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  This class handles Parties. It's a wrapper for the built-in class "Array."
#  It is accessed by $game_parties
#==============================================================================
 
class Game_Parties
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def initialize
    @data = [$game_party]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Retrieve Party
  #    id : the ID of the party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def [] (id)
    @data[id] = Game_Party.new if @data[id] == nil
    return @data[id]
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def []= (id, party)
    # Does nothing unless it is a party object
    return unless party.class == Game_Party
    @data[id] = party
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Merge
  #    id_1 : the ID of the first party
  #    id_2 : the ID of the second party
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def merge (id_1, id_2)
    new_party = Game_Party.new
    # Get old parties
    op1 = self[id_1]
    op2 = self[id_2]
    # Gold
    new_party.gain_gold (op1.gold + op2.gold)
    # Members
    (op1.actors | op2.actors).each { |actor| new_party.add_actor (actor.id) }
    # Items, Weapons, and Armor
    (op1.items | op2.items).each { |item|
      new_party.gain_item (item, op1.item_number (item) +  op2.item_number (item))
    }
    # Steps
    new_party.add_multiple_steps (op1.steps + op2.steps)
=begin
    # Not used in RPG Maker Xp
    # Last Item
    new_party.last_item_id = op1.last_item_id
    # Last Actor
    new_party.last_actor_index = op1.last_actor_index
    # Last Target
    new_party.last_target_index = op1.last_target_index
    
    # Quest Log was for Vx not Xp so cut out here.
    
=end
    return new_party
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Merge!
  #    id_1 : the ID of the first party to which the second party is merged
  #    id_2 : the ID of the second party that is deleted
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def merge! (id_1, id_2)
    @data[id_1] = merge (id_1, id_2)
    delete (id_2)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Delete
  #     id : the ID of the quest to be deleted
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def delete (id)
    @data[id] = nil
    # If this was the last in the array
    if id == @data.size - 1
      # Delete any nil elements that exist between this party and its successor
      id -= 1
      while @data[id] == nil
        @data.delete (id)
        id -= 1
      end
    end
  end
end
 
#==============================================================================
# ** Scene_Title
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - create_game_objects
#==============================================================================
 
class Scene_Title
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Create Game Objects
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias command_new_game_GP_alias command_new_game
  def command_new_game
    $game_parties      = Game_Parties.new
    command_new_game_GP_alias
  end
end
 
#==============================================================================
# ** Scene_Save
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods -  write_save_data
#==============================================================================
 
class Scene_Save
 
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Write Save Data
  #     file : write file object (opened)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_multiparty_wrt_sv_dta_6hye write_save_data
  def write_save_data(file)
    modalg_multiparty_wrt_sv_dta_6hye (file)
    Marshal.dump($game_parties,        file)
  end
end
 
#==============================================================================
# ** Scene_Load
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased methods - read_save_data
#==============================================================================
 
class Scene_Load
 
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Load Save Data
  #     file : file object for reading (opened)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_multiparty_rd_sv_dat_2gte read_save_data
  def read_save_data(file)
    modalg_multiparty_rd_sv_dat_2gte (file)
    $game_parties        = Marshal.load(file)
  end
end
 


ChangeLog:

- Fixed Merge definition,
- Changed the format of the instructions to match the original,
- Added Links to both Versions (VX and XP),
- Deleted QuestLog part as that questlog was for RMVX.
Title: Re: Multiparties script
Post by: FruitBodyWash on August 11, 2011, 09:50:58 PM
this is a noob question (and I guess I'm still kind of a noob), i would have asked in the stickied how to section, but it's locked, and this is a script i would really like to use.  I'm trying to paste it into it's own/new script (as I've done in the past) but when i paste, it puts it all on one line. It coudl just be an error on my end, something in rmxp, because I know it's worked before. I've tried selecting the code using the select button and selecting it all manually, not really sure what the problem is. Thanks for your help and makin this script :)

~~ Sorry about this (I think it's my computers incompatability with the code entry boxes on the forum, it isn't recognizing the lines as seperate (no return/enter key strokes) but I went in, following what i could see to make line breaks where your code shows, now to test, sorry for being a pest. .... ... it was no jest (.... hehe sorry)
Title: Re: Multiparties script
Post by: FruitBodyWash on August 12, 2011, 12:19:11 AM
sweet! got it working, thanks :) this is exactly what i was looking for :)
Title: Re: Multiparties script
Post by: XaineC on December 07, 2011, 05:44:08 PM
I know I'm kinda necroposting, but what would the script call be if I wanted to push the R button to scroll into another party and the L button to scroll back, say in a party changer.