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)
-   -   Script limiting aircraft types (including multilingual messages) (http://forum.fulqrumpublishing.com/showthread.php?t=26808)

pupo162 05-22-2012 07:57 PM

Hi, still on the same topic, yet a differente type of code, im tryign to get a submenu to have an option to refly.

code

Quote:

public override void OnOrderMissionMenuSelected(Player player, int ID, int menuItemIndex)
{
base.OnOrderMissionMenuSelected(player, ID, menuItemIndex);

if (player != null)
{
if (menuItemIndex == 1)
{
GamePlay.gpHUDLogCenter(new Player[] { player }, "Red - {0} blue - {1}", new object[] { redscore, bluescore });

}
if (menuItemIndex == 2)
{
GamePlay.gpHUDLogCenter(new Player[] { player }, "Ainda nao funciona");
}
if (menuItemIndex == 3)
{
GamePlay.gpHUDLogCenter(new Player[] { player }, "You will refly in 5 seconds!");
Timeout(20, () =>
{ destroyPlane(aircraft); });
}
}
}
The clear problem is, aircraft used in destroy plane, does not exist i nthis function, pnly player. how do i get over this?

sorry, but im really noob in C#

FG28_Kodiak 05-23-2012 07:02 AM

you get the Aircraft via player.Place()

Code:

if (player.Place() != null && player.Place() is AiAircraft)
{
        AiAircraft aircraft = player.Place() as AiAircraft;

       
}


pupo162 05-23-2012 09:53 AM

Thnak you Kodiak, will try that when i get home.

Where do you get all of this info? of what info is stored in wich class? and wich classes can be converted to others?

from trial and error, and from seeing other people i get to learn some of them ( actor can be used as aircraft and such), but where does this knowledge comes from? trial and error?

FG28_Kodiak 05-23-2012 10:04 AM

Object-Explorer in Visual Studio and try and error (sometimes Cliffs don't react as expected :rolleyes:).

_79_dev 05-29-2012 02:58 PM

Can any of You guys update "plane limit" script that`s working 100% on dedi server pleas...

FG28_Kodiak 06-07-2012 10:57 AM

Don't know if this script working 100% at Dedi Server (theoretical it should :rolleyes:), have not the time to test it properly so it's on you ;):
Code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using maddox.GP;
using maddox.game;
using maddox.game.world;
using part;

public class Mission : AMission
{

    /// <summary>
    /// This Dictionary contains the InternalTypeName of the limited actor and the number of available actors
    /// </summary>
    /// <remarks>Actors which are not in List are not limited</remarks>
    internal Dictionary<string, int> AircraftLimitations = new Dictionary<string, int>
    {
        //{"bob:Aircraft.Bf-109E-3",10},                       
        //{"bob:Aircraft.Bf-109E-3B",10},
        //{"bob:Aircraft.Bf-109E-1",10},
        {"bob:Aircraft.Bf-109E-4",5},
        {"bob:Aircraft.Bf-109E-4B",5},
        //{"bob:Aircraft.Bf-110C-4",10},
        //{"bob:Aircraft.Bf-110C-7",10},
        //{"bob:Aircraft.Ju-87B-2",10},
        //{"bob:Aircraft.Ju-88A-1",10},
        //{"bob:Aircraft.He-111H-2",10},
        //{"bob:Aircraft.He-111P-2",10},
        //{"bob:Aircraft.DH82A",10},
        //{"bob:Aircraft.HurricaneMkI",10},
        //{"bob:Aircraft.HurricaneMkI_dH5-20",10},
        //{"bob:Aircraft.BlenheimMkIV",10},
        //{"bob:Aircraft.SpitfireMkI",10},
        {"bob:Aircraft.SpitfireMkIa",5},
        {"bob:Aircraft.SpitfireMkIIa",5},
        //{"bob:Aircraft.SpitfireMkI_Heartbreaker",10},
        //{"bob:Aircraft.G50",10},
        //{"bob:Aircraft.BR-20M",10}
    };


    private bool IsLimitReached(AiActor actor)
    {
        bool limitReached = false;
        AiCart cart = actor as AiCart;

        if (cart != null)
            if (AircraftLimitations.ContainsKey(cart.InternalTypeName()))
                if (AircraftLimitations[cart.InternalTypeName()] < 1)
                    limitReached = true;

        return limitReached;
    }


    private void CheckActorOut(AiActor actor)
    {
        AiCart cart = actor as AiCart;

        if (cart != null)
            if (AircraftLimitations.ContainsKey(cart.InternalTypeName()))
                AircraftLimitations[cart.InternalTypeName()]--;
    }


    private void CheckActorIn(AiActor actor)
    {
        AiCart cart = actor as AiCart;

        if (cart != null)
            if (AircraftLimitations.ContainsKey(cart.InternalTypeName()))
                AircraftLimitations[cart.InternalTypeName()]++;
    }


    private void DebugPrintNumberOfAvailablePlanes()
    {
        foreach (KeyValuePair<string, int> current in AircraftLimitations)
        {
            GamePlay.gpLogServer(new Player[] { GamePlay.gpPlayer()},"InternalTypeName: {0}, Available: {1}", new object[]{current.Key, current.Value.ToString(CultureInfo.InvariantCulture)});
        }
    }


    private int NumberPlayerInActor(AiActor actor)
    {
        int number = 0;

        AiCart cart = actor as AiCart;

        if(cart != null)
            for (int i = 0; i < cart.Places(); i++)
                if (cart.Player(i) != null)
                    number++;

        return number;
    }


    private AiAirport GetNearestAirfield(AiActor actor)
    {
        if (actor == null) return null;
       
        AiAirport nearestAirfield = null;
        AiAirport[] airports = GamePlay.gpAirports();

        Point3d actorPos = actor.Pos();

        if (airports != null)
        {
            foreach (AiAirport airport in airports)
            {
                if (nearestAirfield != null)
                {
                    if (nearestAirfield.Pos().distance(ref actorPos) > airport.Pos().distance(ref actorPos))
                        nearestAirfield = airport;
                }
                else nearestAirfield = airport;
            }
        }
        return nearestAirfield;
    }


    private bool LandedOnAirfield(AiActor actor, AiAirport airport, double maxdistance)
    {
        if (actor == null || airport == null || !IsActorGrounded(actor)) return false;
       
        Point3d ActorPos = actor.Pos();

        if (airport.Pos().distance(ref ActorPos) < maxdistance)
            return true;
        return false;
    }


    private bool IsActorGrounded(AiActor actor)
    {
        bool onGround = false;
        AiAircraft aircraft = actor as AiAircraft;
       
        if (aircraft != null)
            if (aircraft.getParameter(ParameterTypes.Z_AltitudeAGL, -1) <= 2.0
              || aircraft.getParameter(ParameterTypes.Z_VelocityTAS, -1) <= 1.0)
            onGround = true;
     
        return onGround;
    }


    private bool IsActorDamaged(AiActor actor)
    {
        foreach (AiActor ac in Battle.GetDamageVictims())
            if (ac == actor)
                return true;
       
        return false;
    }


    private string ParseTypeName(string typeName)
    {
        string[] tempString = null;
        string parsedName = "";
        tempString = typeName.Split('.');

        parsedName = tempString[1].Replace("_", " ");

        return parsedName;
    }


    public void CheckActorAvailibility(Player player, AiActor actor, int placeIndex)
    {
        if (actor != null)
        {
            if (NumberPlayerInActor(actor) == 1)
            {
                if (!IsLimitReached(actor))
                    CheckActorOut(actor);
                else
                {
                    AiCart cart = actor as AiCart;

                    if (cart != null)
                    {
                        GamePlay.gpHUDLogCenter(new Player[] { player }, "Planetype: {0} no longer available", new object[] { ParseTypeName(cart.InternalTypeName()) });
                   
                        if (AircraftLimitations.ContainsKey(cart.InternalTypeName()))
                            AircraftLimitations[cart.InternalTypeName()] = -1; // after leaving the plane +1 is added via CheckActorIn
                       
                        player.PlaceLeave(placeIndex); // does not work on Dedi correctly
                        Timeout(2, cart.Destroy);      // so destroy the plane
                    }
                }
            }
        }
    }


    private bool OverEnemyTeritory(AiActor actor)
    {
        if (actor == null) return false;
        if (!GamePlay.gpFrontExist()) return false;

        if (GamePlay.gpFrontArmy(actor.Pos().x, actor.Pos().y) != actor.Army())
            return true;
        return false;
    }


    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceEnter(player, actor, placeIndex);

        CheckActorAvailibility(player, actor, placeIndex);

        DebugPrintNumberOfAvailablePlanes(); // for testing
    }
   

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);

        if (actor != null)
        {
            if (NumberPlayerInActor(actor) == 0 && LandedOnAirfield(actor, GetNearestAirfield(actor), 2000.0) && !OverEnemyTeritory(actor) /*&& !IsActorDamaged(actor)*/)
            {
                CheckActorIn(actor);
            }

            if (NumberPlayerInActor(actor) == 0)
                if (actor is AiCart)
                    Timeout(5, ()=>
                        {
                            if (actor as AiCart != null)
                                (actor as AiCart).Destroy();
                        });
        }
    }

}


_79_dev 06-07-2012 11:41 AM

thanx Kodiak will check it today evening...

_79_dev 06-08-2012 08:58 PM

Tested, works fine so far. You cant spawn the plane so it`s not causing spamming on the runway.... Thanx again Kodiak


All times are GMT. The time now is 09:19 PM.

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