[SOLVED] Divide damage among enemies present

Status
Not open for further replies.

Lunesis

Veteran
Veteran
Joined
Oct 4, 2015
Messages
88
Reaction score
31
First Language
English
Primarily Uses
RMMZ
I know this was easy in MV with one of Yanfly's plugins but struggling on this in MZ. I want an aoe attack that does say, a base amount of 100 to one enemy alone, but when there are two enemies present it will do 50 to each, and to three enemies 33.3 etc. Is there a good way to achieve this in the damage formula, or a plugin that can accomplish this?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,662
Reaction score
8,483
First Language
German
Primarily Uses
RMMV
my approach would be to make the skill hit all enemies, and divide the damage by the number of enemies alive - no plugin needed at all.

two problems:
1) if an early enemy is killed, the damage suddenly increases for the following enemies
2) I don't know the syntax for the number of enemies for the formula in MZ, you'll have to wait for someone to fill that in.
 

Lunesis

Veteran
Veteran
Joined
Oct 4, 2015
Messages
88
Reaction score
31
First Language
English
Primarily Uses
RMMZ
2) I don't know the syntax for the number of enemies for the formula in MZ, you'll have to wait for someone to fill that in.
That's what I'm hoping for, unfortunately there are no glossaries with all of the formula commands for MZ that I could find, just the 101 page for MV with some examples.
 

micoomer

Villager
Member
Joined
Apr 24, 2019
Messages
24
Reaction score
9
First Language
Indonesia
Primarily Uses
RMMV
use $gameTroop.members().length to get current number of enemies present.
 

Corygon

Storyteller
Member
Joined
Mar 20, 2019
Messages
17
Reaction score
11
First Language
English
Primarily Uses
RMMZ
use $gameTroop.members().length to get current number of enemies present.
So, correct me if I'm wrong, but this might be the damage formula:

"100 / $gameTroop.members().length"

Correct?
 

ScorchedGround

Blizzards most disappointed fan (More than ever)
Veteran
Joined
Apr 12, 2020
Messages
620
Reaction score
832
First Language
German
Primarily Uses
RMMV
There are problems with using the approaches already mentioned.
As Andar has also pointed out.



"$gameTroop.members().length" will return the amount of enemies in the enemy troop.
This CAN work, but keep in mind that any enemy that has not appeared yet ("appear halfway" function) or has already been defeated will also be counted. So the damage will always be the same.

For example, if you have 5 enemies and 4 of them are already defeated, the skill will only deal 20 damage to the one remaining enemy instead of 100.



"$gameTroop.aliveMembers().length" will return the amount of enemies that are ACTUALLY present.
This will exclude defeated enemies and those that have not appeared yet.
The problem with this however is that if during the attack any enemies are defeated, the next enemy will take more damage because the amount of present enemies has been reduced.

Example: the skill deals 100 damage and there are 5 enemies with 20 HP each.
Keep in mind, that the formula is evaluated for each enemy individually.

First enemy will take 20 damage and die. ( 100 / 5 )
Second enemy will take 25 damage and die. ( 100 / 4 )
Third enemy will take 33 damage and die. ( 100 / 3 )
Fourth enemy will take 50 damage and die. ( 100 / 2 )
Fifth enemy will take 100 damage and die. ( 100 / 1 )


 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,743
Reaction score
2,095
First Language
EN
Primarily Uses
RMMZ
By default a skill targets All, One, or X Random members of a given unit. I'm guessing you're asking about the "All" scope (e.g. "All Enemies"). If you're actually using a plugin that offers its own custom scope, then I recommend you post a link to that plugin and give details about exactly how you're using it, since it is likely it implements its own way of counting targets. Otherwise...

I suggest this formula:
  • 100 / b.friendsUnit().aliveMembers().length
I.e. "100 divided by the number of non-dead members in the target's friendly unit".

As already mentioned, though, this does not solve the "early deaths" problem. One possible solution might be to set aside a game variable (e.g. variable ID 123) specifically for storing the number of living targets. Then you could try something like this (untested):
  • v[123] = v[123] || b.friendsUnit().aliveMembers().length; 100 / v[123]
I.e. "set game variable 123 equal to itself if it is non-zero, or the number of living opponents if it is; then deal damage equal to 100 divided by the value of game variable 123".

Finally, make a Common Event that sets the variable to 0, and link that to the skill using its Effects list. The event should run once, after all targets have received damage.

If using this approach, make sure not to change the value of that variable anywhere else (or at least not without resetting it to 0).
 

Lunesis

Veteran
Veteran
Joined
Oct 4, 2015
Messages
88
Reaction score
31
First Language
English
Primarily Uses
RMMZ
Thanks for the quick replies! I don't mind the early deaths pumping the numbers for subsequent hits in the same attack, seems logical as long as the main number gets distributed as evenly as possible. Trying to avoid where the aoe special move is less powerful against a single boss enemy.

Edit: Nevermind, I see what you mean about the multiplicatives that don't just stay at one value

Caethyril's solution worked, so do the enemies not all get hit at the exact same time with target all? What it sounds like is that even if you have target all, each hit gets processed individually in order.
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,743
Reaction score
2,095
First Language
EN
Primarily Uses
RMMZ
Caethyril's solution worked, so do the enemies not all get hit at the exact same time with target all? What it sounds like is that even if you have target all, each hit gets processed individually in order.
Good to hear you got it working! :kaojoy:

Without plugins, targets are processed one after another: the damage formula gets evaluated once per target. Most effects (e.g. Add State 50%) also get checked/applied once per target; the Common Event effect is an exception to that rule since it always applies once, after processing all targets.

Plugins are capable of changing any aspect of the game, including this stuff.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,920
Reaction score
5,847
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

I forgot that forums have profile walls that you can post or comment on, guess I found a new platform to specifically rant about game-related deranged thought or problems that I have. Salut mes amis!
I couldn't help myself, so I edited the tiles a bit and made a birdhouse :LZSsmile: I hope I will finish the town today!Screenshot 2021-09-17 134349.png
How do I find the threads I have watched? It's been so long I've forgotten :kaoswt:
So far, this is how the wall tileset its looking in-editor. :kaoswt2:
1631863283853.png
Still thinking on details to add.
Added a plugin to RMMV Plugin Releases with all relevant info but it looks like the topic wasn't approved for whatever reason. Cool.

Forum statistics

Threads
115,132
Messages
1,087,482
Members
149,639
Latest member
TheBilby
Top