item error

I've been trying to code damage/healing items but when actor 1 eats the item it damages actor 2 and I'm not sure if my coding is bad.
const healingPercentage = 10; // Healing percentage (adjust as needed)
const damagePercentage = 30; // Damage percentage (adjust as needed)

$gameParty.members().forEach(actor => {
const actorID = actor.actorId();
let healingAmount = 0;
let damageAmount = 0;

if (actorID === 1) {
// Calculate healing amount for Actor 1
const maxHp = actor.mhp;
healingAmount = Math.floor((maxHp * healingPercentage) / 100);
actor.gainHp(healingAmount); // Apply healing to Actor 1
return;

} else if (actorID === 3) {
// Calculate healing amount for Actor 3
const maxHp = actor.mhp;
healingAmount = Math.floor((maxHp * healingPercentage) / 100);
actor.gainHp(healingAmount); // Apply healing to Actor 3
return;

} else if (actorID === 2) {
// Calculate damage amount for Actor 2
const maxHp = actor.mhp;
damageAmount = Math.floor((maxHp * damagePercentage) / 100);
actor.gainHp(-damageAmount); // Apply damage to Actor 2
return;

} else if (actorID === 4) {
// Calculate damage amount for Actor 4
const maxHp = actor.mhp;
damageAmount = Math.floor((maxHp * damagePercentage) / 100);
actor.gainHp(-damageAmount); // Apply damage to Actor 4
return;

}

});
You're using a forEach for every party member, so no matter who uses the item it will affect every party member each time it's used.
You're using a forEach for every party member, so no matter who uses the item it will affect every party member each time it's used.
Thx for the help, I think I can try to solve it from here.
You can also trim down your code significantly. You don't explain where this code is going, but I would assume you're sticking it into a VisuStella Battle Core notetag so you have access to a target variable. If not, you could use the lastActionData to see which actor was targeted.

But, for example presuming you have target:
Code:
target.gainHp(Math.floor((target.actorId() == 1 || target.actorId() == 3) ? target.mhp*.1 : 0-target.mhp*.3)

If you're not using a notetag that provides target, you'd just have to define it first using the lastActionData:
let target = $gameActors.actor($gameTemp.lastActionData(4));

Then the second line is what I provided above.

Original thread: https://forums.rpgmakerweb.com/threads/item-error.163586/