Problem with deathscript

I have a creature that the player fights. When this creature dies I am using a script like this on the OnDeath:

void PlayCustomAnimationVoid(object oObject, string sAnimation, int iLoop = 0, float fSpeed = 1.f)
{
	PlayCustomAnimation(oObject, sAnimation, iLoop, fSpeed);
}

void Laydown(object oTarget)
{

	PlayCustomAnimationVoid(oTarget,"*proneB",1);
	SetOrientOnDialog(oTarget, FALSE);
}

void DoAllTheStuff()
{

		object oPC = GetFirstPC();
		SendMessageToPC(oPC,"Death script is running");	

		object oDead = OBJECT_SELF;
		location lDead = GetLocation(OBJECT_SELF);
		CreateObject(OBJECT_TYPE_CREATURE,"malvrik",lDead);
		object oMalvrik = GetObjectByTag("malvrik");
		DelayCommand(0.2,Laydown(oMalvrik));
		

}

void main()
{
		

		AssignCommand(GetModule(), DoAllTheStuff());
    	//ExecuteScript("nw_c2_default7", OBJECT_SELF);
		
}

I can confirm that the script is running. Now, the problem is that the other object called “malvrik” isn’t spawned in. I think this is due to the game having problem with the dead creature and not being able to find the location of the dead creature since it’s now dead. However, I can’t come up with a way to solve this. I need the location of the creature when it dies. How does one accomplish this? Do I need to check the location when the creature is almost dead perhaps, and spawn a waypoint there and then use that waypoint as reference for spawning in the new object called “malvrik”?

You’re assigning the command to the module here:

AssignCommand(GetModule(), DoAllTheStuff());

As such, the following commands:

object oDead = OBJECT_SELF;
location lDead = GetLocation(OBJECT_SELF);

are being run from the perspective of the module; OBJECT_SELF will refer to the module rather than the dead creature. Try changing that and see if works.

2 Likes

Ah, ok. Didn’t realize that mistake. I’ll test it.

@Akhacha - That seemed to make it work. I did it like:

object oDead = GetObjectByTag("creature");
location lDead = GetLocation(oDead );

I just hope it always works. I know that dead objects/creatures can be finnicky, but hopefully by using the GetModule like I did, the game will instantly grab the location of the dead creature before it fades away.

There’s only one thing I would have liked to add, but I’m not sure how to do that with scripting, is to make the game notice in which direction the dead creature lies, and spawn in the new creature that has the prone animation face the same way. I hope you understand what I’m saying.

You could try GetFacing() / SetFacing().

2 Likes

@Akhacha - That actually worked like a charm.

1 Like