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)
-   -   AI-Aircraft classes for scripts (http://forum.fulqrumpublishing.com/showthread.php?t=24918)

SNAFU 07-27-2011 08:39 AM

AI-Aircraft classes for scripts
 
Quote:

Originally Posted by FG28_Kodiak (Post 275321)
Argh german language:

Das bomber! -> (singular) Der Bomber! (plural) Die Bomber!
Das jager! -> (singular) Der Jäger! (plural) Die Jäger!

Next time i fly a bombing raid over the translator. :grin:

AircraftType could be:
AmphibiousPlane
BNZFighter
Bomber
DiveBomber
Fighter
Glider
HeavyFighter
JaBo
SailPlane
Scout
Sturmovik
TNBFighter
TorpedoBomber
Transport
UNKNOWN

So if you are in a Ju87 or Ju88 there should be Bomber or DiveBomber to Show that you are in a Bomber
Code:

      if ((aircraft.Type() == AircraftType.Bomber) || (aircraft.Type() == AircraftType.DiveBomber))  // if Bomber or Divebomber
              { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Der Bomber!"); } // show Der Bomber!
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Der Jäger!"); } //in all other cases show Der Jäger!















This I found in another thread and embedded it into a script for pilot briefing, this way:












Code:

                                       
        public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);
        AiAircraft aircraft = actor as AiAircraft;
       
        if (aircraft != null)
        switch (aircraft.Army())
                {               
            case 1:
                if (aircraft.Type() == AircraftType.Bomber)                                //Nachricht fuer rote Spieler beim spawnen
                { GamePlay.gpHUDLogCenter(new Player[] {player},"Fly a recon from Manston -AW25 to LeHavre -AN4"); }               
                else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Cover our shipping south of Isle of White - AD17"); }       
                break;
            case 2:
                if (aircraft.Type() == AircraftType.Bomber) //Nachricht fuer blaue Spieler beim spawnen
                { GamePlay.gpHUDLogCenter(new Player[] { player }, "Attack britisch shipping south of Isle of White - AD17"); }               
                else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Escort Ju87 from Theville - AC6 to AE15"); }         
                break;

                }
    }

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

        if (GamePlay.gpPlayer().Place() != aircraft)
            return;
       
        switch (aircraft.Army())
                {
            case 1:
              if (aircraft.Type() == AircraftType.Bomber)                                                        //Nachricht fuer rote Spieler nach Start
                { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Fly a recon from Manston -AW25 to LeHavre -AN4"); }                       
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Cover our shipping south of Isle of White - AD17"); }               
              break;
            case 2:
                if ((aircraft.Type() == AircraftType.Bomber) || (aircraft.Type() == AircraftType.DiveBomber)) //Nachricht fuer blaue Spieler nach Start
              { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Attack britisch shipping south of Isle of White - AD17"); }                     
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Escort Ju87 from Theville - AC6 to AE15"); }               
              break;

                }
    }

Works fine while spawning in 109, 110, He111, red fighters or blenheim, but Stukas and Ju88 seem to be recognised as fighter and receive the fighter message.

Furthermore the message "OnAircraftTookOff" does not show up at all. Has anyone any idea?

FG28_Kodiak 07-27-2011 09:00 AM

Do you include my code into the other?

OnAircraftTookOff works only correct if there is a Waypoint after the start. If you use Spawn-Areas and take off from there it doesn't work, it's not a feature its a bug. It worked correctly on first Version.

SNAFU 07-27-2011 09:06 AM

Jepp, I included this into the submission script:

Code:

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

public class Mission : AMission
{
//-----------------------------------------------------------------------------------------------
//Section 1: Trigger Nachrichten

        public override void OnTrigger(int missionNumber, string shortName, bool active)
        {
                        if ("Trigger1R".Equals(shortName) && active)                                //Trigger 1 Nachricht
                        {
                                GamePlay.gpHUDLogCenter("Blue succeeded and sunk 3 red tanker");
                                GamePlay.gpGetTrigger(shortName).Enable = false;
                        }

                        if ("Trigger2R".Equals(shortName) && active)                                //Trigger 1 Nachricht
                        {
                                GamePlay.gpHUDLogCenter("Red successfully reconnoitered LeHavre");
                                GamePlay.gpGetTrigger(shortName).Enable = false;
                        }

                        if ("Trigger1B".Equals(shortName) && active)                                //Trigger 2 Nachricht
                        {
                                GamePlay.gpHUDLogCenter("Red succeeded and shot down 20% blue bomber");
                                GamePlay.gpGetTrigger(shortName).Enable = false;
        }               

// Trigger Aktionen
base.OnTrigger(missionNumber, shortName, active);

          if ("SpawnIntercept1".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnIntercept1");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
                 
                  if ("SpawnIntercept2".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnIntercept2");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
                 
                  if ("SpawnEscort1".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnEscort1");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
                 
                  if ("SpawnEscort2".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnEscort2");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
                 
                  if ("SpawnStuka1".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnStuka1");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
                 
                  if ("SpawnStuka2".Equals(shortName) && active)
          {
                AiAction action = GamePlay.gpGetAction("SpawnStuka2");
                if (action != null)
                {
                    action.Do();
                }
                GamePlay.gpGetTrigger(shortName).Enable = false;           
          }
    }




//-----------------------------------------------------------------------------------------------
//Section 3: Briefing
                                               
        public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);
        AiAircraft aircraft = actor as AiAircraft;
       
        if (aircraft != null)
        switch (aircraft.Army())
                {               
            case 1:
                if (aircraft.Type() == AircraftType.Bomber)                                //Nachricht fuer rote Spieler beim spawnen
                { GamePlay.gpHUDLogCenter(new Player[] {player},"Fly a recon from Manston -AW25 to LeHavre -AN4"); }               
                else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Cover our shipping south of Isle of White - AD17"); }       
                break;
            case 2:
                if (aircraft.Type() == AircraftType.Bomber) //Nachricht fuer blaue Spieler beim spawnen
                { GamePlay.gpHUDLogCenter(new Player[] { player }, "Attack britisch shipping south of Isle of White - AD17"); }               
                else { GamePlay.gpHUDLogCenter(new Player[] { player }, "Escort Ju87 from Theville - AC6 to AE15"); }         
                break;

                }
    }

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

        if (GamePlay.gpPlayer().Place() != aircraft)
            return;
       
        switch (aircraft.Army())
                {
            case 1:
              if (aircraft.Type() == AircraftType.Bomber)                                                        //Nachricht fuer rote Spieler nach Start
                { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Fly a recon from Manston -AW25 to LeHavre -AN4"); }                       
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Cover our shipping south of Isle of White - AD17"); }               
              break;
            case 2:
                if ((aircraft.Type() == AircraftType.Bomber) || (aircraft.Type() == AircraftType.DiveBomber)) //Nachricht fuer blaue Spieler nach Start
              { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Attack britisch shipping south of Isle of White - AD17"); }                     
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Escort Ju87 from Theville - AC6 to AE15"); }               
              break;

                }
    }
       
//Section 4 : AI entfernen
public override void OnTickGame()
{
  double initTime;   

    if (Time.tickCounter() % 324000 == 323999) // Nach 180 Minuten werden die AI wieder entfernt
  {

foreach (int army in GamePlay.gpArmies())
            {
                foreach (AiAirGroup group in GamePlay.gpAirGroups(army))
                {
                    if (ActorName.MissionNumber(group.Name()).Equals(MissionNumber)) // Zeile L schen wenn auch AAA entfernt werden soll
                    {
                        AiActor[] members = group.GetItems();
                        for (int i = members.Length - 1; i > -1; i--)
                        {
                            (members[i] as AiAircraft).Destroy();
                        }
                    }
                }
                foreach (AiGroundGroup group in GamePlay.gpGroundGroups(army))
                {
                    if (ActorName.MissionNumber(group.Name()).Equals(MissionNumber)) // Zeile L schen wenn auch AAA entfernt werden soll
                    {
                        AiActor[] members = group.GetItems();
                        for (int i = members.Length - 1; i > -1; i--)
                        {
                            (members[i] as AiGroundActor).Destroy();
                        }
                    }
                }
            }
        }
}
                       
                public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)
                                {

        base.OnActorCreated(missionNumber, shortName, actor);

        if (actor is AiGroundActor)
        {
            Timeout(324000, () => {        // nach 180minuten werden AI entfernt
                if (actor != null)
                {
                    (actor as AiGroundActor).Destroy();
                }
            });
        }
    }
    }

Ok, takeoff doesn´t work for multiplayer, I already pictured that. ;)
But the briefing message for blue bomber, does only work for He111 so far, all other work, except Stuka, Ju88...

FG28_Kodiak 07-27-2011 09:15 AM

Code:

if (aircraft.Type() == AircraftType.Bomber)                                                        //Nachricht fuer rote Spieler nach Start
                { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Fly a recon from Manston -AW25 to LeHavre -AN4"); }                       
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Cover our shipping south of Isle of White - AD17"); }               
              break;

If you want stukas and Ju88 as Bombertype-Planes you must use Divebomber
so your code is not correct.

it should look like:
Code:

if ((aircraft.Type() == AircraftType.Bomber) || (aircraft.Type() == AircraftType.DiveBomber))
 { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Fly a recon from Manston -AW25 to LeHavre -AN4"); }                       
                else { GamePlay.gpHUDLogCenter(new Player[] { GamePlay.gpPlayer() }, "Cover our shipping south of Isle of White - AD17"); }


SNAFU 07-27-2011 09:25 AM

I tried that also, doesn´t work.

I used the same lines as for "Takeoff" and to no avail. Just have a testing version of the script here in office, that are the lines you see here, so I cannot give you the actual code, but you can join our III./JG27TestServer, map with the script should be running now (if Steam didnt disconnect). ;)

Also the || connection to Divebomber doesnt work for spawning.

FG28_Kodiak 07-27-2011 09:31 AM

Heh hab auch bloß Kaffeepause und bin auf die dumme Idee gekommen ins 1C Forum zu schauen :rolleyes:

Ich schau mirs heute Abend mal an.

SNAFU 07-27-2011 09:37 AM

:grin:

Ja, imer fleissig fürs BSP schaffen... ich muss auch mal wieder... :rolleyes:

FG28_Kodiak 07-27-2011 10:53 AM

So figured it out, the Devs made Ju87 and Ju88 to "Bomber, DiveBomber". So the earlier version with DiveBomber only, don't work anymore.

New working code (Testversion):
Code:

using System;
using maddox.game;
using maddox.game.world;


public class Mission : AMission
{

    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);
       
        AiAircraft aircraft = actor as AiAircraft;
       
        if (aircraft != null)
            switch (aircraft.Army())
            {               
                case 1:
                    if (aircraft.Type() == AircraftType.Bomber || aircraft.Type().ToString().Equals("Bomber, DiveBomber"))      //rote spieler
                    {
                        GamePlay.gpHUDLogCenter(new Player[] {player}, "roter Bomber");
                    }       
                    else
                    {
                        GamePlay.gpHUDLogCenter(new Player[] {player}, "roter Jäger");
                    }   
                break;
               
                case 2:
                if (aircraft.Type() == AircraftType.Bomber || aircraft.Type().ToString().Equals("Bomber, DiveBomber"))          //blaue Spieler
                    {
                        GamePlay.gpHUDLogCenter(new Player[] {player}, "blauer Bomber");
                    }       
                    else
                    {
                        GamePlay.gpHUDLogCenter(new Player[] {player}, "blauer Jäger");
                    }   
                    break;
            }
    }
}

Man kann seine Mittagspause auch sinnvoller verbringen :rolleyes:

SNAFU 07-27-2011 01:08 PM

Great! Thx.

Now the stukas and ju88 do not have to escort the ju87 anymore and are allowed to sink the shipping. :cool:


All times are GMT. The time now is 10:36 PM.

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