1C Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official 1C Company forum > 1C Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #21  
Old 05-22-2012, 07:57 PM
pupo162 pupo162 is offline
Senior Member
 
Join Date: Feb 2010
Posts: 1,183
Default

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#
Reply With Quote
  #22  
Old 05-23-2012, 07:02 AM
FG28_Kodiak FG28_Kodiak is offline
Senior Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

you get the Aircraft via player.Place()

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

        
}
Reply With Quote
  #23  
Old 05-23-2012, 09:53 AM
pupo162 pupo162 is offline
Senior Member
 
Join Date: Feb 2010
Posts: 1,183
Default

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?
Reply With Quote
  #24  
Old 05-23-2012, 10:04 AM
FG28_Kodiak FG28_Kodiak is offline
Senior Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Object-Explorer in Visual Studio and try and error (sometimes Cliffs don't react as expected ).
Reply With Quote
  #25  
Old 05-29-2012, 02:58 PM
_79_dev _79_dev is offline
Approved Member
 
Join Date: Sep 2010
Location: Dublin
Posts: 242
Default

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

Asus P6T V2 Deluxe, I7 930, 3x2 GB RAM XMS3 Corsair1333 Mhz, Nvidia Leadtek GTX 470, Acer 1260p screen projector, Track IR 4 OS ver5, Saitek Pro Flight Rudder, Saitek X52, Win 7 x64 ultimate
Reply With Quote
  #26  
Old 06-07-2012, 10:57 AM
FG28_Kodiak FG28_Kodiak is offline
Senior Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Don't know if this script working 100% at Dedi Server (theoretical it should ), 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();
                        });
        }
    }

}

Last edited by FG28_Kodiak; 06-07-2012 at 11:11 AM.
Reply With Quote
  #27  
Old 06-07-2012, 11:41 AM
_79_dev _79_dev is offline
Approved Member
 
Join Date: Sep 2010
Location: Dublin
Posts: 242
Default

thanx Kodiak will check it today evening...
__________________

Asus P6T V2 Deluxe, I7 930, 3x2 GB RAM XMS3 Corsair1333 Mhz, Nvidia Leadtek GTX 470, Acer 1260p screen projector, Track IR 4 OS ver5, Saitek Pro Flight Rudder, Saitek X52, Win 7 x64 ultimate
Reply With Quote
  #28  
Old 06-08-2012, 08:58 PM
_79_dev _79_dev is offline
Approved Member
 
Join Date: Sep 2010
Location: Dublin
Posts: 242
Default

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

Asus P6T V2 Deluxe, I7 930, 3x2 GB RAM XMS3 Corsair1333 Mhz, Nvidia Leadtek GTX 470, Acer 1260p screen projector, Track IR 4 OS ver5, Saitek Pro Flight Rudder, Saitek X52, Win 7 x64 ultimate
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Based on a design by: Miner Skinz.com

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2007 1C Company. All rights reserved.