Originally Posted by
1lokos
I try but still don't work, the plane (108) land and did a taxi to parking position where's remains.
These script (in game trigger) thing are crazy: I made crash landing on the area for spawn trigger, so the new plane spawn an take off, then another - with the same squadron letters spawn and take off...
Sokol1
The OnAircraftLanded event is not triggered when the aircraft actually lands. It's triggered when the aircraft finishes taxiing & comes to a stop. So in the script above, the aircraft will not despawn until 60 seconds after it finishes taxiing & comes to a stop.
To remove planes immediately after they finish taxiing to a spawn point .....
Code:
using System;
using maddox.game;
using maddox.game.world;
using maddox.GP;
public class Mission : AMission
{
public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded
double DespawnAfter = 1; // 1 second after landing & taxiing to spawn point
Timeout(DespawnAfter, () => // despawn after specified seconds
{
try { aircraft.Destroy(); }
catch { }
});
}
}
Alternatively, here's a little more sophisticated script. Here's how it works ...
1. It records all AI aircraft that takeoff in a list (the AirborneAiPlanes list).
2. It tests each AI aircraft in the list every 30 seconds to see if the aircraft is on (just above) the ground.
3. If the Ai aircraft is on the ground AND it's in the list of aircraft that have taken off, then it's assumed to be a landing aircraft. The script will wait 10 seconds then remove the AI aircraft from the battle.
4. This should result in AI aircraft being despawned very soon after landing, and overcome the problem of the OnAircraftLanded event not being triggered until after the aircraft has taxied all the way to a spawn point.
Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections;
using System.Collections.Generic;
using maddox.GP;
public class Mission : AMission
{
List<AiAircraft> AirborneAiPlanes = new List<AiAircraft>();
public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftTookOff(missionNumber, shortName, aircraft);
if (isAiControlledPlane(aircraft)) // aircraft that tookoff is an AI controlled plane
{
if (!AirborneAiPlanes.Contains(aircraft)) // plane is not in list of airborne AI planes
{
AirborneAiPlanes.Add(aircraft); // add aircraft to list of airborne AI planes
}
}
}
public override void OnTickGame()
{
base.OnTickGame();
if (Time.tickCounter() % (32 * 60 * 0.5) == 0) // every 30 seconds
{
if (AirborneAiPlanes.Count > 0) // there are airborne AI planes in the battle
{
foreach (AiAircraft aircraft in AirborneAiPlanes) // look at each AI aircraft that has taken off
{
if (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) < 0.01) // what's the altitude Above Ground Level
{
if (AirborneAiPlanes.Contains(aircraft)) // the aircraft has previously taken off
{
Timeout(10.0, () => // wait 10 seconds
{
AirborneAiPlanes.Remove(aircraft); // remove aircraft from the airborne AI aircraft list
aircraft.Destroy(); // remove aircraft from battle
});
}
}
}
}
}
}
private bool isAiControlledPlane(AiAircraft aircraft)
#region Returns whether aircraft is an Ai plane (no humans in any seats)
{ // returns true if specified aircraft is AI controlled with no humans aboard, otherwise false
if (aircraft == null) return false;
//check if a player is in any of the "places"
for (int i = 0; i < aircraft.Places(); i++)
{
if (aircraft.Player(i) != null) return false;
}
return true;
}
#endregion
}
Bookmarks