Log in

View Full Version : OnAircraftCrashLanded trying to subtract flyable planes


hc_wolf
04-23-2012, 05:48 AM
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?



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:

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.