View Single Post
  #1  
Old 07-27-2011, 07:49 AM
SNAFU SNAFU is offline
Approved Member
 
Join Date: Feb 2011
Posts: 324
Default Removal of AI from submissions

I am trying to remove the AI which was loaded via submission with the script of the submission. The submission is lasting max. 3hrs then a new missions will be laoded. I use the following for removal of the AI planes


Code:
public override void OnTickGame()
{
   double initTime;    

    if (Time.tickCounter() % 324000 == 323999) // 180mins 
  {

foreach (int army in GamePlay.gpArmies())
            {
                foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
                {
                    if (ActorName.MissionNumber(group.Name()).Equals(MissionNumber))
                    {
                        AiActor[] members = group.GetItems();
                        for (int i = members.Length - 1; i > -1; i--)
                        {
                            (members[i] as AiAircraft).Destroy();
                        }
                    }
                }
                foreach (AiGroundGroup group in GamePlay.gpGroundGroups(army))
                {
                    if (ActorName.MissionNumber(group.Name()).Equals(MissionNumber)) 
                    {
                        AiActor[] members = group.GetItems();
                        for (int i = members.Length - 1; i > -1; i--)
                        {
                            (members[i] as AiGroundActor).Destroy();
                        }
                    }
                }
            }
	}
}
			
		public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
				{

        base.OnActorCreated(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
        {
            Timeout(324000, () => {	// nach 180minuten werden AI entfernt
                if (actor != null)
                { 
                    (actor as AiGroundActor).Destroy(); 
                }
            });
        }
    }
The "AIGroundGroup" is not really necessary I think, due the fact that actuall no ground groups are on the map, on AI ships, which should be take out of the map by the last part "AIGroundActor", at least that worked while testing. But now I already declared a "public override void OnTickGame()" in the main script to have time counter for the submission loading. Might that cause some problems and are there some issues I ve overseen? Testing on a small map it worked well with the removal of planes and groundunits, but it might be related to planes dissappearing or not even spawing visible, but possible to switch onto in the external view.
The mission with this script will be loaded into the main map after 1minute, so the 324000 ticks should acutally be far away?
__________________
http://cornedebrouwer.nl/cf48e
Reply With Quote