Help with Death script

I’m trying to make a script that runs if a certain NPC dies. I want it to be game over so to speak, if he dies. At first I tried something, but I didn’t quite know what I was doing and the game became really strangely buggy, so I went back and…Well, I’ve been thinking of putting this script on OnHeartbeat of the area. Problem is I don’t know what string the EndMovie of the game has. It would be even better if the screen with Load, Save etc. popped up instead of playing the EndMovie, but I don’t know how to do that. The death script I’m using for my module is from Colorsfade. Ok, first, here’s the OnHeartbeat script (based on a script my brother made months ago):

    int CheckIfCreaturesWithTagAreAllDead(string tagName)
    {
        object oPC = GetFactionLeader(GetFirstPC());
        int i = 1;
        object oNavon = GetNearestObjectByTag(tagName, oPC, i);
        while(GetIsObjectValid(oNavon))
        {
            if(!GetIsDead(oNavon)) 
            {
            return FALSE;
            }
            i++;
            oNavon = GetNearestObjectByTag(tagName, oPC, i);
        }
        return TRUE;
    }

    void main()
    {

        object oArea = GetObjectByTag("the_void");
        object oPC = GetFirstPC(FALSE);
            
        if(GetArea(oPC) == oArea)
        {

            if (CheckIfCreaturesWithTagAreAllDead("navon"))
            {
                
            EndGame();

            }
        }
    }

And Colorsfade’s module death (k_mod_player_death) script (I’m thinking of maybe one could use that somehow…)

#include "ginc_death" 
#include "ginc_debug"

void main()
{
    object oDead = GetLastPlayerDied();
    PrintString( "k_mod_player_death: " + GetName(oDead) + " executing OnPlayerDeath event" );

    // Abort if dying character is not an owned PC
    if ( GetIsOwnedByPlayer( oDead ) == FALSE )
    {
        PrintString( "** k_mod_player_death: " + GetName(oDead) + " not owned by a player. ABORT!" );
        return;    
    }
    // Making sure, here.
    //ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(), oDead);
    AssignCommand( oDead, KnockOutCreature( oDead ) );
    
    // Check for additional death script
    string sDeathScript = GetLocalString( oDead, "DeathScript" );
    if ( sDeathScript != "" ) ExecuteScript( sDeathScript, oDead );    
    
    // Check if there are any members left for PC to possess
    if ( GetIsOwnedByPlayer(oDead) == TRUE || GetIsRosterMember(oDead) == TRUE )
    {
        if ( GetIsDeathPopUpDisplayed(oDead) == FALSE )
        {
            if ( GetIsPartyPossessible(oDead) == FALSE )
            {
                PrettyDebug( "*** NO ONE LEFT! ***", 30.0 );    
                ShowProperDeathScreen( oDead );
            }
        }
    }
    
    ExecuteScript("k_death_remove_gui", oDead);
}

Ok, the first thing I’m telling you, is that you should not use the the heartbeat event of the area.
You want this script to run when this npc dies, so you should really slot in the npc’s On Death Script (you see it in the creature blueprint editor if you scroll down).

By default this is the “nw_c2_default7” script, however, in case of this npc, you can replace it with something entirely new.

Toolset_Pic2

For something very standard, that script should be like this:

void main()
{
	object oPC = GetFirstPC();
	while (oPC != OBJECT_INVALID)
	{
		PopUpDeathGUIPanel(oPC, FALSE, FALSE);
		oPC = GetNextPC();
	}
}

If you don’t find the results satisfactory, we can still include Colorsfade’s script into it later. For the time being, give this a try.

Thanks, Clangeddin! I was on my way home and I just realized what you just said. I don’t know why I didn’t think of putting the script on the OnDeath of the character. Sometimes the brain doesn’t work the way it should.

Still, your script assumes this is a PC. It’s an NPC, but no matter. Therefore the while loop is unnecessary.

My script assumes that the one who will see the gameover screen is a PC, and I’m pretty sure it’s a correct assumption.
The loop is there for multiplayer redundancy, but it shouldn’t hurt single player.

Aha. Ok. Didn’t realize that. Sorry, my mistake.

Could I just add to the regular death script then, like this?

//:://////////////////////////////////////////////////
//:: NW_C2_DEFAULT7
/*
  Default OnDeath event handler for NPCs.

  Adjusts killer's alignment if appropriate and
  alerts allies to our death. 
 */
//:://////////////////////////////////////////////////
//:: Copyright (c) 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 12/22/2002
//:://////////////////////////////////////////////////
// chazm 5/6/05 added DeathScript
// ChazM 7/28/05 removed call to user defined event for onDeath
// ChazM - 1/26/07 - EvenFlw modifications
// ChazM -5/17/07 - Spirits don't drop crafting items, removed re-equip weapon code
// JSH-OEI 5/28/08 - NX2 campaign version.

#include "x2_inc_compon"
#include "x0_i0_spawncond"

void main()
{
	string sDeathScript = GetLocalString(OBJECT_SELF, "DeathScript");
	if (sDeathScript != "")
		ExecuteScript(sDeathScript, OBJECT_SELF);
	
    int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    object oKiller = GetLastKiller();

    // If we're a good/neutral commoner,
    // adjust the killer's alignment evil
    if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    {
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    }

    // Call to allies to let them know we're dead
    SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);

    //Shout Attack my target, only works with the On Spawn In setup
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
	
	/*if (!GetIsSpirit(OBJECT_SELF))
    	craft_drop_items(oKiller);*/
		
	object oPC = GetFirstPC();
	while (oPC != OBJECT_INVALID)
	{
		PopUpDeathGUIPanel(oPC, FALSE, FALSE);
		oPC = GetNextPC();
	}		
	
}

No because that would trigger a game over every time you killed any creature with that script, not just that npc.

If you wanted to add it to the regular script, there should be a line that checks the tag of the creature that just died is the one you intend it to be.

Like this:

//:://////////////////////////////////////////////////
//:: NW_C2_DEFAULT7
/*
  Default OnDeath event handler for NPCs.
  Adjusts killer's alignment if appropriate and
  alerts allies to our death. 
 */
//:://////////////////////////////////////////////////
//:: Copyright (c) 2002 Floodgate Entertainment
//:: Created By: Naomi Novik
//:: Created On: 12/22/2002
//:://////////////////////////////////////////////////
// chazm 5/6/05 added DeathScript
// ChazM 7/28/05 removed call to user defined event for onDeath
// ChazM - 1/26/07 - EvenFlw modifications
// ChazM -5/17/07 - Spirits don't drop crafting items, removed re-equip weapon code
// JSH-OEI 5/28/08 - NX2 campaign version.

#include "x2_inc_compon"
#include "x0_i0_spawncond"

void main()
{
	object oDEAD = OBJECT_SELF;
	string sDeathScript = GetLocalString(oDEAD, "DeathScript");
	if (sDeathScript != "") ExecuteScript(sDeathScript, oDEAD);
	
    int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    int nAlign = GetAlignmentGoodEvil(oDEAD);
    object oKiller = GetLastKiller();

    // If we're a good/neutral commoner,
    // adjust the killer's alignment evil
    if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    {
        AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    }

    // Call to allies to let them know we're dead
    SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);

    //Shout Attack my target, only works with the On Spawn In setup
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
	
	/*if (!GetIsSpirit(OBJECT_SELF)) craft_drop_items(oKiller);*/
	
	if (GetTag(oDEAD) == "navon")
	{		
		object oPC = GetFirstPC();
		while (oPC != OBJECT_INVALID)
		{
			PopUpDeathGUIPanel(oPC, FALSE, FALSE);
			oPC = GetNextPC();
		}
	}
}

Ok. I was actually thinking of using this modified script only on that character (and thus renaming the script of course). Anyhow, I’ll use what you suggested here.