Results 1 to 25 of 25

Thread: Script for random composition of air units

  1. #1
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Question Script for random composition of air units

    Hi guys!

    I am a quite experienced IL-2 1946-er, but VERY noobish when it comes to CLOD. Being an avid FMB-er I've already made some inroads with the CLOD FMB, but the whole Script thing is quite new to me. But I do understand the beauty and not least the sheer potential of scripts system. So I will try to learn that thing as well, even though right now I can't code even if my life depended on it.

    Now I'm learning the CLOD FMB by building missions!

    My question: is there already some script around that you can use to randomize the composition of AI air groups? (Mainly randomize the aircraft type, the number and even the skill.)

    This would really be a great thing! It would greatly enhance re-playability of both missions and campaigns. (This, combined with the branched mission structure - another really nice feature of CLOD, from my simple campaign building perspective.) Trying to reinvent the wheel (i.e. do a script that has already been done) is never a good way to use your time, especially when your new wheel probably wouldn't be too great anyway ...

    All the best
    /Poltava

  2. #2
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    I think Salmo had one, have a search through his postings.

    The key though is not purely randomisation. Because the AI are so hit and miss you really are better off playing with the settings to find the sweet spot you want to give say a "good, ace, noob" setting, then randomising between those. Otherwise you will have bloody stupid barrel rolling AI everywhere and that won't add to your campaign or mission.

  3. #3
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Thanks! Will have a look! (I've found and applied his script for randomized weather BTW.)

    And I WILL avoid all randomizing of the AI skills ...

  4. #4
    Public Relations ATAG_Lewis's Avatar
    Join Date
    Jan 2012
    Location
    Sheffield UK
    Posts
    7,253
    Post Thanks / Like
    Total Downloaded
    506.15 MB

    Re: Script for random composition of air units

    Welcome to the community and forums Poltava...~S~

    Many of us flew IL2 1946 for years before we came to CLOD....The transition is not smooth but the benefits are excellent...CLOD flies nothing like IL2 1946...and I found I couldn't get on with TrackIR in IL2 1946 either but using it in CLOD felt right...so that was a good thing...

    Anyway....

    Checkout the 'Beginners Guide'...for info and tips...It will save you a heap of time in getting up to scratch.....and its a really fun learning curve anyway..

    Beginners Guide Link Here

    Windows Management Guide

    Also try youtube for startup procedures on all the aircraft...

    I recommend getting in the online server as soon as you can take off if that's ultimately where you'd like to fly...I flew single player for 30 minutes before I took the plunge...The ATAG online server is a great environment to learn and there's not really any damage you can do in there as a new player.....It is also mission based just with real players trying to foil your objectives...If you are concerned then pick an airstrip furthest from the front line (there always is one or two on every map) and get some alt before you go hunting...You'll get tagged a lot but there are tricks you learn out of pure desperation in those first few weeks that you'll be able to use later...I know cos I still use the same tricks I learned then too because they work...and never underestimate the stall to get you out of a tight fix...That sometimes works too...

    TeamSpeak is optional but you'll learn a whole lot faster with it even if you say very little once you are on the server...You are quite welcome to just listen if you feel more comfortable with that....so you don't actually need a mic either...Try it and see!...

    How to set up Teamspeak


    Here are a few fun, helpful and interesting links amongst these forums

    Most Watched CLOD Videos

    Easy Allied CEM for New Players

    Joystick and Hardware Thread

    ATAG Forum Age Poll Results

    Nvidea Control Panel Settings

    Downloads

    Contact Spotting Test

    and....Don't forget to keep up with the latest on the TeamFusion new aircraft and patch news...You could well be AMAZED!

    TeamFusion Facebook Updates


    Any questions then you've come to the right place....

    Good to have you with us buddy...and remember its all about the Fun!!!

    ...Lew...
    Last edited by ATAG_Lewis; Dec-27-2016 at 10:19.
    "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt.'' - Bertrand Russell
    1.618 - You know this number?
    My Turing machine :CPU: Intel Core i7 2700K 3.50GHz Sandybridge, Motherboard: Asus Maximus IV Extreme -Z Intel Z68 (Socket 1155) PCI-Express DDR3,
    RAM: 8GB (2x4GB) DDR3 Dual Channel Kit, Graphics Card: Nvidia GeForce GTX 970 4096MB GDDR5, OS:Windows 10
    Joystick: Microsoft Sidewinder II ForceFeedback Joystick, Throttle: CH Products Pro Throttle
    ATAG_Lewis Youtube Channel

  5. Likes danperin liked this post
  6. #5
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Thanks for the info, Lewis!

    All the best
    /Poltava

  7. #6
    Manual Creation Group ATAG_Ezzie's Avatar
    Join Date
    Feb 2014
    Posts
    2,301
    Post Thanks / Like
    Total Downloaded
    115.2 KB

    Re: Script for random composition of air units

    Quote Originally Posted by Poltava View Post
    Thanks! Will have a look! (I've found and applied his script for randomized weather BTW.)

    And I WILL avoid all randomizing of the AI skills ...
    Good you found Salmo's stuff Poltava and made contact with SOW Reddog - the random weather script is excellent and Reddog was very patient with me when I was trying to learn scripting.

    Re the weather script - watch the wind settings. when I used this script online a lot of players found some of the winds too difficult to take off in and we had to wind the speeds down lower than what Salmo used. Eventually we removed the random weather all together as the random nature didn't seem to be a hit with some players.

    Will probably try it again when I next make a mission.

    Ezzie

  8. #7
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Good to know - thanks!

    I am doing this step by step, trying to build more and more complex missions. The whole script thing is of course quite new, but the potential seems really wonderful. There are many things in CLOD that really comes as a pleasant surprise, not least the feel of flying, which is great.

    I welcome all tips regarding great scripts! I've already found quite a few

  9. #8
    Novice Pilot
    Join Date
    Feb 2014
    Posts
    68
    Post Thanks / Like
    Total Downloaded
    81.47 MB

    Re: Script for random composition of air units

    I've tried some of your mission in 1946 especially the night fighting ones. so welcome to CLOD
    I've got something you may like to look into that helped me learn the scripting side of things

    Heres the link
    http://www.mediafire.com/file/cg9hfr.../ReleaseV6.rar

  10. #9
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Migman!

    Thank you! That's very, very impressive! You will soon be putting us poor builders of static campaigns out of work ...

  11. #10
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    BTW: I found a script that randomizes the number in AI airgroups, by Salmo.

    http://forum.1cpublishing.eu/showthread.php?t=34479

    Excellent! Now I'm off to test it!

    PS. And another variant, with a different approach, to be found here:

    http://forum.1cpublishing.eu/showthread.php?t=31523
    Last edited by Poltava; Dec-28-2016 at 06:17.

  12. #11
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    So now I've tested both.

    1.) Salmos script runs without a hitch, does what it promises to do. A simple yet elegant and very controllable solution with the red crosses. Great job!

    2.) The script by David198502 is another matter. The concept there is to spawn a random submission when the mission starts. Could be very useful. (Although having 29 submissions for a single mission seems to be a bit over the top, IMHO.) But something is amiss. When I run the mission there doesn't seem to be any submission called up. That single Bf109 stays very much single: no AI is spawned.

    Can anyone of the talented coders here shed light on this? This is the script:

    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 OnActorCreated(int missionNumber, string shortName, AiActor actor)
        {
            base.OnActorCreated(missionNumber, shortName, actor);
    
            if (actor is AiAircraft)
            {
                switch ((actor as AiAircraft).InternalTypeName())
                {
    
                    case "bob:Aircraft.He-111P-2":
                    case "bob:Aircraft.BlenheimMkIV":
    
                        Timeout(3000, () =>    // Time in Seconds
                             {
                                 (actor as AiAircraft).Destroy();
                             });
                        break;
                }
            }
        }
    
        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 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;
        }
    
    public override void OnTickGame()
        {
        
            if(MissionTimer.Elapsed.TotalSeconds >= 130 && GetSumAllPlanes() < 60)  //Loads a mission every 120s and only if the sum of all planes < 50
            {
                Random ZufaelligeMission = new Random();
    
                MissionTimer.Restart(); // Sets timer to 0 and start again
        
                switch (ZufaelligeMission.Next(1,30))
                {
                    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;
                    case 4:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission4.mis");
                        break;
                    case 5:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission5.mis");
                        break;
                    case 6:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission6.mis");
                        break;
                    case 7:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission7.mis");
                        break;
                    case 8:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission8.mis");
                        break;
                    case 9:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission9.mis");
                        break;
                    case 10:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission10.mis");
                        break;
                    case 11:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission11.mis");
                        break;
                    case 12:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission12.mis");
                        break;
                    case 13:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission13.mis");
                        break;
                    case 14:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission14.mis");
                        break;
                    case 15:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission15.mis");
                        break; 
                    case 16:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission16.mis");
                        break;
                    case 17:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission17.mis");
                        break;
                    case 18:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission18.mis");
                        break;
                    case 19:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission19.mis");
                        break;
                    case 20:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission20.mis");
                        break;
                    case 21:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission21.mis");
                        break;
                    case 22:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission22.mis");
                        break;
                    case 23:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission23.mis");
                        break;
                    case 24:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission24.mis");
                        break;
                    case 25:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission25.mis");
                        break;
                    case 26:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission26.mis");
                        break;
                    case 27:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission27.mis");
                        break;
                    case 28:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission28.mis");
                        break;
                    case 29:
                        GamePlay.gpPostMissionLoad("missions\\Blitzkrieg\\mission29.mis");
                        break;
    
                }
            }
        }
    }
    And yes, all the submissions are in place. Link to his original posting with D/L here: http://forum.1cpublishing.eu/showthr...918#post714918

  13. #12
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    I can't remember, is gpPostMissionload local to the mission file? Have you put the sub mis files in the right folder?

    Anything in the console?

  14. #13
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Reddog - but of course!

    The script is looking for the missions in the wrong place. (And a strange one at that, not in "Single" but in "missions".) Fixed that. Now it works!

    The script as it stands loads a new submission picked at random every 120 seconds, until a limit of 60 aircraft in the air is reached. I want it to just load ONE submission picked at random, once. (And skip the 60 aircraft limit.)

    Can this be done by just erasing the section starting "if(MissionTimer.Elapsed.TotalSeconds"? Sorry for being such a total scripts NOOB ...

    All the best
    /P

  15. #14
    ATAG Member ATAG_Freya's Avatar
    Join Date
    Jan 2013
    Location
    Lethbridge, Alberta
    Posts
    3,592
    Post Thanks / Like
    Total Downloaded
    16.16 MB

    Re: Script for random composition of air units

    if(MissionTimer.Elapsed.TotalSeconds >= 130 && GetSumAllPlanes() < 60)
    to

    if(MissionTimer.Elapsed.TotalSeconds >= 3600 && GetSumAllPlanes() < 60)

    (if mission is an hour long)




    That's prob what I would do, but I don't script I just mangle things a bit lol

  16. #15
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    If you want to only load one mission, say after an hour, then I would do something like this
    Code:
    Bool Mis = true; //variable so that you don't load more than one mission - put this in OnBattlestarted like MissionTimer 
    
    //this bit in OnTickGame
    If (Mis && MissionTimer.Elapsed.TotalSeconds>=3600)
    {
    Mis=false;
    //Load mission here 
    }
    I've done this on my phone so I can not guarantee the syntax etc.

  17. #16
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Thanks guys! Super!

    I will try both solutions, and then report back!

  18. #17
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Unhappy Re: Script for random composition of air units

    No, fellas - sorry: I botched up ... I really hope that you can bear me out: I am new to CLOD, but really want to try building missions and campaigns using the full potential of this game.

    This is the code as it stands now:

    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;
            Bool Mis = true;        //variable so that you don't load more than one mission
        }
       public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
        {
            base.OnActorCreated(missionNumber, shortName, actor);
    
            if (actor is AiAircraft)
            {
                switch ((actor as AiAircraft).InternalTypeName())
                {
    
                    case "bob:Aircraft.He-111P-2":
                    case "bob:Aircraft.BlenheimMkIV":
    
                        Timeout(3000, () =>    // Time in Seconds
                             {
                                 (actor as AiAircraft).Destroy();
                             });
                        break;
                }
            }
        }
    
        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 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;
        }
    
    public override void OnTickGame()
        {
        
            if(MissionTimer.Elapsed.TotalSeconds >= 3600 && GetSumAllPlanes() < 90)  //Loads a mission every 3600s and only if the sum of all planes < 90
        }
    Bool Mis = false; //Load mission here 
        {
                Random ZufaelligeMission = new Random();
    
                MissionTimer.Restart(); // Sets timer to 0 and start again
        
                switch (ZufaelligeMission.Next(1,3))
                {
                    case 1:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission1.mis");
                        break;
                    case 2:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission2.mis");
                        break;
    		case 3:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission3.mis");
                        break;
                }
            }
        }
    }
    You have already spotted my errors, I guess. The console says this:

    System.Exception ... Test_random.cs (132.5) error CS.1519: Invalid token '(' in class, struct, or interface member declaration
    DITTO (135.33) DITTO
    DITTO (137.43) DITTO
    DITTO (140.47) DITTO
    DITTO (143.47) DITTO
    DITTO (146.47) DITTO
    System.Exception ... Test_random.cs (149.9) error CS.1022: Type or nameface definition, or end-of-file expected
    DITTO (150.5) DITTO
    DITTO (151.1) DITTO


    1.) Notice that compared to the last script I changed the number of sub missions possible to load (now it's just 3) and the location of these file. (No need for 29 sub missions in what I am trying to do.)
    2.) The script could be simplified even further, as there A.) will be no need for the check of the total number of aircraft in the air, or B.) destroy landed AI aircraft. What it needs to do is just load randomly one of 3 sub missions at the start of the mission.

    Sorry about being such a pain ...

    All the best
    /P

  19. #18
    ATAG Member ATAG_Freya's Avatar
    Join Date
    Jan 2013
    Location
    Lethbridge, Alberta
    Posts
    3,592
    Post Thanks / Like
    Total Downloaded
    16.16 MB

    Re: Script for random composition of air units

    I used microsoft visual c# 2010 express and found the errors, mostly some syntax stuff (I don't know the lingo). Its a handy proggy to open scripts with, it helps hunt down errors and you should d/l it if you haven't already. Here is an error free version:

    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();
        Bool Mis = false; 
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start();
            MissionNumberListener = -1;
            Bool Mis = true;        //variable so that you don't load more than one mission
        }
       public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
        {
            base.OnActorCreated(missionNumber, shortName, actor);
    
            if (actor is AiAircraft)
            {
                switch ((actor as AiAircraft).InternalTypeName())
                {
    
                    case "bob:Aircraft.He-111P-2":
                    case "bob:Aircraft.BlenheimMkIV":
    
                        Timeout(3000, () =>    // Time in Seconds
                             {
                                 (actor as AiAircraft).Destroy();
                             });
                        break;
                }
            }
        }
    
        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 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;
        }
    
    public override void OnTickGame()
        {
    
            if (MissionTimer.Elapsed.TotalSeconds >= 3600 && GetSumAllPlanes() < 90)  //Loads a mission every 3600s and only if the sum of all planes < 90
            {
                Random ZufaelligeMission = new Random();
        
                //Bool Mis = false go here maybe???
    
                MissionTimer.Restart(); // Sets timer to 0 and start again
    
                switch (ZufaelligeMission.Next(1, 3))
                {
                    case 1:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission1.mis");
                        break;
                    case 2:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission2.mis");
                        break;
                    case 3:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission3.mis");
                        break;
                }
            }
        }
    }
    Not tested in game though, or 'compiled' in the FMB...

    PS not sure if I put the bool mis= false in the right spot

    Last edited by ATAG_Freya; Dec-30-2016 at 21:11.

  20. #19
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    I'd recommend getting yourself c# express or visual studio as it's now called. It really will help with your code. Trying to use just the script editor is a nightmare. However, it is useful once you've got a script which doesn't throw any errors in c# to then run a compile in the FMB to check it works ok in game.

    Freya's example will not work for what you want. I've highlighted in Red the changes that I've made.

    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();
        Bool Mis = true;
    
        public override void OnBattleStarted()
        {
            base.OnBattleStarted();
            MissionTimer.Start();
            MissionNumberListener = -1;
            //Bool Mis = true;       apologies, this is not required in OnBattleStarted, trying to do things on my phone before made me give you a bum steer. 
        }
       public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
        {
            base.OnActorCreated(missionNumber, shortName, actor);
    
            if (actor is AiAircraft)
            {
                switch ((actor as AiAircraft).InternalTypeName())
                {
    
                    case "bob:Aircraft.He-111P-2":
                    case "bob:Aircraft.BlenheimMkIV":
    
                        Timeout(3000, () =>    // Time in Seconds
                             {
                                 (actor as AiAircraft).Destroy();
                             });
                        break;
                }
            }
        }
    
        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 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;
        }
    
    public override void OnTickGame()
        {
    
            if (MissionTimer.Elapsed.TotalSeconds >= 3600 && Mis)  //Checks to see if the time has passed the 3600 seconds, and that the bool Mis is true - ie hasn't been triggered yet        {
                Random ZufaelligeMission = new Random();
        
                Bool Mis = false; //Sets the variable to false, which means that the code segment will not run again
    
                MissionTimer.Restart(); // Sets timer to 0 and start again
    
                switch (ZufaelligeMission.Next(1, 3))
                {
                    case 1:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission1.mis");
                        break;
                    case 2:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission2.mis");
                        break;
                    case 3:
                        GamePlay.gpPostMissionLoad("missions\\Single\\Test\\mission3.mis");
                        break;
                }
            }
        }
    }
    Bear in mind that there's some code in here that is no longer directly related to the exact requirements you've specified, but I've left them in in case they're being used in snippets that you didn't provide. Otherwise it's good practice to comment (that's what the // indicates at the start or mid way through a line btw if you hadn't guessed) out or remove entirely the unnecessary code.

  21. #20
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Guys, you are the best! THANKS!!!

    I will report back when I've run my tests.

  22. #21
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Lightbulb Re: Script for random composition of air units

    Hi fellas - Happy New Year!

    Slightly hung over I've run Reddogs amended version, and have to report: close, but no cigar, yet. We are getting there! Now the console gives just these two error messages:

    System.exception ... Test_random.cs (151.1) CS1022: Type or namespace definition, or end-of-file expected
    at RULv3kje ... (String, Boolean, Boolean)
    at RULv3kje ... (String)
    at RULv3kje ... (String, Int32)

    System.exception ... Test_random.cs (151.1) CS1022: Type or namespace definition, or end-of-file expected
    at RULv3kje ... (String, Int32)
    at ilgAer4x8 ... (SzcBQDRIQP)

    What do you script wizards out there has to say about that?

    All the best
    /P

  23. #22
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    Those errors don't look like errors from the script but internal clod errors to me.

    Do you have any debugging output in your code? If not it's invaluable to use some to identify how your logic is flowing.

    Also, did the script compile in the FMB script editor?

    Lastly are you running this from the fmb or the single mission menu or MP lobby/servery?

  24. Likes Poltava liked this post
  25. #23
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Re: Script for random composition of air units

    Quote Originally Posted by SoW Reddog View Post

    Also, did the script compile in the FMB script editor?

    Lastly are you running this from the fmb or the single mission menu or MP lobby/servery?
    1.) Yes, I guess it did compile. I got no error messages.

    2.) I've tried both, with the same result: the main mission starts allright, but no sub-missions are loaded. Those "System.exception"-errors don't show in the original script (the one first mentioned above, which BTW works), so the problem seems to be with the new code somehow.

    Nah, I guess I'm in over my head here I think I better just stick to already functioning scripts straight off the shelf ...

    But thanks anyway fellas, for the assistance given!
    Last edited by Poltava; Jan-03-2017 at 19:31.

  26. #24
    Ace
    Join Date
    May 2013
    Location
    Stamford, Lincs, UK
    Posts
    1,033
    Post Thanks / Like
    Blog Entries
    8
    Total Downloaded
    7.46 MB

    Re: Script for random composition of air units

    Nah, we can crack this.

    Let me write some stuff for you and check it works. Is the script doing anything else other than loading these sub missions? Plane despawn, scoring or other stuff?

  27. Likes ♣_Spiritus_♣, Poltava liked this post
  28. #25
    Novice Pilot Poltava's Avatar
    Join Date
    Dec 2016
    Posts
    35
    Post Thanks / Like
    Total Downloaded
    233.22 MB

    Red face Re: Script for random composition of air units

    That would be absolutely GREAT, Reddog!!!

    1.) What the script is supposed to do is this: When the main mission starts it should randomly load one out of three sub-missions (submission1.mis, submission2.mis, submission3.mis.). The sub-missions are to be found in a special folder (inside the "Single" folder). That is the main priority.

    2.) Regarding despawning: is it possible to do someting about AI aircraft in the players own unit being destroyed automatically upon landing? And then being reported as "destroyed" in the post-mission briefing. But if I understand this correctly this this a major AI thing that will perhaps be fixed in 5.0. If so, I can live with that.

    3.) Also another thing, is it possible to give the player an automatic score if he manages to land at his original airfield? Perhaps with a message: "Mission accomplished!", or some such.

    With such a script in place, I can go on with my very first Cliffs of Dover campaign!

    With my grateful best wishes
    /P

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •