Results 1 to 15 of 15

Thread: Script for remove AI aircraft.

  1. #1
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Script for remove AI aircraft.

    I set a SP mission that require a AI plane landing and when "alerted" by player, done a fly-by at 50m above runway, take-off again.

    The take-off part work OK (in game script).
    But after landing the IA aircraft do a taxi for a far parking point, where I place a camouflage net to hide him, since the new respawn occurs in the next near spawn point, also hide by camouflage net. Crude solution but work.

    The trouble is: the taxing to parking point and from the respawn point to runway end take 5 or 6 minutes... which undermines the mission progress.

    I find this script that supposedly remove AI aircraft after landing.

    Code:
     public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftLanded
    
            double DespawnAfter = 1 * 60;   // seconds after landing
            Timeout(DespawnAfter, (60) =>     // despawn after specified seconds
            {
                try { aircraft.Destroy(); }
                catch { }
            });
        }
    I save this code with mission name, it appears in the FMB script editor... but dont work..

    What I need change in it to remove a specific aircraft, in case a Bf-108B-2?

    Sokol1

  2. #2
    Team Fusion Salmo's Avatar
    Join Date
    Nov 2011
    Posts
    2,332
    Post Thanks / Like
    Total Downloaded
    191.25 MB

    Re: Script for remove AI aircraft.

    Try this as your script file.

    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {
        public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftLanded
    
            double DespawnAfter = 1 * 60;   // seconds after landing
            Timeout(DespawnAfter, () =>     // despawn after specified seconds
            {
                try { aircraft.Destroy(); }
                catch { }
            });
        }
    }

  3. Likes ATAG_Lord Wukits liked this post
  4. #3
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script for remove AI aircraft.

    I try but still don't work, the plane (108) land and did a taxi to parking position where's remains.

    These script (in game trigger) thing are crazy: I made crash landing on the area for spawn trigger, so the new plane spawn an take off, then another - with the same squadron letters spawn and take off...

    Sokol1
    Last edited by 1lokos; Jun-09-2013 at 18:37.

  5. #4
    Team Fusion Salmo's Avatar
    Join Date
    Nov 2011
    Posts
    2,332
    Post Thanks / Like
    Total Downloaded
    191.25 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by 1lokos View Post
    I try but still don't work, the plane (108) land and did a taxi to parking position where's remains.

    These script (in game trigger) thing are crazy: I made crash landing on the area for spawn trigger, so the new plane spawn an take off, then another - with the same squadron letters spawn and take off...

    Sokol1
    The OnAircraftLanded event is not triggered when the aircraft actually lands. It's triggered when the aircraft finishes taxiing & comes to a stop. So in the script above, the aircraft will not despawn until 60 seconds after it finishes taxiing & comes to a stop.

    To remove planes immediately after they finish taxiing to a spawn point .....
    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using maddox.GP;
    
    public class Mission : AMission
    {
        public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftLanded
    
            double DespawnAfter = 1;           // 1 second after landing & taxiing to spawn point
            Timeout(DespawnAfter, () =>     // despawn after specified seconds
            {
                try { aircraft.Destroy(); }
                catch { }
            });
        }
    }
    Alternatively, here's a little more sophisticated script. Here's how it works ...

    1. It records all AI aircraft that takeoff in a list (the AirborneAiPlanes list).
    2. It tests each AI aircraft in the list every 30 seconds to see if the aircraft is on (just above) the ground.
    3. If the Ai aircraft is on the ground AND it's in the list of aircraft that have taken off, then it's assumed to be a landing aircraft. The script will wait 10 seconds then remove the AI aircraft from the battle.
    4. This should result in AI aircraft being despawned very soon after landing, and overcome the problem of the OnAircraftLanded event not being triggered until after the aircraft has taxied all the way to a spawn point.

    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.GP;
    
    
    public class Mission : AMission
    {
        List<AiAircraft> AirborneAiPlanes = new List<AiAircraft>();
    
        public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftTookOff(missionNumber, shortName, aircraft);
    
            if (isAiControlledPlane(aircraft))  // aircraft that tookoff is an AI controlled plane
            {
                if (!AirborneAiPlanes.Contains(aircraft)) // plane is not in list of airborne AI planes
                {
                    AirborneAiPlanes.Add(aircraft);   // add aircraft to list of airborne AI planes
                }
            }
        }
    
        public override void OnTickGame()
        {
            base.OnTickGame();
    
            if (Time.tickCounter() % (32 * 60 * 0.5) == 0)    // every 30 seconds
            {
                if (AirborneAiPlanes.Count > 0)   // there are airborne AI planes in the battle
                {
                    foreach (AiAircraft aircraft in AirborneAiPlanes) // look at each AI aircraft that has taken off
                    {
                        if (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) < 0.01)  // what's the altitude Above Ground Level
                        {
                            if (AirborneAiPlanes.Contains(aircraft)) // the aircraft has previously taken off
                            {
                                Timeout(10.0, () => // wait 10 seconds
                                {
                                    AirborneAiPlanes.Remove(aircraft);    // remove aircraft from the airborne AI aircraft list
                                    aircraft.Destroy(); // remove aircraft from battle
                                });
                            }
                        }
                    }
                }
            }
        }
    
        private bool isAiControlledPlane(AiAircraft aircraft)
        #region Returns whether aircraft is an Ai plane (no humans in any seats)
        {   // returns true if specified aircraft is AI controlled with no humans aboard, otherwise false
            if (aircraft == null) return false;
            //check if a player is in any of the "places"
            for (int i = 0; i < aircraft.Places(); i++)
            {
                if (aircraft.Player(i) != null) return false;
            }
            return true;
        }
        #endregion
    }
    Last edited by Salmo; Jun-09-2013 at 23:17.

  6. #5
    Student Pilot
    Join Date
    Mar 2013
    Posts
    21
    Post Thanks / Like
    Total Downloaded
    2.10 MB

    Re: Script for remove AI aircraft.

    Hi Salmo i just saw this script and at the moment not able to test my qestion, but if the line ....

    if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) < 0.01) // what's the altitude Above Ground Level

    ... were to read....

    if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) <> 0.00) // what's the altitude, Above or Below Ground Level?

    would it have the same effect, the reason why i ask is if an aircraft land on water thats un damaged, when the player leaves their aircraft, the script i have the aircraft remins but not always .
    was just wondering if its a go before i tried

    92 Sqn Sods

  7. #6
    Team Fusion Salmo's Avatar
    Join Date
    Nov 2011
    Posts
    2,332
    Post Thanks / Like
    Total Downloaded
    191.25 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by Sods View Post
    Hi Salmo i just saw this script and at the moment not able to test my qestion, but if the line ....

    if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) < 0.01) // what's the altitude Above Ground Level

    ... were to read....

    if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) <> 0.00) // what's the altitude, Above or Below Ground Level?

    would it have the same effect, the reason why i ask is if an aircraft land on water thats un damaged, when the player leaves their aircraft, the script i have the aircraft remins but not always .
    was just wondering if its a go before i tried

    92 Sqn Sods
    Firsty, you could try if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) == 0.00) // what's the altitude Above Ground Level in the existing script. It really shouldn't make any difference, since this will test if the aircraft altitude above ground level (AGL) is exactly zero.

    However, if i read your question correctly you want to remove a human piloted aircraft if it lands on water & the human pilot bails out? Is this correct? This is a different problem to solve.

  8. #7
    Student Pilot
    Join Date
    Mar 2013
    Posts
    21
    Post Thanks / Like
    Total Downloaded
    2.10 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by Salmo View Post
    However, if i read your question correctly you want to remove a human piloted aircraft if it lands on water & the human pilot bails out? Is this correct? This is a different problem to solve.
    Hi Salmo, yes the above is correct. any help would be greatly appreciated.


    92 Sqn Sods.
    Last edited by Sods; Aug-04-2013 at 12:08.

  9. #8
    Student Pilot
    Join Date
    Mar 2013
    Posts
    21
    Post Thanks / Like
    Total Downloaded
    2.10 MB

    Re: Script for remove AI aircraft.

    I have tried this and seems to work for non AI..

    PHP Code:
        public override void OnPlaceLeave(Player pAiActor actorint placeIndex)
        {
            
    base.OnPlaceLeave(pactorplaceIndex);
            if (
    isSafeDestroyOnPlaceLeave)
            {
                
    AiAircraft aircraft actor as AiAircraft;
                
    DestroyPLAircraft(aircraft);
            }
        } 
    and for AI I have added the line
    PHP Code:
    if (aircraft.getParameter(ParameterTypes.Z_AltitudeAG L, -1) == 0.00 
    and seems ok!

    Thx Salmo you made me think LOL

  10. Likes ATAG_Lord Wukits liked this post
  11. #9
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script for remove AI aircraft.

    LOL - Four years after I look at this again, and this time manage do make things work.

    AI Aircraft despawn 1 second after landing and taxi for parking area. After the "trigger1" spawn a "copy" of this aircraft for takeoff.

    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.GP;
    
    public class Mission : AMission
    {
        public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
        {
            base.OnAircraftLanded(missionNumber, shortName, aircraft);
    
            double DespawnAfter = 1;   // seconds after landing
            Timeout(DespawnAfter, () =>     // despawn after specified seconds
            {
                try { aircraft.Destroy(); }
                catch { }
            });
        }
    	 public override void OnTrigger(int missionNumber, string shortName, bool active) 
        {
           base.OnTrigger(missionNumber, shortName, active); 
    
              if ("trigger1".Equals(shortName) && active) 
              { 
                    AiAction action = GamePlay.gpGetAction("trigger1"); //same as YourTriggerName
                    GamePlay.gpLogServer(null, "Triggered ", new object[] { }); //Testmessage
                    if (action != null)
                   {
                         action.Do();
                   }
                    GamePlay.gpGetTrigger(shortName).Enable = false;            
              }
        }
    }

  12. #10
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script for remove AI aircraft.

    More three years goes by...

    For remove an specific aircraft - an not all that landing, use 'shortName' (FMB > View > Object Name -1 plus a 0 at right).

    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.GP;
    
    public class Mission : AMission
    { 
             public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
      {	  
            base.OnAircraftLanded(missionNumber, shortName, aircraft);	  
    		
    	    if (shortName.Equals("BoB_LW_Wekusta_51.010"))	 //despawn just this specif AI plane
    	 {
    		double DespawnAfter = 1;   // seconds after landing
            Timeout(DespawnAfter, () =>     // despawn after specified seconds
           {
                try { aircraft.Destroy(); }
                catch { }
           });
         }	
       }
     }

  13. #11
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by 1lokos View Post
    More three years goes by...

    For remove an specific aircraft - an not all that landing, use 'shortName' (FMB > View > Object Name -1 plus a 0 at right).

    Code:
    using System;
    using maddox.game;
    using maddox.game.world;
    using System.Collections;
    using System.Collections.Generic;
    using maddox.GP;
    
    public class Mission : AMission
    { 
             public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
      {	  
            base.OnAircraftLanded(missionNumber, shortName, aircraft);	  
    		
    	    if (shortName.Equals("BoB_LW_Wekusta_51.010"))	 //despawn just this specif AI plane
    	 {
    		double DespawnAfter = 1;   // seconds after landing
            Timeout(DespawnAfter, () =>     // despawn after specified seconds
           {
                try { aircraft.Destroy(); }
                catch { }
           });
         }	
       }
     }

    Remember you can set DespawnAfterLandingTimeout in the mission file to -1 so nothing despawns.

    Don't call the base class method, it does nothing. base.OnAircraftLanded(missionNumber, shortName, aircraft);

    Try shortName.Contains("Wekusta") or shortName.Contains("BoB_LW").

  14. Likes fenbeiduo liked this post
  15. #12
    Ace 1lokos's Avatar
    Join Date
    Jan 2012
    Posts
    5,323
    Post Thanks / Like
    Total Downloaded
    1.04 GB

    Re: Script for remove AI aircraft.

    I don't understand, because I set a mission with 2 Bf 108 with the above script and just one (the .010) are removed 1 second after the landing, the other is keep for the normal time, seems 5 minutes.

    If I use this "shortName.Contains("Wekusta") or shortName.Contains("BoB_LW")" both will be removed, no?

    BTW - With the above Salmo script, compiler report error in "ParameterTypes", say that don't exist in actual context.

    Perhaps because their code is too old?
    Last edited by 1lokos; Sep-23-2020 at 17:04.

  16. #13
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by 1lokos View Post
    I don't understand, because I set a mission with 2 Bf 108 with the above script and just one (the .010) are removed 1 second after the landing, the other is keep for the normal time, seems 5 minutes.

    If I use this "shortName.Contains("Wekusta") or shortName.Contains("BoB_LW")" both will be removed, no?
    Just pointing out that in simple missions you don't need the full name if the aircraft to grab a reference.

  17. #14
    varrattu
    Guest

    Re: Script for remove AI aircraft.

    Just a few aditional remarks to "Z_AltitudeAGL" ...

    I guess that

    (aircraft as AiAircraft).getParameter(part.ParameterTypes.Z_Alt itudeAGL, -1)

    is equal to the height of the aircrafts Aerodynamic Center:




    Maybe it's the position through which all the net lift increments act for a change in angle of attack:




    The enclosed script gives you an idea, which values the Z_AltitudeAGL should return.

    ~V~

    Code:
    using maddox.game;
    using maddox.game.world;
    
    public class Mission : AMission
    {
      public override void OnTickGame()
      {
        base.OnTickGame();
    
        AiAircraft aircraft = GamePlay.gpPlayer().Place() as AiAircraft;
        if (aircraft == null) return;
        
        double agl = aircraft.getParameter(part.ParameterTypes.Z_AltitudeAGL, -1);
        double msl = aircraft.getParameter(part.ParameterTypes.Z_AltitudeMSL, -1);
    
        GamePlay.gpHUDLogCenter(msl.ToString("0.00m") + " | " + agl.ToString("0.00m"));
      }
    }
    Attached Images Attached Images
    Last edited by varrattu; Sep-25-2020 at 04:35.

  18. #15
    Manual Creation Group fenbeiduo's Avatar
    Join Date
    May 2013
    Posts
    70
    Post Thanks / Like
    Total Downloaded
    282.61 MB

    Re: Script for remove AI aircraft.

    Quote Originally Posted by ATAG_Oskar View Post
    Remember you can set DespawnAfterLandingTimeout in the mission file to -1 so nothing despawns.

    ...
    Thank you @Oskar

    To make it work, builder should not to write additional despawn script.

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
  •