Ил-2 Штурмовик: Битва за Британию. Скрипты. Удаление самолетов — различия между версиями

Материал из АвиаВики
Перейти к: навигация, поиск
(Новая страница: « This code removes landed and crashed AI and player aircraft and destroys abandoned player aircraft. If the player had some AI in his/her group, they are also destro...»)
 
Строка 1: Строка 1:
This code removes landed and crashed AI and player aircraft and destroys abandoned player aircraft. If the player had some AI in his/her group, they are also destroyed. First, we need the following private methods in our mission's script:
+
Автор: '''TheEnlightenedFlorist'''
  
Автор: TheEnlightenedFlorist
+
http://www.airwarfare.com/sow/index.php?option=com_kunena&func=view&catid=43&id=539&Itemid=54
 
   
 
   
 +
Этот скрипт удаляет приземлившиеся и разбитые самолеты под управлением AI и игрока. Если игрок имеет AI в своей группе, они также удаляются. Нам понадобится следующий метод в скрипте:
 +
 
  private bool isAiControlledPlane(AiAircraft aircraft)
 
  private bool isAiControlledPlane(AiAircraft aircraft)
 
     {
 
     {
Строка 54: Строка 56:
 
     }
 
     }
  
Putting the following code in your OnPlaceLeave() method will, when a player abandons an aircraft, disable controls and engines and remove the plane after 300 seconds. Hopefully, it has crashed by then.
+
Поместите следующий код в метод OnPlaceLeave(). Теперь, если игрок покинет самолет, у него отключится управление и двигатели, а через 300 секунд самолет будет удален. Конечно же он разобьется перед этим.
 
+
 
   
 
   
 
         Timeout(1, () =>
 
         Timeout(1, () =>

Версия 10:55, 30 сентября 2011

Автор: TheEnlightenedFlorist

http://www.airwarfare.com/sow/index.php?option=com_kunena&func=view&catid=43&id=539&Itemid=54

Этот скрипт удаляет приземлившиеся и разбитые самолеты под управлением AI и игрока. Если игрок имеет AI в своей группе, они также удаляются. Нам понадобится следующий метод в скрипте:

private bool isAiControlledPlane(AiAircraft aircraft)
   {
       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;
   }

   private void destroyPlane(AiAircraft aircraft)
   {
       if (aircraft != null && isAiControlledPlane(aircraft))
           aircraft.Destroy();
   }

   private void damageAiControlledPlane(AiActor actorMain)
   {
       foreach (AiActor actor in actorMain.Group().GetItems())
       {
           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);
           int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
           for (int i = 0; i < iNumOfEngines; i++)
           {
               aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
           }


           Timeout(300, () =>
           { destroyPlane(aircraft); }
               );
       }
   }

Поместите следующий код в метод OnPlaceLeave(). Теперь, если игрок покинет самолет, у него отключится управление и двигатели, а через 300 секунд самолет будет удален. Конечно же он разобьется перед этим.

       Timeout(1, () =>
       { damageAiControlledPlane(actor); }
           );

After one of the patches, the dev team made it so that crashed and landed planes would disappear without needing to put anything in a script. This makes the next block of code redundant, but you can still use it if you want to decrease the time before aircraft disappear. Put the following code in your OnAircraftLanded() and OnAircraftCrashLanded() methods. The 300 is the number of seconds before the aircraft is removed.

  Timeout(300, () =>
       { destroyPlane(aircraft); }
           );

Here is what it should look like all together. Barring any other code you have in your script, of course. Again, the OnAircraftLanded() and OnAircraftCrashLanded() methods are redundant and not necessary.

using System;

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

public class Mission : AMission {

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

       //listen to events from all missions.
       MissionNumberListener = -1;
   }

   public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
   {
       base.OnPlaceLeave(player, actor, placeIndex);
       Timeout(1, () =>
       { damageAiControlledPlane(actor); }
           );
   }

   public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
   {
       base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
       Timeout(300, () =>
       { destroyPlane(aircraft); }
           );
   }
   public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
   {
       base.OnAircraftLanded(missionNumber, shortName, aircraft);
       Timeout(300, () =>
       { destroyPlane(aircraft); }
           );
   }

   private bool isAiControlledPlane(AiAircraft aircraft)
   {
       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;
   }

   private void destroyPlane(AiAircraft aircraft)
   {
       if (aircraft != null)
           aircraft.Destroy();
   }

   private void damageAiControlledPlane(AiActor actorMain)
   {
       foreach (AiActor actor in actorMain.Group().GetItems())
       {
           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);
           int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
           for (int i = 0; i < iNumOfEngines; i++)
           {
               aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
           }


           Timeout(300, () =>
           { destroyPlane(aircraft); }
               );
       }
   }
}