View Single Post
  #2  
Old 12-31-2011, 02:01 AM
wildwillie wildwillie is offline
Approved Member
 
Join Date: Aug 2010
Posts: 111
Default

salmo -

I use the OnActorCreated to create a list of actors created. It picks up statics that are Artillery, Ships, AAGuns, etc. It does not pick up static objects like fuel barrels, fire extinguisher, etc.

Each actor created is stored in a list that I can go through at mission end to destroy them.

Code:
 private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();


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
    }

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]+")");
                    }
                }
            }
            stats.disconnectStats();
        }
        catch (Exception ex)
        {
            System.Console.WriteLine("Stats.OnBattleStoped - Exception: " + ex);
        }
        #endregion
        //add your code here
    }
Hope that helps some.

WildWillie
Reply With Quote