Check Average Party HP

Hello can you help me?
I'm looking for the average party HP value to replace:
this.drawActorHp($gameParty.leader(), 0, 0, 200)
};

on the following function:


My_Window.prototype.refresh = function(){

this.contents.clear();
this.drawActorHp($gameParty.leader(), 0, 0, 200)
};

My_Window.prototype.windowWidth = function(){
return 240;
};
My_Window.prototype.windowHeight = function(){
return 80;
};


My party size can be 1, 2, 3 or 4 actors. I'd need to show the average HP value there


You mean this?

Code:
const averageHp = $gameParty.members().map(actor => actor.hp).reduce((hp1, hp2) => hp1 + hp2) / $gameParty.members().length

Math.floor(averageHP) // to get an integer result
You don't actually need to map that, and that will also include dead party members in the calculation.

JavaScript:
$gameParty.aliveMembers().reduce((total, member) => total += member.hp, 0) / $gameParty.aliveMembers().length

Original thread: https://forums.rpgmakerweb.com/threads/check-average-party-hp.141674/