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)
-   -   OnAircraftCrashLanded trying to subtract flyable planes (http://forum.fulqrumpublishing.com/showthread.php?t=31415)

hc_wolf 04-23-2012 05:48 AM

OnAircraftCrashLanded trying to subtract flyable planes
 
I am having a bit of trouble getting this to subtract from the allowable flying planes on Crash land. It is usually easy when Actor is present. But how do I do it when player is null.

Below if a spitIIa crashlands then it should subtract 1 and the int allowedSpitIIas = 9;

The rest of the code works but it does not subtract from the allowedSpitIIas

Any idea?

Code:


    int allowedSpitIIas = 10;
    int currentSpitIIas = 0;
    int allowed109s = 10;
    int current109s = 0;



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

        Player player = null;
        if (player != null && player is AiAircraft)
        {
           
            switch ((player as AiAircraft).InternalTypeName())
            {

                case "bob:Aircraft.SpitfireMkIIa":
                    currentSpitIIas--;
                    allowedSpitIIas -= 1;
                    break;
                case "bob:Aircraft.Bf-109E-4":
                    currentSpitIIas--;
                    allowed109s -= 1;
                    break;

            }
        }

        if (aircraft.Player(0) != null)
        {
            for (int i = 0; i < aircraft.Places(); i++)
            {
                if (aircraft.Player(i) != null)
                {
                    player = aircraft.Player(i);
                    break;
                }
            }
            if (player != null)
                GamePlay.gpHUDLogCenter(new Player[] { player }, "Looks like you are walking home...", new object[] { });

        }

    }


FG28_Kodiak 04-23-2012 06:02 AM

You dont need a player in this case, you get a AiAircraft via OnAircraftCrashLanded. So you don't need a Player. The most of your player code make no sense ;)
corrected:
Code:

    public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
    {
        base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
     
            switch ((aircraft).InternalTypeName())
            {
                case "bob:Aircraft.SpitfireMkIIa":
                    currentSpitIIas--;
                    allowedSpitIIas -= 1;
                    break;
                case "bob:Aircraft.Bf-109E-4":
                    currentSpitIIas--;  // <---- Attention wrong variable
                    allowed109s -= 1;
                    break;
            }
       

        List<Player> playersInPlane = new List<Player>();

        for (int i = 0; i < aircraft.Places(); i++)
        {
            if (aircraft.Player(i) != null)
            {
                playersInPlane.Add(aircraft.Player(i));
            }
        }
       
        if (playersInPlane.Count > 0)
            GamePlay.gpHUDLogCenter(playersInPlane.ToArray(), "Looks like you are walking home...", new object[] { });

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


hc_wolf 04-23-2012 06:55 AM

Oh. Using PplayersInplane so much neater. thanks kodiak.


All times are GMT. The time now is 04:23 PM.

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