Help with deathscript

Well, as in my previous threads I am at a situation now where the player controlls the companions and won’t be able to control the PC. They can go off into a fight without the PC who is stuck in a “prison” in the same area.

Now, I want to let the game show the death screen if all companions are dead but not the PC. I have tried to modify my OnPlayerDeath script, but I haven’t succeeded in what I’m trying to do. There must be a pretty simple way to achieve this, but I have not been able to so far. Here’s the script:

// k_mod_player_death
/*
   Module OnDeath handler to queue KnockOut script for owned PCs
*/
// BMA-OEI 12/19/05
// BMA-OEI 2/28/06 -- DeathScript support
// BMA-OEI 8/10/10 -- Exit if not owned by player (e.g. possessed companions)
// MDiekmann 7/10/07 - Modified to cause game ending condition if caused by spirit eater death
// TDE 6/20/08 - Adapted script for NX2

#include "ginc_death" 
#include "ginc_debug"

void main()
{

	if(GetGlobalInt("chicken"))
	{
	
		object oDead = GetLastPlayerDied();
	
		PrintString( "k_mod_player_death: " + GetName(oDead) + " executing OnPlayerDeath event" );

		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 ( GetIsRosterMember(oDead) == TRUE )
		{
			if ( GetIsDeathPopUpDisplayed(oDead) == FALSE )
			{
			
					PrettyDebug( "*** NO ONE LEFT! ***", 30.0 );	
					ShowProperDeathScreen( oDead );
		
			}
		}
	
		ExecuteScript("k_death_remove_gui", oDead);
	
	
	
	}


	else
	{
		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);
	}
} 

Tried another version, but this doesn’t work either:

// k_mod_player_death
/*
   Module OnDeath handler to queue KnockOut script for owned PCs
*/
// BMA-OEI 12/19/05
// BMA-OEI 2/28/06 -- DeathScript support
// BMA-OEI 8/10/10 -- Exit if not owned by player (e.g. possessed companions)
// MDiekmann 7/10/07 - Modified to cause game ending condition if caused by spirit eater death
// TDE 6/20/08 - Adapted script for NX2

#include "ginc_death" 
#include "ginc_debug"

void CountDead(object oDead)
{

int i;

AssignCommand( oDead, KnockOutCreature( oDead ) );

i++;

	if(i==3)
	{
		//PrettyDebug( "*** NO ONE LEFT! ***", 30.0 );	
		ShowProperDeathScreen( oDead );
		return;
	}

}


void main()
{

	if(GetGlobalInt("chicken"))
	{
	
		object oDead = GetLastPlayerDied();
	
		PrintString( "k_mod_player_death: " + GetName(oDead) + " executing OnPlayerDeath event" );
			
		// Check for additional death script
		string sDeathScript = GetLocalString( oDead, "DeathScript" );
		if ( sDeathScript != "" ) ExecuteScript( sDeathScript, oDead );	
	
		CountDead(oDead);
	
		ExecuteScript("k_death_remove_gui", oDead);
	
	
	
	}


	else
	{
		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);
	}
}

why complicate everything so much just make a script like this kill the pc if everyone is dead and that’s it(ihave this script)

1 Like

Can I take a look at your script then?

give me a couple of minutes.
I’ll get it right now.
i have a similar script it works well

1 Like

Thanks!

I did some additional testing with my OnPlayerDeath script and I noticed that this script isn’t run at all when a companion dies (maybe because, just as it’s stated, it just runs when the player character dies, which I didn’t realize at first). So I wonder where I should/put a script like this for this to work. Do I have to alter all the companions’ death scripts perhaps to check stuff there?

here take look on script

//Example Script
#include "x0_i0_enemy"
#include "nw_i0_spells"
#include "ginc_misc"
#include "ginc_group"
#include "ginc_debug"

#include "x2_inc_switches"
#include "nw_i0_spells"
void main()
{   object oPC=GetFirstPC();   
    
  
 
    // Create the effect to apply
effect eDeath = EffectDeath();


    // Create the visual portion of the effect. This is instantly
    // applied and not persistent with whether or not we have the
    // above effect.

    // Apply the visual effect to the target

	
    // Apply the effect to the object  
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eDeath, oPC);
 
 //SendMessageToPC(object oPlayer, string szMessage);
}

very simple yes?
Well, this is my case, he is on the creature, if the creature is killed, then pc dies.

and you need to do approximately the same thing but hang variables on the characters like alive and dead.Do you undestand?in my example this deat script in on death creature

I can make a script for you, it will take some time.

Then I was right in my previous post. I have to alter the death script of all the 9 potential companions and put something like your script there. Ok, that’s not very simple. It would have been a lot simpler to just alter ONE script like I tried to do, but if this is how it must go, I’ll do it.

EDIT: You don’t have to make a script like this for me. I can do it myself. No problem.

1 Like

weather i have an idea and it can be faster|i remenber i have group on death script it easy

here

// 01_lizman_journal

// When the lizardmen die, advance the journal state to 30.

// EPF 8/17/06

#include "ginc_group"

const string GROUP_LIZMEN = "grplizmen";

void main()
{
	GroupAddTag(GROUP_LIZMEN,"01_lizman1");
	GroupAddTag(GROUP_LIZMEN,"01_lizman2");
	GroupOnDeathSetJournalEntry(GROUP_LIZMEN, "01_lizardfolk",30);	
}

Now that you mention it, I could probably use the same death script on every companion, actually. I think I’ll try that. At the moment I’m using the stock gb_comp_death script on every companion so I’ll just do a modified version of that.

So I don’t even need to do a grouping. I didn’t realize this at first. Thanks for pointing me in the right direction!

1 Like

groups are not that difficult. You can open
Uninvited Guests module and see how it is / it’s not difficult. well then good luck with scripting. if anything ask me.

1 Like

Now it works. It was really simple. I just copied and edited the gb_com_death script and put it among my campaign scripts, thus it overrides the original version of the script. This is how I wrote it:

// gb_comp_death
/*
   OnDeath handler to queue KnockOut script for companions
*/
// ChazM 8/17/05
// BMA-OEI 12/19/05 knock out death system
// BMA-OEI 1/26/06 exit if owned and controlled
// BMA-OEI 2/27/06 DeathScript support, exit if not in PC faction
// BMA-OEI 2/28/06  
// NLC 7/14/08 - Increased NX2's hardcore quotient.

#include "ginc_companion"
#include "ginc_death"
#include "ginc_debug"
#include "x2_inc_switches"

const string VAR_GLOBAL_NX2_TRANSITIONS = "bNX2_TRANSITIONS";

void main()
{
	object oDead = OBJECT_SELF;
	PrintString( "gb_comp_death: " + GetName(oDead) + " executing OnDeath event" );
	
	if(GetGlobalInt("chicken"))
	{
		if ( GetIsDeathPopUpDisplayed(oDead) == FALSE )
		{
			if ( GetIsPartyPossessible(oDead) == FALSE )
			{
				effect eDeath = EffectDeath(FALSE, TRUE, TRUE);
    			ApplyEffectToObject(DURATION_TYPE_INSTANT, eDeath, GetFirstPC());							
				PrettyDebug( "** ginc_death: " + GetName(oDead) + "'s party wiped. displaying death screen", 30.0 );	
				ShowProperDeathScreen( oDead );
				return;
			}
		}
	}

	// Abort if dying character is owned PC (owned PCs should fire module OnDeath)
	if ( GetIsOwnedByPlayer( oDead ) == TRUE )
	{
		PrintString( "** gb_comp_death: " + GetName(oDead) + " is owned by a player. ABORT!" );
		return;	
	}
	
	// Check for additional death script
	string sDeathScript = GetLocalString( oDead, "DeathScript" );
	if ( sDeathScript != "" )	ExecuteScript( sDeathScript, oDead );

	// Abort if dying character is not in PC faction
	if ( GetIsObjectInParty( oDead ) == FALSE )
	{
		PrintString( "** gb_comp_death: " + GetName(oDead) + " not in " + GetName(GetFirstPC()) + "'s party. ABORT!" );
		return;
	}
	if( !GetGlobalInt( VAR_GLOBAL_NX2_TRANSITIONS ) )
	{
		//NX2 is HARDCORE! No auto-ressing!
		AssignCommand( oDead, KnockOutCreature( oDead ) );
	}
	

	
	else
	{
		if ( GetIsDeathPopUpDisplayed(oDead) == FALSE )
		{
			if ( GetIsPartyPossessible(oDead) == FALSE )
			{
											
				PrettyDebug( "** ginc_death: " + GetName(oDead) + "'s party wiped. displaying death screen", 30.0 );	
				ShowProperDeathScreen( oDead );
			}
		}
	}
}

I based it upon @lord_XD 's idea of just killing the PC when all the companions are dead.

2 Likes