Party Stealer

Harosata

Dramatic Lightning's BFF
Veteran
Joined
Aug 20, 2015
Messages
246
Reaction score
70
First Language
English
Primarily Uses
RMVXA
Date: Feb 21, 2020
Script Name:
Author: Harosata/Dramatic Lightning Co

Introduction:
This script will allow an event to "borrow" a party member (usually the leader). Using the script calls will turn on/off the D self-switch for that event.

Update:
Feb 22 - Added more functions. You can remove first or last follower. You can also see if event holds an actor, if any actor is missing on current/any map, and retrieving actors from current/any map.

How to Use:
1. Use the party_steal(state_id = 0, actor_id = 0) in your Event's script call to take away your party member. By default, your leader will be captured, but you can add a "display state" and you can take away a specific actor instead.

2. Use the party_return(state_id = 0) to return an actor to your party. The display state will be removed, but you can also add a new state upon their release. This does nothing if the event hasn't captured a party member. You can also use Add Party Member with similar results.

3. Use the party_relocate(actor_id, state_id = -1) to transfer the party member from one event to another. You can set the state_id to replace (or 0 to erase) the display state. This does nothing if the actor is not in another event.

4. Comment <ActorReplace> inside that event's page and the event can look like your borrowed party member. If you have a graphic-change script, it makes the state_ids above have more worth.

Additional:
-You can also script call $game_map.events[id].party_***** should you feel like certain events on the map can use this.
-You should be able to use a follower-touch script like Himework's Follower Touch Event to have the event take your followers instead.

Terms and Credit:
Free to use, nice to credit.

Ruby:
=begin
=begin
#===============================================================================
Title: Party Stealer
Author: Dramatic Lightning Co
Date: Feb 21, 2020
--------------------------------------------------------------------------------
Changelog:
-Feb 21, 2020 - Extended script
-- Using -1 or -2 as the actor id for party_steal lets you take the first/last
    follower if event touches player.
-- holds_member?(actor_id) returns true if the actor is assigned to that event.
-- lost_members?(all_map = false) returns true if the map has any lost members.
-- retrieve_lost_members(all_map = false) will add all members from that map.
  (if all_map is true, returns true if any member is considered missing or
   adds all missing members depending on the function)
--------------------------------------------------------------------------------

This script will use Self-Switch D.  If an event doesn't use the script calls,
you can still use this self-switch normally.  Also, note that the party
cannot be stolen if the party size is at 1.

When you use this script, use a party_steal script-call from a map event
or $game_map.events[id].party_steal to have that event "steal" your party leader
(with Himework's Follower Event Touch or similar, the event can steal a follower).
You can extend this with party_steal(state_id) to change the stolen member's
state (if you use a state-dependent character graphic script) and
party_steal(state_id, actor_id) if you want to steal a specifc actor instead.
(state_id can be set to 0 if you don't want to apply a state)
--------------------------------------------------------------------------------
You can use party_return or $game_map.events[id].party_return to return
the stolen member back to your party and remove their display state.
You can extend this with party_return(state_id) to add a new state upon
their release.  Alternatively, adding that character back with Add Actor
will reset the association with that event.

You can also use party_relocate(actor_id) or
$game_map.events[id].party_relocate(actor_id) to reassign the actor to that
event.  You can extend this with party_relocate(actor_id, state_id) if you want
to replace their display state (or remove that state with 0).
--------------------------------------------------------------------------------
You can also comment the "D" Event Page with <ActorReplace> to replace
the event's graphic with your character.  As stated above, you can use a
state-dependent character graphic script on your actor to affect that event's
appearance.  If you opt not to use this tag, the event's own appearance
will be used instead.

#===============================================================================
=end

module RPG
 
  class Event::Page
    def actor_replace
      @list.each {|cmd|
        if cmd.code == 108 && res = cmd.parameters[0].match(/<ActorReplace>/i)
          return true
        end
      }
      return false
    end
  end
end

class Game_Interpreter
  def party_steal(playerstate = 0,playerid = 0)
    $game_map.events[@event_id].party_steal(playerstate, playerid)
  end
  def party_return(playerstate = 0)
    $game_map.events[@event_id].party_return(playerstate)
  end
  def party_relocate(playerid, replace_state = -1)
    $game_map.events[@event_id].party_relocate(playerid, replace_state)
  end
  def holds_member?(actorid)
    return $game_map.events[@event_id].holds_member?(actorid)
  end
  def lost_members?(all_map = false)
    $game_party.lost_members?(all_map)
  end
  def retrieve_lost_members(all_map = false)
    $game_party.retrieve_lost_members(all_map)
  end
end

class Game_Party < Game_Unit
  attr_accessor :owned
  alias :dl_party_steal_initialize :initialize
  def initialize
    @owned = []
    dl_party_steal_initialize
  end
 
  alias :dl_party_steal_add_actor :add_actor
  def add_actor(actor_id)
    dl_party_steal_add_actor(actor_id)
    @owned.each_index do |i|
      a = $game_party.owned[i]
      next if a == nil
      if a[2] == actor_id
        $game_self_switches[[a[0], a[1],"D"]] = false
        $game_actors[a[2]].remove_state(a[3]) if a[3] > 0
        $game_party.owned[i] = nil
      end
    end
  end
 
  def lost_members?(all_map = false)
    if all_map
      return @owned.size > 0
    else
      return @owned.any? {|a| a[0] == $game_map.map_id}
    end
  end
 
  def retrieve_lost_members(all_map = false)
    $game_party.owned.each_index do |i|
      a = $game_party.owned[i]
      next if a == nil
      $game_party.add_actor(a[2]) if a[0] == $game_map.map_id or all_map
    end
     $game_party.owned = $game_party.owned.compact
  end
 
end

class Game_Event < Game_Character
 
  def holds_member?(actor_id)
    $game_party.owned.each_index do |i|
      a = $game_party.owned[i]
      next if a == nil
      return true if a[0] == @map_id and a[1] == @id and a[2] == actor_id
    end
    return false
  end

  def party_relocate(playerid, playerstate = -1)
    $game_party.owned.each_index do |i|
      a = $game_party.owned[i]
      next if a == nil
      if a[2] == playerid
        $game_self_switches[[a[0], a[1],"D"]] = false
        $game_actors[a[2]].remove_state(a[3]) if playerstate >= 0 and playerstate != a[3] and a[3] > 0
        if playerstate > 0 and playerstate != a[3]
          $game_actors[a[2]].add_state(playerstate)
          a[3] = playerstate
        end
        $game_party.owned[i] = [@map_id, @id, playerid, a[3]]
        $game_self_switches[[@map_id, @id,"D"]] = true
      end
    end
    $game_party.owned = $game_party.owned.compact
  end
 
  def party_return(playerstate = 0)
    $game_party.owned.each_index do |i|
      a = $game_party.owned[i]
      next if a == nil
      if a[0] == @map_id and a[1] == @id
        $game_actors[a[2]].add_state(playerstate) if playerstate > 0
        $game_party.add_actor(a[2])
      end
    end
    $game_party.owned = $game_party.owned.compact
  end
 
  def character_name
    if @page and @page.actor_replace
      $game_party.owned.each_index do |i|
        a = $game_party.owned[i]
        next if a == nil
        if a[0] == @map_id and a[1] == @id
          return $game_actors[a[2]].character_name
        end
      end
    end
    @character_name
  end
  def character_index
    if @page and @page.actor_replace
      $game_party.owned.each_index do |i|
        a = $game_party.owned[i]
        next if a == nil
        if a[0] == @map_id and a[1] == @id
          return $game_actors[a[2]].character_index
        end
      end
    end
    @character_index
  end
 
  def party_steal(playerstate = 0, playerid = 0)
    return unless $game_party.members.size > 1
    return if playerid < -2
    return if $game_party.owned.compact.any? {|a| a[0] == @map_id and a[1] == @id}
    if playerid == 0
      if in_front($game_player.x, $game_player.y)
        $game_party.owned << [@map_id, @id, $game_player.actor.id, playerstate]
        $game_player.actor.add_state(playerstate) if playerstate > 0
        $game_party.remove_actor($game_player.actor.id)
        $game_self_switches[[@map_id, @id,"D"]] = true
      end
      if $data_system.opt_followers
        $game_player.followers.each do |follower|
          if in_front(follower.x, follower.y)
            $game_party.owned << [@map_id, @id,follower.actor.id, playerstate]
            follower.actor.add_state(playerstate) if playerstate > 0
            $game_party.remove_actor(follower.actor.id)
            $game_self_switches[[@map_id, @id,"D"]] = true
            break
          end
        end
      end
    elsif playerid < 0
      follower = $game_player.followers[0]
      follower = $game_player.followers[-1] if playerid == -2
      if in_front($game_player.x, $game_player.y)
        $game_party.owned << [@map_id, @id,follower.actor.id, playerstate]
        follower.actor.add_state(playerstate) if playerstate > 0
        $game_party.remove_actor(follower.actor.id)
        $game_self_switches[[@map_id, @id,"D"]] = true
      end
    else
      $game_party.owned << [@map_id, @id, playerid, playerstate]
      $game_actors[playerid].add_state(playerstate) if playerstate > 0
      $game_party.remove_actor(playerid)
      $game_self_switches[[@map_id, @id,"D"]] = true
    end
    $game_party.owned = $game_party.owned.compact
  end
   
  def in_front(thisx, thisy)
    bob = distance_x_from(thisx).abs + distance_y_from(thisy).abs <= 1 #Diamont Direction 531
    bob = false if @direction == 2 and distance_y_from(thisy) >= 0
    bob = false if @direction == 4 and distance_x_from(thisx) <= 0
    bob = false if @direction == 6 and distance_x_from(thisx) >= 0
    bob = false if @direction == 8 and distance_y_from(thisy) <= 0
    return bob
  end 
end
Examples:
The classic "leave your party behind to watch" trick.
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
14,275
Reaction score
7,859
First Language
English
Primarily Uses
RMMV
@Harosata Please add terms of use and credits to your original post.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

It's weird I actually have MORE work to do when stuck at home than before.
The No Travel Game Jam is here! Jump in to make a game in the month of April that takes place all in one town!


Decided to take a stab at video editing.... Even made a clickbait screen. I'm so proud of my sellout ways. :LZSexcite:

Forum statistics

Threads
95,470
Messages
929,392
Members
125,711
Latest member
cst
Top