![]() |
|
#3
|
|||
|
|||
|
Quote:
I can tell you that this method is called when a Spitfire and a tank reach their final waypoints. Anyway, here's the script. This is the code that I wrote. You won't have this in your script, although you might have some code in the OnActorTaskCompleted() method. Code:
public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);
//destroy it if it's an aircraft
damageAiControlledPlane(actor);
//destroy it if it's a grond object
destroyGroundActor(actor);
}
private void destroyGroundActor(AiActor actor)
{
//loop through all of the ground groups from both armies
foreach (AiGroundGroup g in GamePlay.gpGroundGroups(1))
{
//if we find our actor in the ground group...
if (g.Name() == actor.Name())
{
//Destroy them! Destroy them all!
foreach (AiActor a in g.GetItems())
(a as AiGroundActor).Destroy();
}
}
foreach (AiGroundGroup g in GamePlay.gpGroundGroups(2))
{
//if we find our actor in the ground group...
if (g.Name() == actor.Name())
{
//Destroy them! Destroy them all!
foreach (AiActor a in g.GetItems())
(a as AiGroundActor).Destroy();
}
}
}
http://forum.1cpublishing.eu/showpos...0&postcount=92 You probably already have this because this is the code people are using to destroy aircraft that players abandon. And finally, here's the script in it's entirety so you can see how it all fits together. Code:
using System;
using System.Collections;
using maddox.game;
using maddox.game.world;
using System.Diagnostics;
public class Mission : AMission
{
public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
{
base.OnActorTaskCompleted(missionNumber, shortName, actor);
//destroy it if it's an aircraft
damageAiControlledPlane(actor);
//destroy it if it's a grond object
destroyGroundActor(actor);
}
private void destroyGroundActor(AiActor actor)
{
//loop through all of the ground groups from both armies
foreach (AiGroundGroup g in GamePlay.gpGroundGroups(1))
{
//if we find our actor in the ground group...
if (g.Name() == actor.Name())
{
//Destroy them! Destroy them all!
foreach (AiActor a in g.GetItems())
(a as AiGroundActor).Destroy();
}
}
foreach (AiGroundGroup g in GamePlay.gpGroundGroups(2))
{
//if we find our actor in the ground group...
if (g.Name() == actor.Name())
{
//Destroy them! Destroy them all!
foreach (AiActor a in g.GetItems())
(a as AiGroundActor).Destroy();
}
}
}
private bool isAiControlledPlane(AiAircraft aircraft)
{
if (aircraft == null)
{
return false;
}
Player[] players = GamePlay.gpRemotePlayers();
foreach (Player p in players)
{
if (p != null && (p.Place() is AiAircraft) && (p.Place() as AiAircraft) == aircraft)
{
return false;
}
}
return true;
}
private void damageAiControlledPlane(AiActor actor)
{
if (actor == null || !(actor is AiAircraft))
{
return;
}
AiAircraft aircraft = (actor as AiAircraft);
if (!isAiControlledPlane(aircraft))
{
return;
}
if (aircraft == null)
{
return;
}
aircraft.hitNamed(part.NamedDamageTypes.ControlsElevatorDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsAileronsDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsRudderDisabled);
aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFailure);
aircraft.hitNamed(part.NamedDamageTypes.Eng0TotalFailure);
aircraft.hitNamed(part.NamedDamageTypes.Eng1TotalFailure);
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
private void destroyPlane(AiAircraft aircraft)
{
if (aircraft != null)
{
aircraft.Destroy();
}
}
}
|
|
|