PDA

View Full Version : Multiple scripts



♣_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.

9./JG52 Hans Gruber
Apr-23-2014, 12:26
See post #13.

http://theairtacticalassaultgroup.com/forum/showthread.php?t=8027

When I get home this evening I can PM you some stuff.

♣_Spiritus_♣
Apr-23-2014, 13:50
Thanks Gruber, I'll look for those PMs once I get back as well.

bolox
Apr-23-2014, 15:51
you just have to add an 'on trigger' section with the specific triggers and actions included.
. Using the example for triggers I gave you earlier this would give something like


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); }
);
}
}


///add this bit here for triggers-2 sep triggers shown use as many as you like- repeat. Use the previous spawntrigger you used
public override void OnTrigger(int missionNumber, string shortName, bool active)
{
base.OnTrigger(missionNumber, shortName, active);

if ("56".Equals(shortName) && active)
{
AiAction action = GamePlay.gpGetAction("56");
if (action != null)
{
action.Do();
}
//GamePlay.gpHUDLogCenter("56"); // rem slashes if want message on spawn
GamePlay.gpGetTrigger(shortName).Enable = false; //optional dep on circumstancea
}

if ("264".Equals(shortName) && active)
{
AiAction action = GamePlay.gpGetAction("264");
if (action != null)
{
action.Do();
}
GamePlay.gpHUDLogCenter("264");
GamePlay.gpGetTrigger(shortName).Enable = false;
}
}

// end of added section


}

No.401_Wolverine
Apr-23-2014, 16:55
Ahhh that's right. Yes, I led you a little astray last night. You CAN use the 'action' tab stuff from the OnTrigger section, you have to do it as bolox has indicated. Forgot about that since I've not used that method in a long time.

♣_Spiritus_♣
Apr-23-2014, 17:59
No worries Wolverine.

So should I use that code in my script except delete the line:

///add this bit here for triggers-2 sep triggers shown use as many as you like- repeat. Use the previous spawntrigger you used
public override void OnTrigger(int missionNumber, string shortName, bool active)



...what about the brackets?

bolox
Apr-24-2014, 01:27
Any line starting with '//' is a 'remark' and is ignored by the script- it's there to remind you/anyone else what is being done, or to test removing a line from a script

Brackets- You must keep the correct bracket pairing or the script won't work.
What are you writing scripts in? vis studio or notepad++ ? both have ways of showing the bracket pairings.
I found messing up pairings one of the things I'd screw up on.