PDA

View Full Version : Despawn script for AI



69th_Spiritus_Mortem
Jun-03-2014, 14:20
Searched for this but couldn't find anything.

Anyone have a script for despawning AI ground units after they are destroyed? I want to be able to remove trains that have been destroyed so I can continue spawning other ones on the same set of tracks.

Thanks

No601_Swallow
Jun-04-2014, 01:43
I think Kodiak despawns trucks at the end of their run in this sample mission (http://forum.sturmovik.de/index.php/topic,721.0.html?PHPSESSID=da8130d037d907e6aeb0e07 b1bb5840c). It's google-translated, and - to be honest - a bit too complex for me to follow without some sort of pharmaceutical synapse boost, so good luck, but there might be what you need somewhere in there... :salute:

Salmo
Jul-04-2014, 01:01
using System;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;

public class Mission : AMission
{
public override void Inited()
{
base.Inited();
this.MissionNumberListener = -1;
}

public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)
{
base.OnActorDead(missionNumber, shortName, actor, damages);

if (actor is AiGroundActor)
{ // removed killed cars etc
Timeout((5 * 60), () => // remove actor 5 minutes after killed
{ // remove killed ground actors (cars etc)
if (actor != null & actor is AiGroundActor)
{
(actor as AiGroundActor).Destroy();
}
});
}

if (actor is AiAircraft)
{ // remove killed aircraft
Timeout((10 * 60), () => // remove aircraft 10 minutes after killed
{
if (actor != null & actor is AiAircraft)
{
(actor as AiAircraft).Destroy();
}
});
}
}
}