Help - Search - Members - Calendar
Full Version: Attacking Allies (solved)
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
LostSamurai
I was wondering if it was possible to allow/modify the attack command (using RMXP's default battle system) to allow targeting allies rather than just enemies.

I need this for one particular fight only, and I would like to apply it only to one battle.

This is extremely crucial for my game, please help! biggrin.gif

It would be extremely beneficial if I could also make harmful spells target allies for this one particular fight as well, but that's not necessary.
Jens of Zanicuud
This could be done, but requires a bit of scripting, since you should modify:

classes
Arrow_Enemy
Arrow_Actor
Scene_Battle 3

I've no time ATM, but if you wait three/four days, I can script it.
Before this, I need to know what Battle System you are using.
Without this info, nobody could create a system like this without finding compatibilities issues...

Well, let me know...

Jens
LostSamurai
I'm using the RMXP default battle system. I have a few scripts modifying the battle system (sandgolem quicker combat, sandgolem levelup animation, jens009 view SP recovery, jens009 defend restores SP, and sandgolem autobattle.) I don't think any of them modify the scripts you're mentioning, so it should be compatible.

Also, would it be possible to make this only apply for one battle? There's only one battle in my game that requires attacking your own allies.
Jens of Zanicuud
Urgh! Xcuse me, but this sounds... terrible. In my opinion, you should keep this setting active, it's the player choosing what to do. If he/she is dumb enough to attack their allies when not needed, well, it would not be your fault.

You provide the mechanics, how to use them is to the player smile.gif

Ok, then. Wait four days and I'll script it.

Jens
LostSamurai
Very true. I didn't think about that. Not to mention, if all of a sudden you can attack your allies for one battle, the puzzle will be pretty obvious. hehe

Thank you very much. I look forward to this smile.gif
Jens of Zanicuud
I've not forgotten your request, but I have to adapt one of my old scripts to fulfill it.
When I finish it, I'll reply here.

Jens
Vexus
Give this script a try maybe it works:

http://forum.chaos-project.com/index.php?topic=2506.0
TheCableGuy
If it's only for one battle, sounds like you could do better with an Event. Make a Doppelganger Enemy and have the event switch out your Ally for the enemy.

Of course, I reckon it might depend on how you want the Fight to occur, but that's the first thing I thought of.
Jens of Zanicuud
QUOTE (TheCableGuy @ Feb 17 2012, 04:12 AM) *
If it's only for one battle, sounds like you could do better with an Event. Make a Doppelganger Enemy and have the event switch out your Ally for the enemy.

Of course, I reckon it might depend on how you want the Fight to occur, but that's the first thing I thought of.


I'm sorry, but it think this could be tremendously inefficient, since events are not so easy to manage in RMXP battle system.
Moreover, if I understood correctly, you should be able to attak even enemies, not only allies in that battle.

@LostSamurai

Tell me if the script linked by Vexus works properly for you. If the answer is "No, it doesn't" I'll script it, if the answer is "Yes, it works in a perfect way" I'll consider this request solved.

Jens
LostSamurai
I apprecaite your help Vexus, but that script is not what I am looking for. It does not allow the characters to attack their allies.

@TheCableGuy I currently have events to (sort of) deal with the problem. However, it's very sloppy and doesn't make for a very good puzzle.
Jens of Zanicuud
Alright, I'll script it then...

Jens
Vexus
Ops sorry I posted that link in the wrong thread blush.gif
Jens of Zanicuud
This should let you to attack your allies. Beware this script could be not compatible with a custom battle script.
Paste this above main.

CODE
#==============================================================================
#=#============================================================================
# #** Jens of Zanicuud target script v 1.0
# #   -free use, just credit
# #   -free customization, however, posting on RRR the modified version is
# #    mandatory
# #   -you can find me on www.rpgrevolution.com
#=#============================================================================
#==============================================================================

#==============================================================================
# ** Arrow_All
#------------------------------------------------------------------------------
#  This arrow cursor is used to choose targets. This class inherits from the
#  Arrow_Base class.
#==============================================================================

class Arrow_All < Arrow_Base
  def initialize(viewport,for_actors)
   @for_actors = for_actors
   if for_actors
    @troop = $game_party.actors + $game_troop.enemies
  else
    @troop = $game_troop.enemies + $game_party.actors
  end
  super(viewport)
  end
  #--------------------------------------------------------------------------
  # * Get Enemy Indicated by Cursor
  #--------------------------------------------------------------------------
  def target
    return @troop[@index]
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Skip if indicating a nonexistant target
    @troop.size.times do
      break if self.target.exist?
      @index += 1
      @index %= @troop.size
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @troop.size.times do
        @index += 1
        @index %= @troop.size
        break if self.target.exist?
      end
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @troop.size.times do
        @index += @troop.size - 1
        @index %= @troop.size
        break if self.target.exist?
      end
    end
    # Set sprite coordinates
    if self.target != nil
      self.x = self.target.screen_x
      self.y = self.target.screen_y
    end
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    # Display enemy name and state in the help window
    if self.target.is_a?(Game_Enemy)
    @help_window.set_enemy(self.target)
    else
    @help_window.set_actor(self.target)
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start Actor Selection
  #--------------------------------------------------------------------------
  def start_actor_select
    # Make actor arrow
    @actor_arrow = Arrow_All.new(@spriteset.viewport2,true)
    @actor_arrow.index = @actor_index
    # Associate help window
    @actor_arrow.help_window = @help_window
    # Disable actor command window
    @actor_command_window.active = false
    @actor_command_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Start Enemy Selection
  #--------------------------------------------------------------------------
  def start_enemy_select
    # Make enemy arrow
    @enemy_arrow =  Arrow_All.new(@spriteset.viewport2,false)
    # Associate help window
    @enemy_arrow.help_window = @help_window
    # Disable actor command window
    @actor_command_window.active = false
    @actor_command_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Set target for skills & items
  #--------------------------------------------------------------------------
  def set_target_battlers(scope)
    # If battler performing action is enemy
    if @active_battler.is_a?(Game_Enemy)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_party.smooth_target_actor(index))
      when 2  # all enemies
        for actor in $game_party.actors
          if actor.exist?
            @target_battlers.push(actor)
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_troop.smooth_target_enemy(index))
      when 4  # all allies
        for enemy in $game_troop.enemies
          if enemy.exist?
            @target_battlers.push(enemy)
          end
        end
      when 5  # single ally (HP 0)
        index = @active_battler.current_action.target_index
        enemy = $game_troop.enemies[index]
        if enemy != nil and enemy.hp0?
          @target_battlers.push(enemy)
        end
      when 6  # all allies (HP 0)
        for enemy in $game_troop.enemies
          if enemy != nil and enemy.hp0?
            @target_battlers.push(enemy)
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
    # If battler performing action is actor
    if @active_battler.is_a?(Game_Actor)
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        if index < $game_troop.enemies.size
          @target_battlers.push($game_troop.smooth_target_enemy(index))
        else
          @target_battlers.push($game_party.smooth_target_actor(index-$game_troop.enemies.size))
        end
      when 2 # all enemies
        for enemy in $game_troop.enemies
          if enemy.exist?
            @target_battlers.push(enemy)
          end
        end
      when 3  #fellow actor
        index = @active_battler.current_action.target_index
        if index > $game_party.actors.size-1
          @target_battlers.push($game_troop.smooth_target_enemy(index-$game_party.actors.size))
        else
          @target_battlers.push($game_party.smooth_target_actor(index))
          end
      when 4  # all allies
        for actor in $game_party.actors
          if actor.exist?
            @target_battlers.push(actor)
          end
        end
      when 5  # fellow (HP 0)
        index = @active_battler.current_action.target_index
        if index>$game_party.actors.size-1
           enemy = $game_troop.enemies[index-$game_party.actors.size]
          if enemy != nil
          @target_battlers.push(enemy)
          end
        else
          actor = $game_party.actors[index]
          if actor != nil
          @target_battlers.push(actor)
        end
          end
      when 6  # all allies (HP 0)
        for actor in $game_party.actors
          if actor != nil and actor.hp0?
            @target_battlers.push(actor)
          end
        end
      when 7  # self
        @target_battlers.push(@active_battler)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Make Basic Action Results
  #--------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # If action battler is enemy
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          
        index = @active_battler.current_action.target_index

        if index < $game_troop.enemies.size
          target = $game_troop.smooth_target_enemy(index)
        else
          target = $game_party.smooth_target_actor(index-$game_troop.enemies.size)
        end
      
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
    end


BTW, rigene script is ready&working. Check the other topic's last post...
Ask for troubleshooting anytime.

I hope this can help...

Jens
LostSamurai
That works perfectly! Thank you very much biggrin.gif
TheCableGuy
QUOTE (Jens of Zanicuud @ Feb 17 2012, 02:44 AM) *
I'm sorry, but it think this could be tremendously inefficient, since events are not so easy to manage in RMXP battle system.
Moreover, if I understood correctly, you should be able to attak even enemies, not only allies in that battle.


Understood. I'm not really a Scripter so that's outside my range. I've just been working with events lot so that's the limit of my knowledge.

It was just a suggestion but maybe I should of kept it to myself.
LostSamurai
QUOTE
It was just a suggestion but maybe I should of kept it to myself.


Don't be silly! Suggestions are always welcome and appreciated. Sometimes they are just not what's needed at the time. But there's always multiple ways to solve a problem. I originally used events to pseudo-solve this problem, but it was very sloppy. The script made everything much... cleaner.
LostSamurai
Ummm, there's a massive glitch that I just noticed. I am unable to target dead allies. This means I am unable to use ressurection spells or items in combat. This is game breaking, please help!
Jens of Zanicuud
Try replacing my old script with this:

CODE
#==============================================================================
#=#============================================================================
# #** Jens of Zanicuud target script v 1.1
# #   -free use, just credit
# #   -free customization, however, posting on RRR the modified version is
# #    mandatory
# #   -you can find me on www.rpgrevolution.com
#=#============================================================================
#==============================================================================

#==============================================================================
# ** Arrow_All
#------------------------------------------------------------------------------
#  This arrow cursor is used to choose targets. This class inherits from the
#  Arrow_Base class.
#==============================================================================

class Arrow_All < Arrow_Base
  def initialize(viewport,for_actors)
   @for_actors = for_actors
   if for_actors
    @troop = $game_party.actors + $game_troop.enemies
  else
    @troop = $game_troop.enemies + $game_party.actors
  end
  super(viewport)
  end
  #--------------------------------------------------------------------------
  # * Get Enemy Indicated by Cursor
  #--------------------------------------------------------------------------
  def target
    return @troop[@index]
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # Skip if indicating a nonexistant target
    @troop.size.times do
      if (self.target.exist? or self.target.is_a?(Game_Actor))
      break
    end
      @index += 1
      @index %= @troop.size
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @troop.size.times do
        @index += 1
        @index %= @troop.size
    if (self.target.exist? or self.target.is_a?(Game_Actor))
      break
    end
      end
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @troop.size.times do
        @index += @troop.size - 1
        @index %= @troop.size
    if (self.target.exist? or self.target.is_a?(Game_Actor))
      break
    end
      end
    end
    # Set sprite coordinates
    if self.target != nil
      self.x = self.target.screen_x
      self.y = self.target.screen_y
    end
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    # Display enemy name and state in the help window
    if self.target.is_a?(Game_Enemy)
    @help_window.set_enemy(self.target)
    else
    @help_window.set_actor(self.target)
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
  attr_reader :active_battler
  #--------------------------------------------------------------------------
  # * Start Actor Selection
  #--------------------------------------------------------------------------
  def start_actor_select
    # Make actor arrow
    @actor_arrow = Arrow_All.new(@spriteset.viewport2,true)
    @actor_arrow.index = @actor_index
    # Associate help window
    @actor_arrow.help_window = @help_window
    # Disable actor command window
    @actor_command_window.active = false
    @actor_command_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Start Enemy Selection
  #--------------------------------------------------------------------------
  def start_enemy_select
    # Make enemy arrow
    @enemy_arrow =  Arrow_All.new(@spriteset.viewport2,false)
    # Associate help window
    @enemy_arrow.help_window = @help_window
    # Disable actor command window
    @actor_command_window.active = false
    @actor_command_window.visible = false
  end
  #--------------------------------------------------------------------------
  # * Set target for skills & items
  #--------------------------------------------------------------------------
  def set_target_battlers(scope)
    # If battler performing action is enemy
    if @active_battler.is_a?(Game_Enemy)
      # Branch by effect scope
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_party.smooth_target_actor(index))
      when 2  # all enemies
        for actor in $game_party.actors
          if actor.exist?
            @target_battlers.push(actor)
          end
        end
      when 3  # single ally
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_troop.smooth_target_enemy(index))
      when 4  # all allies
        for enemy in $game_troop.enemies
          if enemy.exist?
            @target_battlers.push(enemy)
          end
        end
      when 5  # single ally (HP 0)
        index = @active_battler.current_action.target_index
        enemy = $game_troop.enemies[index]
        if enemy != nil and enemy.hp0?
          @target_battlers.push(enemy)
        end
      when 6  # all allies (HP 0)
        for enemy in $game_troop.enemies
          if enemy != nil and enemy.hp0?
            @target_battlers.push(enemy)
          end
        end
      when 7  # user
        @target_battlers.push(@active_battler)
      end
    end
    # If battler performing action is actor
    if @active_battler.is_a?(Game_Actor)
      case scope
      when 1  # single enemy
        index = @active_battler.current_action.target_index
        if index < $game_troop.enemies.size
          @target_battlers.push($game_troop.smooth_target_enemy(index))
        else
          @target_battlers.push($game_party.smooth_target_actor(index-$game_troop.enemies.size))
        end
      when 2 # all enemies
        for enemy in $game_troop.enemies
          if enemy.exist?
            @target_battlers.push(enemy)
          end
        end
      when 3  #fellow actor
        index = @active_battler.current_action.target_index
        if index > $game_party.actors.size-1
          @target_battlers.push($game_troop.smooth_target_enemy(index-$game_party.actors.size))
        else
          @target_battlers.push($game_party.smooth_target_actor(index))
          end
      when 4  # all allies
        for actor in $game_party.actors
          if actor.exist?
            @target_battlers.push(actor)
          end
        end
      when 5  # fellow (HP 0)
        index = @active_battler.current_action.target_index
        if index>$game_party.actors.size-1
           enemy = $game_troop.enemies[index-$game_party.actors.size]
          if enemy != nil
          @target_battlers.push(enemy)
          end
        else
          actor = $game_party.actors[index]
          if actor != nil
          @target_battlers.push(actor)
        end
          end
      when 6  # all allies (HP 0)
        for actor in $game_party.actors
          if actor != nil and actor.hp0?
            @target_battlers.push(actor)
          end
        end
      when 7  # self
        @target_battlers.push(@active_battler)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Make Basic Action Results
  #--------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # If action battler is enemy
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          
        index = @active_battler.current_action.target_index

        if index < $game_troop.enemies.size
          target = $game_troop.smooth_target_enemy(index)
        else
          target = $game_party.smooth_target_actor(index-$game_troop.enemies.size)
        end
      
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
    end


This should work, though I'm not certain at 100%.
I hope this can help...

Jens
LostSamurai
Yes! This worked. Thank you!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.