Official Fulqrum Publishing forum

Official Fulqrum Publishing forum (http://forum.fulqrumpublishing.com/index.php)
-   FMB, Mission & Campaign builder Discussions (http://forum.fulqrumpublishing.com/forumdisplay.php?f=203)
-   -   how to remove AI planes and AI vehicles? (http://forum.fulqrumpublishing.com/showthread.php?t=31457)

David198502 04-24-2012 01:19 PM

how to remove AI planes and AI vehicles?
 
1 Attachment(s)
hey guys....im just building a mission, where i try to load submissions randomly into one main mission.

what i dont know how to achieve though is, how i can "destroy" ai planes if they have landed, and also vehicles or trains, when they have reached a certain waypoint....

i have attached the complete mission...
there is one main mission, and 3 submissions which will be loaded randomly every 30seconds.
the problem with it is, that the trains and vehicles will just stay on the map.
i would like them to have destroyed when they reach their last waypoint....

in the script, there is a way to "destroy" planes after a certain time, but i would like to change it, that they will get destroyed after they have landed...
(i know that this will happen automatically, but only after 10 minutes)i want that the planes are destroyed after maybe 30seconds when they have landed.

David198502 04-24-2012 03:27 PM

1 Attachment(s)
here is the script only...

FG28_Kodiak 04-24-2012 03:44 PM

To remove landed, crashlanded AI-Planes or Groundactors after completing their task :
Code:

using System;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();

        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

// to remove GroundActors after their Task is completed
  public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
            if (IsActorDestroyable(actor))
                (actor as AiGroundActor).Destroy();
    }
}


David198502 04-24-2012 03:45 PM

thx Kodiak...will try that, though im not sure how to implement that part into my already existing one

David198502 04-24-2012 03:58 PM

ok the mission now works, so that the submissions will be loaded and also the planes are destroyed after they have landed.

but ground vehicles and trains just remain on the map after they have reached their last waypoint.how can i make it, that they achieve their "task"?


HTML Code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
    Stopwatch MissionTimer = new Stopwatch();

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionTimer.Start();
        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

// to remove GroundActors after their Task is completed
  public override void OnActorTaskCompleted(int missionNumber, string shortName, AiActor actor)
    {
        base.OnActorTaskCompleted(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
            if (IsActorDestroyable(actor))
                (actor as AiGroundActor).Destroy();
    }
    public override void OnTickGame()
    {
   
        if(MissionTimer.Elapsed.TotalSeconds >
= 30)  //Loads a mission every 120s
        {
            Random ZufaelligeMission = new Random();

            MissionTimer.Restart(); // Sets timer to 0 and start again
   
            switch (ZufaelligeMission.Next(1,4))
            {
                case 1:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
                    break;
                case 2:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
                    break;
                case 3:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
                    break;

            }
        }
    }
}


FG28_Kodiak 04-24-2012 04:51 PM

Removing Ai-Planes after landing, should work (have tested it), but OnActorTaskCompleted seems to work not correctly. Must make more tests, but in next Patch it should be possible to get the current waypoint from an Actor so should be no problem to remove an Actor if it reached the last waypoint. But we must wait for the patch.

Code:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{
    Stopwatch MissionTimer = new Stopwatch();

    public override void OnBattleStarted()
    {
        base.OnBattleStarted();
        MissionTimer.Start();
        MissionNumberListener = -1;
    }


    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);


        if(IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftLanded(missionNumber, shortName, aircraft);

        if (IsActorDestroyable(aircraft))
            aircraft.Destroy();
    }


    private bool IsActorDestroyable(AiActor actor)
    {
        bool actorDestroyable = true;

        //Check if actor is empty (no Player)
        if (actor is AiAircraft)
        {
            if ((actor as AiAircraft).ExistCabin(0))
                for (int i = 0; i < (actor as AiAircraft).Places(); i++)
                {
                    if ((actor as AiAircraft).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }
        else if (actor is AiGroundActor)
        {
            if ((actor as AiGroundActor).ExistCabin(0))
                for (int i = 0; i < (actor as AiGroundActor).Places(); i++)
                {
                    if ((actor as AiGroundActor).Player(i) != null)
                    {
                        actorDestroyable = false;
                        break;
                    }
                }
        }

        return actorDestroyable;
    }

   
    public override void OnTickGame()
    {
   
        if(MissionTimer.Elapsed.TotalSeconds >= 30)  //Loads a mission every 120s
        {
            Random ZufaelligeMission = new Random();

            MissionTimer.Restart(); // Sets timer to 0 and start again
   
            switch (ZufaelligeMission.Next(1,4))
            {
                case 1:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission1.mis");
                    break;
                case 2:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission2.mis");
                    break;
                case 3:
                    GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission3.mis");
                    break;
            }
        }
    }

}


David198502 04-24-2012 04:59 PM

thx Kodiak,..see my above post which i have edited just now...
this time i was able to adjust the script by myself that it worked in the end,...except the ground vehicles of course

David198502 04-24-2012 09:37 PM

btw,...is there a way, to limit the number of planes with scripting?
cause at it is now, the mission will soon have plenty of planes and the numbers will increase continually.
of course its possible to adjust the the script, that the missions will not be loaded that often, or the missions, that the planes will land(destroyed) sooner.

but this approach requires much time adjusting the missions, espesially when one has 60+ submissions.

so i thought it would be really comfortable, if it would be possible to limit the numbers with the script. if the maximum amount of planes is reached, then the script will not load a new submission, until some planes get shot down, or land(destroyed)...

FG28_Kodiak 04-25-2012 06:06 AM

yes its possible.


Code:

    public int GetSumAllPlanes()
    {
        int planeCount = 0;
        List<AiAirGroup> allAirgroups = new List<AiAirGroup>();

        if (GamePlay.gpAirGroups(1) != null)
            allAirgroups.AddRange(GamePlay.gpAirGroups(1));

        if (GamePlay.gpAirGroups(2) != null)
            allAirgroups.AddRange(GamePlay.gpAirGroups(2));


        allAirgroups.ForEach(item =>
            {
                foreach (AiAircraft ac in item.GetItems())
                {
                    planeCount++;
                }
            });

        return planeCount;
    }

before loading a new mission you can check for example
Code:

if(GetSumAllPlanes() < maxPlanes)
You can also use AiAirgroup 's NOfAirc but it seems buggy in the current Clod Version, it sometimes not show the correct Numbers of Airplanes in a group. So it's better to add the Aircrafts like above.

David198502 04-25-2012 06:14 AM

thank you Kodiak, without you i would give up on that thing i think,cause for me its like reading chinese....

but if i can implement that "planecounter" in my script above, then i could build a mission, which gets more and more unpredictable with every submission i add...
that would be really neat.
but i fear i will again have trouble to implement that part correctly into my script...
but will try out immediately..
btw, what do you mean with:"before loading a new mission you can check for example"?
and where and how do i implement this last line of code?


PS: now in my script i have the possibility to "destroy" planes when they land, or after a certain amount of time, but i would like to have the possibility that some planes (bombers) get destroyed when they reach a certain waypoint behind the frontlines....im sure thats possible, but couldnt find it yesterday.


All times are GMT. The time now is 01:05 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.