Trying to kill NPC and leave body behind after script executed

I have a script that executes to create a “goblin attack” at a location when an item is picked up by the PC. The rest of the script works as intended, but I want one of my NPCs to die and leave behind a body that the player can easily identify as the person’s body and loot…in other words, not a loot bag. I tried using the command ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectDeath(), newLorah)) inside this environment changing script but she just stands there, all alive and well. She just won’t die.

Try this:

object oNPC = GetObjectByTag("npc_tag");

SetPlotFlag(oNPC, FALSE);
AssignCommand(oNPC, SetIsDestroyable(FALSE, FALSE, TRUE));
AssignCommand(oNPC, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oNPC));
2 Likes

Adding a Lexicon link to go with that. https://nwnlexicon.com/index.php?title=SetIsDestroyable

Also try EffectDamage(9999), if EffectDeath doesn’t work.

SetImmortal(oNPC, FALSE); might also help, in addition to removing the plot flag before trying to kill the NPC, if it’s still not working by then.

2 Likes

I tried this and she leaves a corpse like she should, but it isn’t lootable, even when I checked the box in her properties.

Edited from NwN1’s Lexicon (I have been repeatedly told that NwN 2’ script is the same)

SetLootable(object, int)

Sets whether a creature leaves a lootable corpse upon death

void SetLootable(
    object oCreature, // NPC to set as lootable or not
    int bLootable //boolean eg TRUE/FALSE
);

Description

Sets the lootable state of a living NPC creature.
This function will not work on players or dead creatures.

Example

SetIsDestroyable(TRUE, FALSE, TRUE);
DelayCommand(1.0, SetLootable(OBJECT_SELF, TRUE));

So try this modified version of @Aqvilinus’s script.

object oNPC = GetObjectByTag("npc_tag");

SetPlotFlag(oNPC, FALSE);
AssignCommand(oNPC, SetIsDestroyable(FALSE, FALSE, TRUE));
SetLootable(oNPC, TRUE);
AssignCommand(oNPC, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oNPC));

TR

There’s also a stanadrd BioWare script already there that you can use for that purpose. It’s called ‘x0_c2_dth_loot’ and you put it OnDeath of your npc character. Then whatever makes them die will call that script and the script will do the rest. (You can also use ‘x0_c2_dth_lootdc’ if you want the corpse to decay after it’s been looted.)

2 Likes