Getting drops from killing some enemies in a group

I'm using script to give items for troops killed.

if(result == 0) {

$gameParty.gainItem($dataItems[50], 1);

}

If I have the player fighting multiple enemies, and they only kill some before dying; how can I give them a drop of the enemy/enemies they killed without drops from the ones they did not?
you can use troop events. make a page for each enemy that triggers when their hp hits 0% that gives the party the item you want them to drop
This doesn't work on the last enemy killed if you win
It would help if you provided some more context, like where on Earth you put that code and what result is supposed to refer to.

But just to answer this

This doesn't work on the last enemy killed if you win
Install HimeWorks' End Phase Triggers.
I put the code in troop battle events and the result in that case was for a win

is there a script call that tells me if an enemy is dead or alive? I could run that for each enemy in an encounter after a loss and give the item associated with each enemy.
I see $gameTroop.deadMembers() which might help

if($gameTroop.members()[index].isDead()==true) {

$gameParty.gainItem($dataItems[#], x);

}


Seems to work
Set to turn 0 under troop battle event
You keep posting these snippets of code, and I honestly don't understand how any of them are working, though you claim they are.

How can any enemies in the troop be dead on turn 0? They were just created, it's impossible.

It's the same with the code you posted originally, there's no such thing as result, it can't be doing what you say it is.
BattleManager.setEventCallback(function(result) {

if(result == 2) {

// Battle was lost - heal and transport to inn

$gameParty.reviveBattleMembers(); // sets dead player's HP to 1

$gameParty.members().forEach(function(actor) {

actor.recoverAll();

});

// Replace the values on this line with inn map ID, coordinates, etc

var mapId = 7, x = 1, y = 1, direction = 4, fadeType = 1;

$gamePlayer.reserveTransfer(mapId, x, y, direction, fadeType)

}

if($gameTroop.members()[0].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

if($gameTroop.members()[1].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

});

BattleManager.setEventCallback(function(result) {

if(result == 0) {

if($gameTroop.members()[0].isDead()==true) {

$gameParty.gainItem($dataItems[301], 2);

}

});

heres the whole code right now; some of it is so instead of game over on loss you spawn at a nearby inn.
Seems to work for 2 enemies but not 3 (with an added if statement for the third enemy)
I thought turn 0 was the end of battle based on who gave me the original script to spawn at an inn after loss rather than lose the game

wait thats not quite what i had... I had something similar that was working* sometimes haha
Putting entire functions really doesn't belong inside events. It should be outsourced into plugins.

What you put also doesn't make sense because you're declaring the same function twice - the first thing isn't going to happen because you immediately overwrite it with a different one.
BattleManager.setEventCallback(function(result) {

if(result == 2) {

// Battle was lost - heal and transport to inn

$gameParty.reviveBattleMembers(); // sets dead player's HP to 1

$gameParty.members().forEach(function(actor) {

actor.recoverAll();

});

if($gameTroop.members()[0].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

if($gameTroop.members()[1].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

// Replace the values on this line with inn map ID, coordinates, etc

var mapId = 7, x = 1, y = 1, direction = 4, fadeType = 1;

$gamePlayer.reserveTransfer(mapId, x, y, direction, fadeType)

}

else if(result == 1) {

if($gameTroop.members()[0].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

if($gameTroop.members()[1].isDead()==true) {

$gameParty.gainItem($dataItems[301], 1);

}

}

else if(result == 0) {

$gameParty.gainItem($dataItems[301], 2);

}

});

Original thread: https://forums.rpgmakerweb.com/threads/getting-drops-from-killing-some-enemies-in-a-group.172528/