Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-19-2011, 12:29 PM
Flashman Flashman is offline
Approved Member
 
Join Date: May 2010
Posts: 109
Default Feature Request: Despawn AI aircraft Command

I've been struggling to get to grips with the FMB. Not so much the placement of objects (I made many IL2 missions) but its the scripting and related subjects. I am only interested in MP and producing maps for MP servers and at the moment I am finding it difficult to get the desired effects and there is one majoy stumbling block for me (and I think many others): Removing unwanted AI objects, especially flying AI aircraft from the mission/server.

I have a simple request: I want to be able to set a command to an AI object or group (be it aircraft, vehicles or ships.... anything AI) that will automatically despawn it. This could after a set time and/or when it reaches a set waypoint.

My preference would be that it would simply be one of the Options available in Properties>Waypoint>Action. So you would set the aircrafts route, target etc and when it reaches the final waypoint it simply despawns and is removed from the server.

I would also ask for an additional setting which sets the maximum time that the AI object/group is alive for. This would be useful is an object doesn't reach its final waypoint (it might be damaged or its route blocked or another propblem) or say if you want an aircraft group to loiter until a set time. I understand that its possible to remove ground object via a script but not flying AI aircraft.

I believe this would be a crucial and much welcomed addition to the FMB. Even with my limited knowledge of scripts (and in reality I borrow other people...thanks Ataros!) I can see the potential but at the moment the big handicap that I see is that we cannot reliably despawn AI objects once they are no longer useful.

If we can have a working, reliable, trusted method of despawning AI then the potential for multiday unpredictable missions (utilising the sub-mission system with scripts) is huge. It would mean you could have essentially a massive mission spread over a wide are with multiple objectives, but with clever mission making the actual number of AI etc in game would be smaller than the whole.
Reply With Quote
  #2  
Old 05-19-2011, 12:51 PM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

+1
I hope one day we have this integrated into FMB.

Another thing that we probably need is a sort of Mission Creation Toolkit including set of useful scripts for various purposes and then some add-ons that can be used to create a mission without knowledge of C#. Ideally a mission builder could just drop several script-files to his mission folder and add their names to a sort of mission.ini file and that is it. I remember how scary it was to open a C# file for the 1st time

Very often C# programmers and mission designers happen to be different people If programmers can deliver such a Toolkit mission builders would quicker produce more interesting missions.

Many people with knowledge of C# helped me a lot in creation of the script for Repka server. Thank you!
Reply With Quote
  #3  
Old 05-19-2011, 11:07 PM
TheEnlightenedFlorist TheEnlightenedFlorist is offline
Approved Member
 
Join Date: May 2011
Location: SLC, Utah, USA
Posts: 143
Default

Quote:
Originally Posted by Flashman View Post
I have a simple request: I want to be able to set a command to an AI object or group (be it aircraft, vehicles or ships.... anything AI) that will automatically despawn it. This could after a set time and/or when it reaches a set waypoint.
I think I've got something pretty similar to this working. This whole thing is base on a method called OnActorTaskCompleted(). This is called whenever an actor completes it's well... task. I can't tell you exactly what an actor is, if it includes human players or just AI, and I can't tell you exactly what a task is.

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();
            }
        }
    }
My code also depends on some of the code in this script.

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();
        }
    }

}
I hope this helps.
Reply With Quote
  #4  
Old 05-20-2011, 03:27 AM
SEE SEE is offline
Approved Member
 
Join Date: Oct 2009
Posts: 1,678
Default

+1 for the despawn waypoint.

I currently have a major headache with the script Trigger-Action Commands. I need an AI ac to land and for that ac to spawn another AI to take off. That results (or would) in a unwanted ground object doing nothing and showing up on the map if icons are enabled (despawn would be nice and simple for me). It should be possible to do this using the 'Group' and Passthorugh (an area on the runway) to act as a trigger but there appears to be a bug in that anything that lands automatically taxis to the same spawn point needed for the newly spawned ac - so it doesn't spawn! If you place an object on the runway and destroy the ac on the runway - the new ac spawns. You can use group and all the other commands with 'passthrough' to spawn Airgroups except a 'group' with a landing waypoint!

So, if there is a script please let me know or alternatively, can we also have a 're-arm' way point for AI ac to 'land - wait - and takeoff'!


Having spent hours on this problem I selected every available ac to land and they all appear to use the same algorithm for landing irrrespective of the FM for that ac........which may explain why some go 'tits up' on landing and others are OK! If you want to spawn a new AI - use the Anson....it can't land without going 'arse over tip' and your new AI spawns in its Hanger (and the Anson despawns!).....

Last edited by SEE; 05-20-2011 at 03:34 AM.
Reply With Quote
  #5  
Old 05-20-2011, 05:41 AM
Ataros Ataros is offline
Approved Member
 
Join Date: Jun 2010
Location: USSR
Posts: 2,439
Default

I think you can destroy an AC onAircraftLanding or do some damage to it, e.g. kill engine preventing it taxiing to a parking slot.
Reply With Quote
  #6  
Old 05-20-2011, 06:05 AM
ZaltysZ's Avatar
ZaltysZ ZaltysZ is offline
Approved Member
 
Join Date: Sep 2008
Location: Lithuania
Posts: 426
Default

Quote:
Originally Posted by Ataros View Post
I think you can destroy an AC onAircraftLanding or do some damage to it, e.g. kill engine preventing it taxiing to a parking slot.
OnAircraftLanded() is called only after plane stops. In case of AI, plane stops only after it reaches parking spot.
Reply With Quote
  #7  
Old 05-20-2011, 08:18 AM
Flashman Flashman is offline
Approved Member
 
Join Date: May 2010
Posts: 109
Default

Quote:
Originally Posted by SEE View Post
+1 for the despawn waypoint.

I currently have a major headache with the script Trigger-Action Commands. I need an AI ac to land and for that ac to spawn another AI to take off. That results (or would) in a unwanted ground object doing nothing and showing up on the map if icons are enabled (despawn would be nice and simple for me). It should be possible to do this using the 'Group' and Passthorugh (an area on the runway) to act as a trigger but there appears to be a bug in that anything that lands automatically taxis to the same spawn point needed for the newly spawned ac - so it doesn't spawn! If you place an object on the runway and destroy the ac on the runway - the new ac spawns. You can use group and all the other commands with 'passthrough' to spawn Airgroups except a 'group' with a landing waypoint!

So, if there is a script please let me know or alternatively, can we also have a 're-arm' way point for AI ac to 'land - wait - and takeoff'!


Having spent hours on this problem I selected every available ac to land and they all appear to use the same algorithm for landing irrrespective of the FM for that ac........which may explain why some go 'tits up' on landing and others are OK! If you want to spawn a new AI - use the Anson....it can't land without going 'arse over tip' and your new AI spawns in its Hanger (and the Anson despawns!).....
I dont know if you are trying to use the ACTION and TRIGGER settings as well as adding a script, but so far I have found that having a script disables the trigger and action setting, i.e. they just don't work. For that reason I dont use them at the moment and also we need the despawn script for MP.

But if you are using both that might help you find your solution.
Reply With Quote
  #8  
Old 05-20-2011, 08:20 AM
Flashman Flashman is offline
Approved Member
 
Join Date: May 2010
Posts: 109
Default

Hi EnlightenedFLorist,

I will have a look at that, though I have no knowledge of C++ and so far my scripts consist of hacking up other peoples and hoping they work!

Im really hoping 1C can include this Despawn idea as a setting in the FMB, it would be most helpful.

Anyhoo, I will have a look, do some swearing, and will see what I can come up with.

Cheers
Reply With Quote
  #9  
Old 05-20-2011, 08:49 AM
TheEnlightenedFlorist TheEnlightenedFlorist is offline
Approved Member
 
Join Date: May 2011
Location: SLC, Utah, USA
Posts: 143
Default

Quote:
Originally Posted by Flashman View Post
so far I have found that having a script disables the trigger and action setting, i.e. they just don't work. For that reason I dont use them at the moment and also we need the despawn script for MP.
I think what might be happening is that when you add a script, the game expects you to deal with triggers and actions in the script. They work fine with my scripts. I actually don't know how to use triggers or actions without a script.

If you need help writing a script, you can post it on the forum and I'm sure there'll be plenty of people willing to help you out.

Also, scripts are written in C#, not C++. C# is very much like Java and way easier to work with than C++. I don't want you to go learning C++ when you should be learning C#.

Last edited by TheEnlightenedFlorist; 05-20-2011 at 09:15 AM.
Reply With Quote
  #10  
Old 05-20-2011, 11:22 AM
SYN_Flashman SYN_Flashman is offline
Approved Member
 
Join Date: Feb 2011
Posts: 48
Default

Quote:
Originally Posted by TheEnlightenedFlorist View Post
Also, scripts are written in C#, not C++. C# is very much like Java and way easier to work with than C++. I don't want you to go learning C++ when you should be learning C#.
Now worries on that score, I wasn't planning on learning either, my brain isn't big enough! I learn just enough to make it appear i know what im doing when in fact I haven't a bloody clue. Mcuh like the rest of my life really....

I will have a look at using triggers and actions within the script itself as some are quite useful. I did have a mission where if one plane was shot down another would spawn... lots of potential with that one.

There is a lot to learn, but equally there is a lot we can do that is really interesting.

I will post up my next daft script and see what people think later on when im home. Cheers!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:19 PM.


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