View Single Post
  #6  
Old 12-09-2011, 10:59 AM
wildwillie wildwillie is offline
Approved Member
 
Join Date: Aug 2010
Posts: 111
Default

Salmo -

This is what I use to destroy actors between missions:

1st create a list to store all the objects at the top of the mission script:
Code:
    private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();
Then I modify the OnActorCreated Script:
Code:
 public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
    {
        #region stats
        base.OnActorCreated(missionNumber, shortName, actor);
        // Add actor to list of all Actors
        if (!allActors.ContainsKey(shortName))
           allActors.Add(shortName, actor);
        try
        {
            stats.newActor(shortName, actor);
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnActorCreated - Exception: " + ex);
        }
        #endregion
    }
Just use the IF statement part. The rest is for my ClodCommander program.

Finally I use the OnBattleStopped trigger to destroy any Actors which have not already been destroyed.

Code:
public override void OnBattleStoped()
    {
        #region stats
        base.OnBattleStoped();
        try
        {
            stats.battleStopped();
            // Loop through list of AiActors and destroy them all
            List<string> keys = new List<string>(allActors.Keys);
            for (int i = 0; i < keys.Count; i++)
            {
                AiActor a = allActors[keys[i]];
                AiAircraft aircraft = a as AiAircraft;
                if (aircraft != null)
                {
                    aircraft.Destroy();
                }
                else
                {
                    AiGroundActor aiGroundActor = a as AiGroundActor;
                    if (aiGroundActor != null)
                    {
                        aiGroundActor.Destroy();
                    }
                    else
                    {
                        System.Console.WriteLine("Stats.OnBattleStoped - Unknown Actor (" + a.Name()+") ShortName ("+keys[i]+")");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnBattleStoped - Exception: " + ex);
        }
        #endregion
        //add your code here
    }
Again any code starting with "stats." links to the ClodCommander program.
WildWillie
Reply With Quote