Target 3 enemies next to each other

Hello, im looking for a way to make a skill that affects the targeted enemy and the enemies being next to it on each side. I have tried using the Yanfly area of effect script, but it's inconsistent with varying enemy sizes. Im looking for something that affects enemy A, B and C when B is targeted, A and B when A is targeted, B, C and D when B is targeted and so on.
Is there any script that can allow me to do that?
@figdor5215
How about adjacent enemies receive only 50% of the total damage while the target enemy receives 100%? This would make those kind of skills effective but not overpowered.
@figdor5215
How about adjacent enemies receive only 50% of the total damage while the target enemy receives 100%? This would make those kind of skills effective but not overpowered.
that would be great, but the question is - are there any scripts that would allow me to do this?
that would be great, but the question is - are there any scripts that would allow me to do this?
The closest thing I could find is Area of Effect by Yanfly. It works with enemy radius and it requires YEA - Target Manager to work properly.

To get exactly what you're looking for, you'd probably need a custom made script. I'd be interested in this as well as long as we had the ability to alter the amount of damage taken by an adjacent enemy like described above. A feature like this would give a very neat tactical vibe to battles and make the right enemy targetting more valueable.
The closest thing I could find is Area of Effect by Yanfly. It works with enemy radius and it requires YEA - Target Manager to work properly.

To get exactly what you're looking for, you'd probably need a custom made script. I'd be interested in this as well as long as we had the ability to alter the amount of damage taken by an adjacent enemy like described above. A feature like this would give a very neat tactical vibe to battles and make the right enemy targetting more valueable.
absolutely agree with you on this
@figdor5215
It's been almost a year now. Got a solution for it? I'd still be interested in this mechanic as well.
@figdor5215
It's been almost a year now. Got a solution for it? I'd still be interested in this mechanic as well.
unfortunately not, I ended up just using Yanfly's AoE script
unfortunately not, I ended up just using Yanfly's AoE script
I think the adjacent mechanic would be quite interesting, but maybe it's too difficult to implement.
It does not seem too hard but I have a few questions: would you be okay with the targeting area being based only on battler index (regardless of the sprite position)? Do you want this adjacency rule to work on the party too? If a battler is dead, do I take the next one by adjacency rule?
@Timtrack
Not sure, if OP is still wants this as he found another solution for himself in the meantime. As I would still be interested, I'm going to answer the questions from my point of view:
  • If you say battler index, just to be sure, you mean the battler Id (like 001, 002, 003 ... in the database)?
  • For me, it would only need to work for enemies, not for the party itself.
  • If a battler is dead, the next living one should be selected following the adjacency rule. Also, enemies using "Appear Halfway" (so they’re not visible yet) should not be targetable until they're actually made visible on screen.
  • Also, the damage that an adjacent enemy should receive from damage that is not dealt directly to them but by adjacency rule, should only be like 50% of the damage the main target receives.
I meant the index of the battler in the troop (not the index of the battler in the database). Okay, I will go along with this interpretation unless OP has other opinions.

There are some further questions:
-do you want some skills to not be concerned by adjacency rule?
-do you want items to be concerned by it?
-do you want random targeting to follow adjacency rule too?
-if an ability applies additional effects outside of the formula (like states addition or healing) do you want them to be nerfed and/or skipped? (If nerfed please tell me to which extend)

By default I was thinking of giving adjacency parameters in skills/items notetags (allowing some skills to have adjacency rules, other without and some with different damage % or even spreading further)
The consequences of my last question can be tricky, it would be easier to apply additional effects without any concern unless you have a specific vision.
I meant the index of the battler in the troop (not the index of the battler in the database).
Okay, got it. That also makes lots more sense tbh. :LZSjoy:

Answers to further questions:
  • Yes. Best to have some note tags in the Skill section to decide how the adjacency rule should work. There's 4 possible ways of hitting:
    • Hit one enemy and additionally, 1/2 damage goes to the enemy left side of it
    • Hit one enemy and additionally, 1/2 damage goes to the enemy right side of it
    • Hit one enemy and additionally, 1/2 damage goes to the enemy left side of it and 1/2 damage goes to the enemy right side of it
    • Skills that work normally without adjacency rules
  • No need for items
  • Random targeting can still work normally without adjacency rules
  • Good question... for example stun and burn, huh? I would exclude them from adjacency rules. Else, stats would turn out to be overpowered if you could stun multiple enemies at once simply by hitting the foe in the middle. But I dunno how OP thinks about this?
By default I was thinking of giving adjacency parameters in skills/items notetags (allowing some skills to have adjacency rules, other without and some with different damage % or even spreading further)

Yes, that sounds perfect. 🙂
No need for items
Items are good to have as well. What if you have a bomb?
Hit one enemy and additionally, 1/2 damage goes to the enemy left side of it and 1/2 damage goes to the enemy right side of it
You mean 1/2 for the enemy on the left of the selected enemy and 1/4 for the enemy on the left of the left enemy. so it looks likes this?
1/4 - 1/2 - full - 1/2 - 1/4
Good question... for example stun and burn, huh? I would exclude them from adjacency rules. Else, stats would turn out to be overpowered if you could stun multiple enemies at once simply by hitting the foe in the middle. But I dunno how OP thinks about this?
If it can be added then I think it's fine, but perhaps at reduced odds?
Random targeting can still work normally without adjacency rules
do you want random targeting to follow adjacency rule too?
That's a tough one. having a skill that targets 3 random enemies and each attack does adjacency? that would make a lot of damage. But it would be up to the person developing the game if they have a skill that targets 3 random enemies and sets it to apply to adjacent enemies then that how he/she wants it to behave.
You mean 1/2 for the enemy on the left of the selected enemy and 1/4 for the enemy on the left of the left enemy. so it looks likes this?
1/4 - 1/2 - full - 1/2 - 1/4
No, it's much simpler. I only need 1/2 damage to the enemy/enemies next to the main target. No spreading of damage across all enemies, just...
  • ...either left and right target receive 1/2 damage the main target receives (shown on the screenshot)
  • ...only the left one of the main target receives 1/2 damage
  • ...only the right one of the main target receives 1/2 damage
This is a first version of the slash skills/items, you can set the skill/item 'area' in their notetags, there are 3 possibilities:
<slash: a,b>
<slash_left: a,b>
<slash_right: a,b>

With a the damage ratio done on the original target (1 by default) and b the damage ratio done to the second target in one direction (or both for <slash>).

For instance: <slash: 1, 0.5> will damage too 100% the original target and 50% the targets around.
You can add as many values to your slash array: <slash: 1, 0.5, 0.25> would damage to 100% the target, then 1/2 the units around, then 1/4 the ones after.

You can also put 0 if you want the target to be skipped, so <slash: 0, 1> would damage the units around.
Finally you can have asymmetrical results if you use both slash_left and slash_right in the same notetags.

I also allowed the damage to spread between party members if you allow it (deactivate by default).
I chose not to display more animations than the vanilla version (so one animation per original target).

For now this ratio only affects the damage of the formula, as I said before, for additional effects, you have to be very precise, keep in mind that anything that you could add to additional effects (healing, status, characteristic and 'others') should be covered here.

For healing I could apply the ratio to change the result, and for status I could apply the ratio to change the probability of adding or removing it, for the rest I don't know how you would like it to work.

Ruby:
#==============================================================================
# Slash Abilties
#------------------------------------------------------------------------------
# Author: Timtrack
# date: 28/04/2025
#==============================================================================

$imported = {} if $imported.nil?
$imported["TIM-Slash-Abilties"] = true

#==============================================================================
# Description
#------------------------------------------------------------------------------
# Allows abilities (skills or items) to damage battlers next to the original
# target.
# The effects of the ability may be nerfed or increased by a ratio depending on
# the distance.
# If the next battler in a direction is defeated or empty, pick the next one.
#==============================================================================
# Installation: put it above main
#
# In skills or items notetags you may put the following comments:
# <slash: a,b,c>
# This will damage with ratio a the first target, then with ratio b the battlers
# on the left and the right and with ratio c the battlers after.
# Example <slash: 0.8,0.3> will damage to 80% the target and 30% the battlers next to it
#
# The number of ratios after the slash command can be anything.
# Putting a 0 value as ratio means that the target will be skipped
#
# Alternatively you may use:
# <slash_right: a,b,c,d> to only affect battlers on the right
# <slash_left: a,b,c,d> to only affect battlers on the left
# If you want asymmetrical behavior you may use the two commands above (note that a will be replaced by the last command)
#==============================================================================
# Terms of use: free for both commercial and non-commercial if you give credit
#==============================================================================
# Installation: put it above Main and as low as possible in your load order
#==============================================================================

module SlashAbilities
  PARTY_SLASHED = false #if you wish slashing abiltiies to also affect multiple party members
  module REGEXP
    CENTER = /<slash:\s*(\d+(\.\d+)?(\s*,\s*\d+(\.\d+)?)*)\s*>/i
    LEFT   = /<slash_left:\s*(\d+(\.\d+)?(\s*,\s*\d+(\.\d+)?)*)\s*>/i
    RIGHT  = /<slash_right:\s*(\d+(\.\d+)?(\s*,\s*\d+(\.\d+)?)*)\s*>/i
  end #REGEXP
end #SlashAbilities

#============================================================================
# DataManager
#============================================================================
module DataManager
  #--------------------------------------------------------------------------
  # alias method: load_database
  #--------------------------------------------------------------------------
  class <<self; alias load_database_slash load_database; end
  def self.load_database
    load_database_slash
    for data in [$data_items,$data_skills]
      data.each{|obj| obj.load_notetags_slash if obj}
    end
  end
end # DataManager

#============================================================================
# RPG::UsableItem -> store slash data for items and skills
#============================================================================
class RPG::UsableItem
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_reader :slash_center, :slash_left, :slash_right
  #--------------------------------------------------------------------------
  # common cache: load_notetags_range_cst
  #--------------------------------------------------------------------------
  def load_notetags_slash
    @slash_center = 1
    @slash_left = []  #contains [l1,l2,l3,...]
    @slash_right = [] #contains [r1,r2,r3,...]
    #---
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when SlashAbilities::REGEXP::CENTER
        l = $1.scan(/(([0-9]*[.])?[0-9]+)/).map {|s| s[0].to_f}
        @slash_center = l.slice!(0) #remove the first value and add it to center
        @slash_left = l.dup
        @slash_right = l.dup
      when SlashAbilities::REGEXP::LEFT
        l = $1.scan(/(([0-9]*[.])?[0-9]+)/).map {|s| s[0].to_f}
        @slash_center = l.slice!(0)
        @slash_left = l.dup
      when SlashAbilities::REGEXP::RIGHT
        l = $1.scan(/(([0-9]*[.])?[0-9]+)/).map {|s| s[0].to_f}
        @slash_center = l.slice!(0)
        @slash_right = l.dup
      end
    } # self.note.split
  end
end # RPG::BaseItem

#============================================================================
# Game_BattlerBase
#============================================================================
class Game_BattlerBase
  attr_accessor :slash_ratio
  #--------------------------------------------------------------------------
  # alias method: initialize
  #--------------------------------------------------------------------------
  alias slash_game_batbase_init initialize
  def initialize
    @slash_ratio = 1
    slash_game_batbase_init
  end
end #Game_BattlerBase

#============================================================================
# Game_ActionResult -> deals with the consequences of the action
#============================================================================
class Game_ActionResult
  #--------------------------------------------------------------------------
  # alias method: make_damage -> nerf the value by ratio
  #--------------------------------------------------------------------------
  alias slash_make_damage make_damage
  def make_damage(value, item)
    slash_make_damage((value*@battler.slash_ratio).to_i,item)
  end
end #Game_ActionResult

#============================================================================
# Game_Unit
#============================================================================
class Game_Unit
  #--------------------------------------------------------------------------
  # new method: left_of -> get the battler left of bat,
  # return nil if no battler on the left or bat is not in unit
  #--------------------------------------------------------------------------
  def left_of(bat)
    mem_id = 0
    mem_id = members.index(bat)
    return nil unless mem_id && mem_id > 0
    return members[mem_id-1]
  end
 
  #--------------------------------------------------------------------------
  # new method: right_of -> get the battler right of bat,
  # return nil if no battler on the right or bat is not in unit
  #--------------------------------------------------------------------------
  def right_of(bat)
    mem_id = 0
    mem_id = members.index(bat)
    return nil unless mem_id && mem_id < members.size-1
    return members[mem_id+1]
  end
end #Game_Unit

#============================================================================
# Scene Battle
#============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # alias method: invoke_item -> extend the effects to other targets
  #--------------------------------------------------------------------------
  alias slash_invoke_item invoke_item
  def invoke_item(target,item)
    return slash_invoke_item(target,item) if item.for_all? || (target.actor? && !SlashAbilities::PARTY_SLASHED)
    invoke_item_ratio(target,item,item.slash_center) #center target effect
    unit = target.actor? ? $game_party : $game_troop
    #left side
    next_target = target
    item.slash_left.each do |r|
      next_target = unit.left_of(next_target)
      next_target = unit.left_of(next_target) until next_target.nil? || valid_target?(next_target,item)
      break if next_target.nil? #no available target
      invoke_item_ratio(next_target,item,r)
    end
    #right side
    next_target = target
    item.slash_right.each do |r|
      next_target = unit.right_of(next_target)
      next_target = unit.right_of(next_target) until next_target.nil? || valid_target?(next_target,item)
      break if next_target.nil? #no available target
      invoke_item_ratio(next_target,item,r)
    end
  end
 
  #--------------------------------------------------------------------------
  # new method: invoke_item_ratio -> invoke item with ratio nerfing the effects
  #--------------------------------------------------------------------------
  def invoke_item_ratio(target,item,ratio = 1)
    return if ratio <= 0 #skip 0 case
    target.slash_ratio = ratio
    slash_invoke_item(target,item) #the aliased method
    target.slash_ratio = 1
  end
 
  #--------------------------------------------------------------------------
  # new method: valid_target? -> return true if target is alive and item
  # is not for dead or opposite
  #--------------------------------------------------------------------------
  def valid_target?(target,item)
    target.exist? && item.for_dead_friend? == target.dead?
  end
end #Scene_Battle
@Timtrack
First off, thanks a ton for putting in that effort and writing this script. This is such a cool mechanic and I really appreciate it you made it possible for me to use this cool feature in battles from now on! :LZSjoy:

I did some testing with the script and here’s what happened:

First off, I added 3 foes to my test battle:
  • Enemy A (Left)
  • Enemy B (Middle)
  • Enemy C (Right)
And those are the actions I let my actors perform:
  • Ally 1 targets B.
  • Ally 2 targets C.
  • Ally 3 does not attack at all (I let them guard to not overcomplicate things in my first test run :LZSlol:).

Both allies used the very same skill (default attack skill) which for testing was note-tagged as <slash_left: 1, 0.5>

Since Ally 2 was faster, they acted first.
  • Ally 2 attacked first, but instead of just hitting C and B, they go C, B, C, B (so bouncing between targets).
  • Ally 1 attack sequencing was as expected
No idea if I am doing something wrong here? :LZSblush:

Something that would be really cool: I use this script to display damage numbers and popups like "Critical!", "Evade" and so on in battles. It's an unnecessary script tbh, but having these hopping numbers make battles look more engaging in my opinion. As for this, would it possible to display "Adjacent hit" there whenever adjacent damage was dealt to any opponent?
Glad to help!

Without this script, would Ally 2 have attacked twice?
Have you tried the script on an unscripted project for comparison?

In theory my script does this: for each time an ability should try to hit a target, call it instead for the target and its neighbors.
This 'splitting' is done after the skill was duplicated by randomness, multihit and base attacks that are duplicated (and also after the animation is displayed).

I suspect that Ally 2 in your project has something that makes their base attack multiple times, in which case this C,B,C,B is my intended behavior.
That, or there is bug in my script, which is definitely possible! :')

Something that would be really cool: I use this script to display damage numbers and popups like "Critical!", "Evade" and so on in battles. It's an unnecessary script tbh, but having these hopping numbers make battles look more engaging in my opinion. As for this, would it possible to display "Adjacent hit" there whenever adjacent damage was dealt to any opponent?
This script is a bit huge for me, I can modify my script to store when the hit is 'adjacent' or not to help but I have no idea where or how I should call a popup in the other script.
Without this script, would Ally 2 have attacked twice?
No, I used the default attack for testing purpose. It's a single hit.

I tested it in a completely new project and it's the same. It goes C, B, C, B. It works for one hero, but not for two heros attacking at the same time. I attached the project ZIP file.

Could it be that because ally 2 targets C and ally 1 targets B at the same turn, which would be ally 2's adjacency target, maybe the script gets confused upon properly sequencing the hits?
Actor2 attacks twice because she wears a weapon that adds an additional attack (the cestus), if you remove the script, you will see that the monster is damaged twice by her attack. So not a bug here!

1745870753297.png
Actor2 attacks twice because she wears a weapon that adds an additional attack (the cestus), if you remove the script, you will see that the monster is damaged twice by her attack. So not a bug here!
Oh jeez, you're so right, bro! :LZSblush:

I removed that weapon and now it works fine, so I have to agree it was never a bug at all.

Sorry to have wasted your time. I totally missed that. :LZSlol:

Original thread: https://forums.rpgmakerweb.com/threads/target-3-enemies-next-to-each-other.169078/