Death Scripts

More
18 years 8 months ago #18760 by GrandpaTrout
Death Scripts was created by GrandpaTrout
Some odd death script behavior was discovered. If a player is given a death script and the player is killed by collision, the death script will trigger.

If a player wingman also has a death script, and is docked to another ship when killed in collision, the death script will not go off.

The work around is to spawn a task that follows around the ship and looks for its death.

Please Log in or Create an account to join the conversation.

More
18 years 8 months ago #14983 by MajorTom
Replied by MajorTom on topic Death Scripts
The task that follows a ship around and looks for it's death is already there. (Thats what triggers the death script).

To catch any player deaths by collision you could add the following to your death script:

last_attacker = iShip.Cast( iShip.LastAttacker( iShip.Cast(player) ) );


if ( ( last_attacker == none ) || ( last_attacker == iShip.Cast(player) ) )
{
// we topped ourselves
// do something (different to the normal death script) here
}else //the usual....

If a player wingman also has a death script, and is docked to another ship when killed in collision, the death script will not go off.

Thats because the docked sim is a child and no longer an independent entity.

You'll find that the same applies to any cargo pods docked to anything that dies by collision (a wingman). They (as child) just disappear mysteriously together with the parent sim which probabaly isn't in the players interest in a trade based game, and also messes up your reputation monitoring.
(I went to a lot of trouble to fix that in the EpicOnline mod)

If you have your own death scripts:
I would add a little routine to make the ship undock any children before you let the death script destroy the sim. (you need one iShip.UndockSelf command per child) Then each undocked sim will go through it's assigned death script (for example as it is destroyed by the explosion in it's proximity).

If you are relying on the stock death scripts:
You can re-set the death script on any sim by changing it's appropriate ObjectStringProperty. I would recommend, that you re-set the death script to a custom version (which includes the undock routine), for parent sims that are docked to something (perhaps whenever the player or a wingman enters an area?) instead of running your own "death watch" task to monitor every ship and cargo pod in the game.

One point about writing you own death scripts:
The originals contain code that, among other things, resets the HUD. When you call sim destroy in your death script, the sim just dissappears from the contact list and the HUD does not automatically swith to the next nearest target (sometimes that will cause a crash) if it doesn't crash, the player must manually select the next target.

To remedy this: just before you call Sim.Destroy (sim) at the end of your custom death script you can call one of the iDeathScript.h functions for example: iDeathscript.Explosives(sim).

cheers



Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
18 years 8 months ago #14985 by mdvalley
Replied by mdvalley on topic Death Scripts
I use iSim.StartExplosion, do the undock thing, wait a few more seconds, then iSim.StopExplosion to make the big boom and destroy the sim. That's how the megapods in MegaTrucking die.

Please Log in or Create an account to join the conversation.

More
18 years 8 months ago #14989 by MajorTom
Replied by MajorTom on topic Death Scripts

Originally posted by mdvalley

I use iSim.StartExplosion, do the undock thing, wait a few more seconds, then iSim.StopExplosion to make the big boom and destroy the sim. That's how the megapods in MegaTrucking die.

There is a iDeathScript.MegaPodDeath( hsim sim ); in iDeathScript.h Have you ever tried that out? I'm mighty curious.

I dunno, but I'm guessing it will spit out the little pods and then make the megapod explode?


Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
18 years 8 months ago #14996 by mdvalley
Replied by mdvalley on topic Death Scripts
I was never able to figure out how the traffic megapods worked, so I had to re-write everything about them. (I suspect that PS cheated when they created them. You ever seen a stock megafreighter load pods?) Since they use a different system to keep track of what’s in them, they needed a little routine to spit out when they die. So iDeathScript.MegaPodDeath doesn't work, no.

Please Log in or Create an account to join the conversation.

More
18 years 7 months ago #15004 by GrandpaTrout
Replied by GrandpaTrout on topic Death Scripts
Thanks! Very helpful information. The case comes up when the player is carrying a wingman and both are struck by a moving asteroid. I will give the undock a try. Hopefully I can free the wingman before it dies and get the death script to trigger.

Please Log in or Create an account to join the conversation.