Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

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

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 09-09-2011, 03:27 PM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Corrected Script after Ataros hint with bail out:
if the player bailed out OnPlaceLeave is also called and then OnPlaceEnter is called but the Actor is null. So i remove the player from prison if that's the case.

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


public class Mission : AMission
{

    const int TotalArrestTime = 30;  // Time in seconds

    public class prisonCell
    {
        public Player Prisoner { get; set; }
        public DateTime JailTime { get; set; }
        public bool Removable { get; set; }
    }

    public List<prisonCell> PrisonCamp = new List<prisonCell>();


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

        if (actor == null) // if player bailed out the actor is null so remove him from prison
        {
            if (PrisonCamp.Count != 0)
            {
                foreach (prisonCell pri in PrisonCamp)
                {
                    if (pri.Prisoner == player)
                    {
                            pri.Removable = true;
                    }
                }
                PrisonCamp.RemoveAll(item => item.Removable == true);
            }
        }

        if (PrisonCamp.Count != 0)
        {
            foreach (prisonCell pri in PrisonCamp)
            {
                if (pri.Prisoner == player)
                {
                    TimeSpan ArrestTime = DateTime.Now.Subtract(pri.JailTime);

                    if (ArrestTime.TotalSeconds < TotalArrestTime)
                    {
                        GamePlay.gpLogServer(null, "Player: {0} get a {1} sec. penalty for leaving Airplane in flight\n", new object[] { player.Name(), TotalArrestTime });
                        GamePlay.gpHUDLogCenter(new Player[] { player }, "{0} you are under Arrest!", new object[] { player.Name() });
                        (actor as AiAircraft).hitNamed(part.NamedDamageTypes.FuelPumpFailure);
                    
                    }
                    else
                    {
                        pri.Removable = true;
                    }
                    
                }
            }

            PrisonCamp.RemoveAll(item => item.Removable == true);
        }
    }

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

        if ((actor as AiAircraft).IsAirborne())
        {

            prisonCell NewPrisoner = new prisonCell();
            NewPrisoner.Prisoner = player;
            NewPrisoner.JailTime = DateTime.Now;

            PrisonCamp.Add(NewPrisoner);
        }
    }
}

Last edited by FG28_Kodiak; 09-09-2011 at 03:49 PM.
Reply With Quote
 


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 07:25 PM.


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