MV Conditional Move Routes? (GALV_EventDetectors)

So I currently have my monsters' move routes set up so that they will chase the player upon sight and then return back to their original position if they stray too far. I want to add an alternate move route where the monsters run away from the player if the player's avg party lv is +x levels higher than the monster. I currently have it so it checks the party leader's level, but I want it to check the entire party's average level. This is what I got so far:
$gameParty.leader().level > 5 ? this.detector(0) : this.detector(2);
My issue is that I need it to be compatible w/ situations where there are different party sizes. For example, 1 party member, 2 party members, or 3 party members.
Hi,

I have been working with my own stuff trying to grab actor data, and researching lots on this forum.
I think I might have found something helpful for you.

You can grab the party member size with this expression:
JavaScript:
var partysize = $gameParty.members().length; //If you have 3 members it will return the number 3.

Now, all you have to do is loop through the party and then perform your trinary.
EDIT: Whoops, let me fix this snippet. There, now it should work.

JavaScript:
var combinedLevel = 0;
for (let i = 0; i < partysize; partysize++) {
combinedLevel += $gameActors.actor(partysize)._level
}
combinedLevel > 5 ? this.detector(0) : this.detector(2);


Caution, I always make mistakes since arrays start with 0, meaning you only want i <= 2, if you have 3 members in your party.
If my for statement is wrong, please try adjusting for that.

I hope it helps!
Awesomesauce, thx a bunch!

Original thread: https://forums.rpgmakerweb.com/threads/conditional-move-routes-galv_eventdetectors.138888/