Attack that does more damage based on an ALLY'S health deficit

I understand that I can use the custom formula function to have an attack do more damage the less health the attacker has:

([a.mhp] - [a.hp]) (and then do whatever you want with the number with other stats like ATK)

But is there a way I can have it based off of an ally's hp deficit instead, ie, the weaker an ally is, the harder this character hits with this ability?
If you know what ally character you want to reference, yes you can do this.

For example if the ally character is Actor 3 in the database, you could replace a (in the a.mhp - a.hp thing) with $gameActors.actor(3) and that will work whether Actor 3 is in battle or on the bench. Not sure whether it will work if, for example, they've never joined your party, though.

You can also reference the party leader using $gameParty.members()[0] or the second member of the party with $gameParty.members()[1] and so on.

If you want to do something more situational, like get the missing HP of the most-injured member of your party, that is possible but the scripting you'd use in the formula is considerably more complex.
My game has only three characters, so specifically calling them out shouldn't be a problem and referencing actors works just perfect and so thank you because I have been pulling my hair out for three hours. Super solved, thank you.

For future Googlers, here's the problem and solution.

Problem: I wanted to have a character grow stronger the weaker her party members were, so with the advice from above, I tested the following Custom Damage Formulas:

The two options from above were:

Calling by Party Member:
(($gameParty.members()[0].mhp - $gameParty.members()[0].hp) + ($gameParty.members()[1].mhp - $gameParty.members()[1].hp) + ($gameParty.members()[2].mhp - $gameParty.members()[2].hp)) + 1

and Calling by Actor Number:

(($gameActors.actor(1).mhp - $gameActors.actor(1).hp) + ($gameActors.actor(2).mhp - $gameActors.actor(2).hp) + ($gameActors.actor(3).mhp - $gameActors.actor(3).hp)) + 1

(Replace the +1 with whatever math you want to perform on the results. I just put it in there to make sure the damage was actually happening when I was still troubleshooting the formula.)

Calling by Party Member expects that you will always have that number of party members (however many you call) and if you have less than that, the code breaks and returns zero. There's likely a method to do it via scripting, but I'm not the greatest at that yet so, I wanted to avoid.

Calling by Actor works if you A: Know specifically the actor you want to refer to and B: Control the HP of allies outside of your party. It works if they're not in your party as well. For my, my game will always have three characters, so I went the Actor method and will make a point of healing up any characters that leave the party so that their HP values have no effect on the end result.

Appreciate your help IMMENSELY, @Wavelength. <3
Not sure whether it will work if, for example, they've never joined your party, though.
It doesn't matter if they're in the party or not. The function call $gameActors.actor(x) will initialize the actor if they haven't yet been initialized, so it's pretty safe to use. They just need to exist in $dataActors somewhere.

Original thread: https://forums.rpgmakerweb.com/threads/attack-that-does-more-damage-based-on-an-allys-health-deficit.133205/