View Single Post
  #16  
Old 04-19-2011, 06:35 PM
ZaltysZ's Avatar
ZaltysZ ZaltysZ is offline
Approved Member
 
Join Date: Sep 2008
Location: Lithuania
Posts: 426
Default

Script for despawning planes without humans inside. Multicrew friendly.

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

public class  Mission : AMission
{
	public void _DespawnEmptyPlane(AiActor actor)
	{
					if (actor == null)
						{ return;}

					Player[] Players = GamePlay.gpRemotePlayers();
					
					bool PlaneIsEmpty = true;
					
					foreach (Player i in Players)
					{	
						if ((i.Place() as AiAircraft) == (actor as AiAircraft))
							{ 
								PlaneIsEmpty = false;
								break;
							}
					}
					
					if (PlaneIsEmpty)
						{ (actor as AiAircraft).Destroy(); }
	}

    public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
    {
        base.OnPlaceLeave(player, actor, placeIndex);
        Timeout(1, () =>
        {
         	_DespawnEmptyPlane(actor);
        });
    }
}
}

Last edited by ZaltysZ; 04-20-2011 at 06:26 PM. Reason: Code change
Reply With Quote