Using VisuMZ_1_BattleCore.js's <JS Targets> tag, how would I go about targeting the ally with the lowest HP?
Targeting lowest health ally
RPG Maker MZ Support
Code:
let lowest = 0;
for (let i = 0; i < user.friendsUnit().aliveMembers().length; i++)
{
if (user.friendsUnit().aliveMembers()[i].hp < user.friendsUnit().aliveMembers()[lowest].hp)
lowest = i;
}
targets = [user.friendsUnit().aliveMembers()[lowest]];
That was a super fast response, thanks! Looks like it worked like a charm! I realized I actually needed to heal the ally with the most missing hp so I made some adjustments to your wonderful code
Code:
<JS Targets>
targets = [];
let lowest = 0;
for (let i = 0; i < user.friendsUnit().aliveMembers().length; i++)
{
if (user.friendsUnit().aliveMembers()[i].hp/user.friendsUnit().aliveMembers()[i].mhp < user.friendsUnit().aliveMembers()[lowest].hp/user.friendsUnit().aliveMembers()[lowest].mhp)
lowest = i;
}
targets = [user.friendsUnit().aliveMembers()[lowest]];
</JS Targets>
Solved!
Instead of typing out the division, MZ has an hpRate() method you could use:
I also don't see the point of adding a line to set targets to an empty array at the top when it isn't used until you set it again at the bottom.
But I'm glad it does what you want.
aliveMembers()[i].hpRate() < etc.I also don't see the point of adding a line to set targets to an empty array at the top when it isn't used until you set it again at the bottom.
But I'm glad it does what you want.
This thread is closed due to being reported as solved. If you need it reopened, report it to let us know. Thank you!
Original thread: https://forums.rpgmakerweb.com/threads/targeting-lowest-health-ally.171859/