♣_Spiritus_♣
Apr-23-2014, 11:55
I am about to give up.
I am close to finishing my mission and have began scripting. Here is the issue I cant seem to resolve:
I created triggers in the FMB to trigger the spawning of AI trains that worked fine.
I then added a script to despawn AI aircraft so in MP the planes properly disappear after the player leaves the aircraft. So my FMB script page looks like this:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
public class Mission : AMission
{
public override void OnBattleStarted()
{
base.OnBattleStarted();
//listen to events from all missions.
MissionNumberListener = -1;
}
public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceLeave(player, actor, placeIndex);
Timeout(1, () =>
{ damageAiControlledPlane(actor); }
);
}
public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
private bool isAiControlledPlane(AiAircraft aircraft)
{
if (aircraft == null)
return false;
//check if a player is in any of the "places"
for (int i = 0; i < aircraft.Places(); i++)
if (aircraft.Player(i) != null)
return false;
return true;
}
private void destroyPlane(AiAircraft aircraft)
{
if (aircraft != null)
aircraft.Destroy();
}
private void damageAiControlledPlane(AiActor actorMain)
{
foreach (AiActor actor in actorMain.Group().GetItems())
{
if (actor == null || !(actor is AiAircraft))
return;
AiAircraft aircraft = (actor as AiAircraft);
if (!isAiControlledPlane(aircraft))
return;
if (aircraft == null)
return;
aircraft.hitNamed(part.NamedDamageTypes.ControlsEl evatorDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsRu dderDisabled);
aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFa ilure);
int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
for (int i = 0; i < iNumOfEngines; i++)
{
aircraft.hitNamed((part.NamedDamageTypes)Enum.Pars e(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
}
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
}
}
I start the mission in my lobby, spawn in, exit, spawn in again. The planes despawn perfectly. Yay! But now none of my triggers for the train works. I imagine I have to add a script for AI spawn or something but cant seem to find anything on how to add that to the existing script.
Help before I just give up.
I am close to finishing my mission and have began scripting. Here is the issue I cant seem to resolve:
I created triggers in the FMB to trigger the spawning of AI trains that worked fine.
I then added a script to despawn AI aircraft so in MP the planes properly disappear after the player leaves the aircraft. So my FMB script page looks like this:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
public class Mission : AMission
{
public override void OnBattleStarted()
{
base.OnBattleStarted();
//listen to events from all missions.
MissionNumberListener = -1;
}
public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceLeave(player, actor, placeIndex);
Timeout(1, () =>
{ damageAiControlledPlane(actor); }
);
}
public override void OnAircraftCrashLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftCrashLanded(missionNumber, shortName, aircraft);
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
private bool isAiControlledPlane(AiAircraft aircraft)
{
if (aircraft == null)
return false;
//check if a player is in any of the "places"
for (int i = 0; i < aircraft.Places(); i++)
if (aircraft.Player(i) != null)
return false;
return true;
}
private void destroyPlane(AiAircraft aircraft)
{
if (aircraft != null)
aircraft.Destroy();
}
private void damageAiControlledPlane(AiActor actorMain)
{
foreach (AiActor actor in actorMain.Group().GetItems())
{
if (actor == null || !(actor is AiAircraft))
return;
AiAircraft aircraft = (actor as AiAircraft);
if (!isAiControlledPlane(aircraft))
return;
if (aircraft == null)
return;
aircraft.hitNamed(part.NamedDamageTypes.ControlsEl evatorDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsAi leronsDisabled);
aircraft.hitNamed(part.NamedDamageTypes.ControlsRu dderDisabled);
aircraft.hitNamed(part.NamedDamageTypes.FuelPumpFa ilure);
int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();
for (int i = 0; i < iNumOfEngines; i++)
{
aircraft.hitNamed((part.NamedDamageTypes)Enum.Pars e(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));
}
Timeout(300, () =>
{ destroyPlane(aircraft); }
);
}
}
}
I start the mission in my lobby, spawn in, exit, spawn in again. The planes despawn perfectly. Yay! But now none of my triggers for the train works. I imagine I have to add a script for AI spawn or something but cant seem to find anything on how to add that to the existing script.
Help before I just give up.