Jump to content

scrips


sandokito
 Share

Recommended Posts

Hola chicos, despues de mucho leer y probar (mas de un mes con esto a vueltas)

 

Cuando usamos scrips para que los aviones desaparezcan, nos encontramos con un problema.

Resulta que si poníamos aviones creados por triggers estos no iniciaban el vuelo.

 

supongamos que utilizamos un scrip como el que sigue para hacer que cuando dejas un avión este se quite del mapa.

 

// v.1.6.17 trig NEW

 

using System;

using System.Collections;

using System.Collections.Generic;

using maddox.game;

using maddox.game.world;

 

 

 

public class Mission : AMission

{

 

 

// destroys aircraft abandoned by a player

private bool isAiControlledPlane (AiAircraft aircraft)

{

if (aircraft == null)

{

return false;

}

 

Player [] players = GamePlay.gpRemotePlayers ();

foreach (Player p in players)

{

if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)

{

return false;

}

}

 

return true;

}

 

private void destroyPlane (AiAircraft aircraft) {

if (aircraft != null) {

aircraft.Destroy ();

}

}

 

private void explodeFuelTank (AiAircraft aircraft)

{

if (aircraft != null)

{

aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);

}

}

 

private void destroyAiControlledPlane (AiAircraft aircraft) {

if (isAiControlledPlane (aircraft)) {

destroyPlane (aircraft);

}

}

 

private void damageAiControlledPlane (AiActor actor) {

if (actor == null || !(actor is AiAircraft)) {

return;

}

 

AiAircraft aircraft = (actor as AiAircraft);

 

if (!isAiControlledPlane (aircraft)) {

return;

}

 

if (aircraft == null) {

return;

}

 

aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);

aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

aircraft.hitNamed (part.NamedDamageTypes.Eng0TotalFailure);

aircraft.hitNamed (part.NamedDamageTypes.Eng1TotalFailure);

 

/***Timeout (240, () =>

{explodeFuelTank (aircraft);}

);

* ***/

 

Timeout (300, () =>

{destroyPlane (aircraft);}

);

}

 

//////////////////////////////////////////////////////////////////////////////////////////////////

 

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

);

}

 

 

// loads my sub-missions

/***

public override void OnTickGame()

{

 

if (Time.tickCounter() % 216000 == 215999) // 2 часа 72000 == 18000 40-10

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/Islands/Islands1_upd.mis");

GamePlay.gpHUDLogCenter("Mission Objectives Updated!");

}

 

 

if (Time.tickCounter() % 72000 == 71999) // 40-40

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/128BoF/128BoFv1_6Bombers1.mis");

GamePlay.gpHUDLogCenter("Intel: Enemy bombers are heading to blue airfields!");

}

 

if (Time.tickCounter() % 72000 == 45000) // 40-25

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/128BoF/128BoFv1_6Bombers2.mis");

GamePlay.gpHUDLogCenter("Intel: Enemy bombers are heading to red airfields in France!");

}

 

 

}

****/

}

 

Pues bien, los aviones se destruyen pero no salen los vuelos que nos interesan.

 

Solucion

 

Simplemente tenemos que añadir lo siguiente

public override void OnTrigger(int missionNumber, string shortName, bool active)

{

base.OnTrigger(missionNumber, shortName, active);

 

AiAction Action = GamePlay.gpGetAction(shortName);

 

if (Action != null)

Action.Do();

 

GamePlay.gpGetTrigger(shortName).Enable = false;

}

 

Quedando el scrip de esta forma

 

// v.1.6.17 trig NEW

 

using System;

using System.Collections;

using System.Collections.Generic;

using maddox.game;

using maddox.game.world;

 

 

 

public class Mission : AMission

{

 

public override void OnTrigger(int missionNumber, string shortName, bool active)

{

base.OnTrigger(missionNumber, shortName, active);

 

AiAction Action = GamePlay.gpGetAction(shortName);

 

if (Action != null)

Action.Do();

 

GamePlay.gpGetTrigger(shortName).Enable = false;

}

 

// destroys aircraft abandoned by a player

private bool isAiControlledPlane (AiAircraft aircraft)

{

if (aircraft == null)

{

return false;

}

 

Player [] players = GamePlay.gpRemotePlayers ();

foreach (Player p in players)

{

if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)

{

return false;

}

}

 

return true;

}

 

private void destroyPlane (AiAircraft aircraft) {

if (aircraft != null) {

aircraft.Destroy ();

}

}

 

private void explodeFuelTank (AiAircraft aircraft)

{

if (aircraft != null)

{

aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);

}

}

 

private void destroyAiControlledPlane (AiAircraft aircraft) {

if (isAiControlledPlane (aircraft)) {

destroyPlane (aircraft);

}

}

 

private void damageAiControlledPlane (AiActor actor) {

if (actor == null || !(actor is AiAircraft)) {

return;

}

 

AiAircraft aircraft = (actor as AiAircraft);

 

if (!isAiControlledPlane (aircraft)) {

return;

}

 

if (aircraft == null) {

return;

}

 

aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);

aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

aircraft.hitNamed (part.NamedDamageTypes.Eng0TotalFailure);

aircraft.hitNamed (part.NamedDamageTypes.Eng1TotalFailure);

 

/***Timeout (240, () =>

{explodeFuelTank (aircraft);}

);

* ***/

 

Timeout (300, () =>

{destroyPlane (aircraft);}

);

}

 

//////////////////////////////////////////////////////////////////////////////////////////////////

 

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

);

}

 

 

// loads my sub-missions

/***

public override void OnTickGame()

{

 

if (Time.tickCounter() % 216000 == 215999) // 2 часа 72000 == 18000 40-10

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/Islands/Islands1_upd.mis");

GamePlay.gpHUDLogCenter("Mission Objectives Updated!");

}

 

 

if (Time.tickCounter() % 72000 == 71999) // 40-40

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/128BoF/128BoFv1_6Bombers1.mis");

GamePlay.gpHUDLogCenter("Intel: Enemy bombers are heading to blue airfields!");

}

 

if (Time.tickCounter() % 72000 == 45000) // 40-25

{

GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/128BoF/128BoFv1_6Bombers2.mis");

GamePlay.gpHUDLogCenter("Intel: Enemy bombers are heading to red airfields in France!");

}

 

 

}

****/

}

 

Ahora los aviones que dejemos desaparecen y los vuelos IA creados por tiggers aparecerán.

 

Vencejo, esto lo he probado con el programa clodcomander que me pasaste y es totalmente compatible con el ya se pueden preparar todo tipo de misiones con triggers y sin triggers.

 

Ahora paso a poner, como tienen que ser los scripps para poder usar las misiones que diseñemos (siempre que no usemos submisiones (que eso es otro cantar).

 

Si no tenemos vuelos IA creados por triggers

 

//$reference IL2ClodCommanderStats.dll

// v.1_0. script by FG28_Kodiak, ZaltysZ, Oreva, Small_Bee, RAF238thWildWillie

using System;

using System.Diagnostics;

using System.Collections;

using maddox.GP;

using maddox.game;

using maddox.game.world;

using part;

using System.Collections.Generic;

using IL2ClodCommanderStats;

 

 

public class Mission : AMission

{

#region Stats Initialization

// For Connection to the IL2 Clod Commander Application

// This allows you to store stats on players within Cliffs of Dover

// Change the following to meet your needs

//

private static string serverName = "Cliffs of Dover";

private static string serverIP = "127.0.0.1";

 

// Password is not used currently

private static string serverPassword = "password";

private static Int32 serverPort = 20005;

private StatsRecording stats = new StatsRecording(serverName, serverIP, serverPassword, serverPort);

private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();

private List<ServerCommand> newCmds = new List<ServerCommand>();

private Stopwatch MissionTimer = new Stopwatch();

#endregion

 

int LastMissionLoaded = 0;

 

double initTime;

 

 

// loading sub-missions

public override void OnTickGame()

{

#region Stats Timer

if (MissionTimer.Elapsed.TotalSeconds >= 5) // 5 seconds

{

MissionTimer.Restart(); // stopwatch reset to 0 and restart

if (stats != null )

{

newCmds = stats.getCommands();

if (newCmds != null && newCmds.Count > 0)

ProcessCommands(newCmds);

}

}

#endregion

///////////////////////

 

//Add any other mission time stuff here:

 

if (Time.tickCounter() % 216000 == 108000) // 216000=120 min repeat. 108000=60 min delay.

{

// GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small01.mis");

}

 

if (Time.tickCounter() % 216000 == 215999) // 216000=120 min repeat. 215999=120 min delay.

{

// GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small02.mis");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////

 

// Base Scripts for Missions

private bool isAiControlledPlane (AiAircraft aircraft)

{

if (aircraft == null)

{

return false;

}

 

Player [] players = GamePlay.gpRemotePlayers ();

foreach (Player p in players)

{

if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)

{

return false;

}

}

 

return true;

}

 

private void destroyPlane (AiAircraft aircraft) {

if (aircraft != null) {

aircraft.Destroy ();

}

}

 

private void explodeFuelTank (AiAircraft aircraft)

{

if (aircraft != null)

{

aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);

}

}

 

private void destroyAiControlledPlane (AiAircraft aircraft) {

if (isAiControlledPlane (aircraft)) {

destroyPlane (aircraft);

}

}

 

private void damageAiControlledPlane (AiActor actor) {

if (actor == null || !(actor is AiAircraft)) {

return;

}

 

AiAircraft aircraft = (actor as AiAircraft);

 

if (!isAiControlledPlane (aircraft)) {

return;

}

 

if (aircraft == null) {

return;

}

 

aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);

aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

 

int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();

for (int i = 0; i < iNumOfEngines; i++)

{

aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));

}

 

/***Timeout (240, () =>

{explodeFuelTank (aircraft);}

);

* ***/

 

Timeout (300, () =>

{destroyPlane (aircraft);}

);

}

 

public override void Init(maddox.game.ABattle battle, int missionNumber)

{

base.Init(battle, missionNumber);

MissionNumberListener = -1; //Listen to events of every mission

}

 

//////////////////////////////////////////

// Methods for Stats (You can add any code you may need after the Stats Region

//////////////////////////////////////////

 

public override void OnBattleStarted()

{

base.OnBattleStarted();

#region Stats

MissionTimer.Start(); // start the stopwatch

#endregion

}

 

private void sendScreenMessageTo(int army, string msg, object[] parms)

{

List<Player> Players = new List<Player>();

 

// on Dedi the server or for singleplayertesting

if (GamePlay.gpPlayer() != null)

{

if (GamePlay.gpPlayer().Army() == army || army == -1)

Players.Add(GamePlay.gpPlayer());

}

if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)

{

foreach (Player p in GamePlay.gpRemotePlayers())

{

if (p.Army() == army || army == -1)

Players.Add(p);

}

}

if (Players != null && Players.Count > 0)

GamePlay.gpHUDLogCenter(Players.ToArray(), msg, parms);

}

 

private void ProcessCommands(List<ServerCommand> newCmds)

{

try

{

foreach (ServerCommand sc in newCmds)

{

if (sc.CommandType.Equals("HUDmsg"))

{

if (sc.ToWho.Equals("All"))

GamePlay.gpHUDLogCenter(sc.Command);

else if (sc.ToWho.Equals("Red"))

{

sendScreenMessageTo(1, sc.Command, null);

}

else if (sc.ToWho.Equals("Blue"))

{

sendScreenMessageTo(2, sc.Command, null);

}

else

{

if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)

{

 

foreach (Player p in GamePlay.gpRemotePlayers())

{

if (p.Name() == sc.ToWho)

GamePlay.gpLogServer(new Player[] { p }, sc.Command, null);

}

}

// Message is for a specific player based on player name in string sc.ToWho

}

}

}

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.ProcessCommands - Exception: " + ex);

}

}

 

public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)

{

#region stats

base.OnActorCreated(missionNumber, shortName, actor);

// Add actor to list of all Actors

if (!allActors.ContainsKey(shortName))

allActors.Add(shortName, actor);

try

{

stats.newActor(shortName, actor);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorCreated - Exception: " + ex);

}

#endregion

}

 

 

public override void OnPersonHealth(maddox.game.world.AiPerson person, maddox.game.world.AiDamageInitiator initiator, float deltaHealth)

{

#region stats

base.OnPersonHealth(person, initiator, deltaHealth);

try

{

stats.playerHealth(person, initiator, deltaHealth);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonHealth - Exception: " + ex);

}

#endregion

 

}

 

public override void OnPersonParachuteFailed(maddox.game.world.AiPerson person)

{

#region stats

base.OnPersonParachuteFailed(person);

try

{

stats.personParachute("Failed", person);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonParachuteFailed - Exception: " + ex);

}

#endregion

}

 

public override void OnPersonParachuteLanded(maddox.game.world.AiPerson person)

{

#region stats

base.OnPersonParachuteLanded(person);

try

{

stats.personParachute("Landed", person);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonParachuteLanded - Exception: " + ex);

}

#endregion

}

 

public override void OnPlayerArmy(maddox.game.Player player, int army)

{

#region stats

base.OnPlayerArmy(player, army);

try

{

stats.playerArmy(player, army);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerArmy - Exception: " + ex);

}

#endregion

 

}

 

public override void OnPlayerConnected(maddox.game.Player player)

{

#region stats

base.OnPlayerConnected(player);

try

{

stats.pilotInfo(player);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerConnected - Exception: " + ex);

}

 

#endregion

// Your code here

}

public override void OnPlayerDisconnected(maddox.game.Player player, string diagnostic)

{

#region stats

base.OnPlayerDisconnected(player, diagnostic);

try

{

stats.playerDisconnect(player, diagnostic);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerDisconnected - Exception: " + ex);

}

 

#endregion

// Your code here

}

 

public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)

{

#region stats

base.OnPlaceEnter(player, actor, placeIndex);

try

{

Point2d actorPos = new Point2d(actor.Pos().x, actor.Pos().y);

String startingGrid = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.sortieBegin(player, actor, placeIndex, actorPos, startingGrid);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlaceEnter - Exception: " + ex);

}

#endregion

//add your code here

}

 

 

public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)

{

#region stats

base.OnPlaceLeave(player, actor, placeIndex);

try

{

stats.sortieEnd(player, actor, placeIndex);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlaceLeave - Exception: " + ex);

}

 

#endregion

//add your code here

Timeout(1, () =>

{ damageAiControlledPlane(actor); }

);

}

 

public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);

try

{

Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);

String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.aircraftLanded("CrashLanded", shortName, aircraft, actorPos, gridRef);

System.Console.WriteLine("Stats.OnAircraftCrashLanded - ("+shortName+")");

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftCrashLanded - Exception: " + ex);

}

#endregion

//add your code here

Timeout (300, () =>

{ destroyPlane(aircraft); }

);

}

 

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftTookOff(missionNumber, shortName, aircraft);

try

{

stats.aircraftTakeoff(shortName, aircraft);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);

}

#endregion

//add your code here

}

 

public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftLanded(missionNumber, shortName, aircraft);

try

{

Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);

String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.aircraftLanded("Landed", shortName, aircraft, actorPos, gridRef);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);

}

#endregion

//add your code here

 

Timeout(300, () =>

{ destroyPlane(aircraft); }

);

}

 

public override void OnActorDamaged(int missionNumber, string shortName, AiActor actor, AiDamageInitiator initiator, NamedDamageTypes damageType)

{

#region stats

base.OnActorDamaged(missionNumber, shortName, actor, initiator, damageType);

try

{

stats.missionActorDamaged(shortName, actor, initiator, damageType);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDamaged - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)

{

#region stats

base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);

try

{

stats.missionAircraftDamaged(shortName, aircraft, initiator, damageType);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftDamaged - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnAircraftCutLimb(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, LimbNames limbName)

{

#region stats

base.OnAircraftCutLimb(missionNumber, shortName, aircraft, initiator, limbName);

try

{

stats.missionAircraftCutLimb(shortName, aircraft, initiator, limbName);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftCutLimb - Exception: " + ex);

}

#endregion

//add your code here

}

 

public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)

{

#region stats

base.OnActorDead(missionNumber, shortName, actor, damages);

try

{

stats.missionActorDead(shortName, actor, damages);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDead - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)

{

#region stats

base.OnActorDestroyed(missionNumber, shortName, actor);

try

{

stats.actorDestroyed(shortName, actor);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDestroyed - Exception: " + ex);

}

#endregion

//add your code here

 

}

public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftKilled(missionNumber, shortName, aircraft);

try

{

stats.aircraftKilled(shortName, aircraft);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftKilled - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnBattleStoped()

{

#region stats

base.OnBattleStoped();

try

{

stats.battleStopped();

// Loop through list of AiActors and destroy them all

List<string> keys = new List<string>(allActors.Keys);

for (int i = 0; i < keys.Count; i++)

{

AiActor a = allActors[keys];

AiAircraft aircraft = a as AiAircraft;

if (aircraft != null)

{

aircraft.Destroy();

}

else

{

AiGroundActor aiGroundActor = a as AiGroundActor;

if (aiGroundActor != null)

{

aiGroundActor.Destroy();

}

else

{

System.Console.WriteLine("Stats.OnBattleStoped - Unknown Actor (" + a.Name()+") ShortName ("+keys+")");

}

}

}

// stats.disconnectStats();

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnBattleStoped - Exception: " + ex);

}

#endregion

//add your code here

}

//////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

}

 

En casod e que tengamos Ia creados con triggers

//$reference IL2ClodCommanderStats.dll

// v.1_0. script by FG28_Kodiak, ZaltysZ, Oreva, Small_Bee, RAF238thWildWillie

using System;

using System.Diagnostics;

using System.Collections;

using maddox.GP;

using maddox.game;

using maddox.game.world;

using part;

using System.Collections.Generic;

using IL2ClodCommanderStats;

 

 

public class Mission : AMission

{

#region Stats Initialization

// For Connection to the IL2 Clod Commander Application

// This allows you to store stats on players within Cliffs of Dover

// Change the following to meet your needs

//

private static string serverName = "Cliffs of Dover";

private static string serverIP = "127.0.0.1";

 

// Password is not used currently

private static string serverPassword = "password";

private static Int32 serverPort = 20005;

private StatsRecording stats = new StatsRecording(serverName, serverIP, serverPassword, serverPort);

private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();

private List<ServerCommand> newCmds = new List<ServerCommand>();

private Stopwatch MissionTimer = new Stopwatch();

#endregion

 

int LastMissionLoaded = 0;

 

double initTime;

 

 

// loading sub-missions

public override void OnTickGame()

{

#region Stats Timer

if (MissionTimer.Elapsed.TotalSeconds >= 5) // 5 seconds

{

MissionTimer.Restart(); // stopwatch reset to 0 and restart

if (stats != null )

{

newCmds = stats.getCommands();

if (newCmds != null && newCmds.Count > 0)

ProcessCommands(newCmds);

}

}

#endregion

///////////////////////

 

//Add any other mission time stuff here:

 

if (Time.tickCounter() % 216000 == 108000) // 216000=120 min repeat. 108000=60 min delay.

{

// GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small01.mis");

}

 

if (Time.tickCounter() % 216000 == 215999) // 216000=120 min repeat. 215999=120 min delay.

{

// GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/BoF1/BoF1_small02.mis");

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////

 

public override void OnTrigger(int missionNumber, string shortName, bool active)

{

base.OnTrigger(missionNumber, shortName, active);

 

AiAction Action = GamePlay.gpGetAction(shortName);

 

if (Action != null)

Action.Do();

 

GamePlay.gpGetTrigger(shortName).Enable = true;

}

 

// Base Scripts for Missions

private bool isAiControlledPlane (AiAircraft aircraft)

{

if (aircraft == null)

{

return false;

}

 

Player [] players = GamePlay.gpRemotePlayers ();

foreach (Player p in players)

{

if (p != null && (p.Place () is AiAircraft) && (p.Place () as AiAircraft) == aircraft)

{

return false;

}

}

 

return false;

}

 

private void destroyPlane (AiAircraft aircraft) {

if (aircraft != null) {

aircraft.Destroy ();

}

}

 

private void explodeFuelTank (AiAircraft aircraft)

{

if (aircraft != null)

{

aircraft.hitNamed (part.NamedDamageTypes.FuelTank0Exploded);

}

}

 

private void destroyAiControlledPlane (AiAircraft aircraft) {

if (isAiControlledPlane (aircraft)) {

destroyPlane (aircraft);

}

}

 

private void damageAiControlledPlane (AiActor actor) {

if (actor == null || !(actor is AiAircraft)) {

return;

}

 

AiAircraft aircraft = (actor as AiAircraft);

 

if (!isAiControlledPlane (aircraft)) {

return;

}

 

if (aircraft == null) {

return;

}

 

aircraft.hitNamed (part.NamedDamageTypes.ControlsElevatorDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsAileronsDisabled);

aircraft.hitNamed (part.NamedDamageTypes.ControlsRudderDisabled);

aircraft.hitNamed (part.NamedDamageTypes.FuelPumpFailure);

 

int iNumOfEngines = (aircraft.Group() as AiAirGroup).aircraftEnginesNum();

for (int i = 0; i < iNumOfEngines; i++)

{

aircraft.hitNamed((part.NamedDamageTypes)Enum.Parse(typeof(part.NamedDamageTypes), "Eng" + i.ToString() + "TotalFailure"));

}

 

/***Timeout (240, () =>

{explodeFuelTank (aircraft);}

);

* ***/

 

Timeout (300, () =>

{destroyPlane (aircraft);}

);

}

 

public override void Init(maddox.game.ABattle battle, int missionNumber)

{

base.Init(battle, missionNumber);

MissionNumberListener = -1; //Listen to events of every mission

}

 

//////////////////////////////////////////

// Methods for Stats (You can add any code you may need after the Stats Region

//////////////////////////////////////////

 

public override void OnBattleStarted()

{

base.OnBattleStarted();

#region Stats

MissionTimer.Start(); // start the stopwatch

#endregion

}

 

private void sendScreenMessageTo(int army, string msg, object[] parms)

{

List<Player> Players = new List<Player>();

 

// on Dedi the server or for singleplayertesting

if (GamePlay.gpPlayer() != null)

{

if (GamePlay.gpPlayer().Army() == army || army == -1)

Players.Add(GamePlay.gpPlayer());

}

if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)

{

foreach (Player p in GamePlay.gpRemotePlayers())

{

if (p.Army() == army || army == -1)

Players.Add(p);

}

}

if (Players != null && Players.Count > 0)

GamePlay.gpHUDLogCenter(Players.ToArray(), msg, parms);

}

 

private void ProcessCommands(List<ServerCommand> newCmds)

{

try

{

foreach (ServerCommand sc in newCmds)

{

if (sc.CommandType.Equals("HUDmsg"))

{

if (sc.ToWho.Equals("All"))

GamePlay.gpHUDLogCenter(sc.Command);

else if (sc.ToWho.Equals("Red"))

{

sendScreenMessageTo(1, sc.Command, null);

}

else if (sc.ToWho.Equals("Blue"))

{

sendScreenMessageTo(2, sc.Command, null);

}

else

{

if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)

{

 

foreach (Player p in GamePlay.gpRemotePlayers())

{

if (p.Name() == sc.ToWho)

GamePlay.gpLogServer(new Player[] { p }, sc.Command, null);

}

}

// Message is for a specific player based on player name in string sc.ToWho

}

}

}

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.ProcessCommands - Exception: " + ex);

}

}

 

public override void OnActorCreated(int missionNumber, string shortName, AiActor actor)

{

#region stats

base.OnActorCreated(missionNumber, shortName, actor);

// Add actor to list of all Actors

if (!allActors.ContainsKey(shortName))

allActors.Add(shortName, actor);

try

{

stats.newActor(shortName, actor);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorCreated - Exception: " + ex);

}

#endregion

}

 

 

public override void OnPersonHealth(maddox.game.world.AiPerson person, maddox.game.world.AiDamageInitiator initiator, float deltaHealth)

{

#region stats

base.OnPersonHealth(person, initiator, deltaHealth);

try

{

stats.playerHealth(person, initiator, deltaHealth);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonHealth - Exception: " + ex);

}

#endregion

 

}

 

public override void OnPersonParachuteFailed(maddox.game.world.AiPerson person)

{

#region stats

base.OnPersonParachuteFailed(person);

try

{

stats.personParachute("Failed", person);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonParachuteFailed - Exception: " + ex);

}

#endregion

}

 

public override void OnPersonParachuteLanded(maddox.game.world.AiPerson person)

{

#region stats

base.OnPersonParachuteLanded(person);

try

{

stats.personParachute("Landed", person);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPersonParachuteLanded - Exception: " + ex);

}

#endregion

}

 

public override void OnPlayerArmy(maddox.game.Player player, int army)

{

#region stats

base.OnPlayerArmy(player, army);

try

{

stats.playerArmy(player, army);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerArmy - Exception: " + ex);

}

#endregion

 

}

 

public override void OnPlayerConnected(maddox.game.Player player)

{

#region stats

base.OnPlayerConnected(player);

try

{

stats.pilotInfo(player);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerConnected - Exception: " + ex);

}

 

#endregion

// Your code here

}

public override void OnPlayerDisconnected(maddox.game.Player player, string diagnostic)

{

#region stats

base.OnPlayerDisconnected(player, diagnostic);

try

{

stats.playerDisconnect(player, diagnostic);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlayerDisconnected - Exception: " + ex);

}

 

#endregion

// Your code here

}

 

public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)

{

#region stats

base.OnPlaceEnter(player, actor, placeIndex);

try

{

Point2d actorPos = new Point2d(actor.Pos().x, actor.Pos().y);

String startingGrid = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.sortieBegin(player, actor, placeIndex, actorPos, startingGrid);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlaceEnter - Exception: " + ex);

}

#endregion

//add your code here

}

 

 

public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)

{

#region stats

base.OnPlaceLeave(player, actor, placeIndex);

try

{

stats.sortieEnd(player, actor, placeIndex);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnPlaceLeave - Exception: " + ex);

}

 

#endregion

//add your code here

Timeout(1, () =>

{ damageAiControlledPlane(actor); }

);

}

 

public override void OnAircraftCrashLanded (int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftCrashLanded (missionNumber, shortName, aircraft);

try

{

Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);

String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.aircraftLanded("CrashLanded", shortName, aircraft, actorPos, gridRef);

System.Console.WriteLine("Stats.OnAircraftCrashLanded - ("+shortName+")");

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftCrashLanded - Exception: " + ex);

}

#endregion

//add your code here

Timeout (300, () =>

{ destroyPlane(aircraft); }

);

}

 

public override void OnAircraftTookOff(int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftTookOff(missionNumber, shortName, aircraft);

try

{

stats.aircraftTakeoff(shortName, aircraft);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);

}

#endregion

//add your code here

}

 

public override void OnAircraftLanded (int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftLanded(missionNumber, shortName, aircraft);

try

{

Point2d actorPos = new Point2d(aircraft.Pos().x, aircraft.Pos().y);

String gridRef = GamePlay.gpSectorName(actorPos.x, actorPos.y).ToString();

stats.aircraftLanded("Landed", shortName, aircraft, actorPos, gridRef);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftTookOff - Exception: " + ex);

}

#endregion

//add your code here

 

Timeout(300, () =>

{ destroyPlane(aircraft); }

);

}

 

public override void OnActorDamaged(int missionNumber, string shortName, AiActor actor, AiDamageInitiator initiator, NamedDamageTypes damageType)

{

#region stats

base.OnActorDamaged(missionNumber, shortName, actor, initiator, damageType);

try

{

stats.missionActorDamaged(shortName, actor, initiator, damageType);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDamaged - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnAircraftDamaged(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, NamedDamageTypes damageType)

{

#region stats

base.OnAircraftDamaged(missionNumber, shortName, aircraft, initiator, damageType);

try

{

stats.missionAircraftDamaged(shortName, aircraft, initiator, damageType);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftDamaged - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnAircraftCutLimb(int missionNumber, string shortName, AiAircraft aircraft, AiDamageInitiator initiator, LimbNames limbName)

{

#region stats

base.OnAircraftCutLimb(missionNumber, shortName, aircraft, initiator, limbName);

try

{

stats.missionAircraftCutLimb(shortName, aircraft, initiator, limbName);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftCutLimb - Exception: " + ex);

}

#endregion

//add your code here

}

 

public override void OnActorDead(int missionNumber, string shortName, AiActor actor, List<DamagerScore> damages)

{

#region stats

base.OnActorDead(missionNumber, shortName, actor, damages);

try

{

stats.missionActorDead(shortName, actor, damages);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDead - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnActorDestroyed(int missionNumber, string shortName, AiActor actor)

{

#region stats

base.OnActorDestroyed(missionNumber, shortName, actor);

try

{

stats.actorDestroyed(shortName, actor);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnActorDestroyed - Exception: " + ex);

}

#endregion

//add your code here

 

}

public override void OnAircraftKilled(int missionNumber, string shortName, AiAircraft aircraft)

{

#region stats

base.OnAircraftKilled(missionNumber, shortName, aircraft);

try

{

stats.aircraftKilled(shortName, aircraft);

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnAircraftKilled - Exception: " + ex);

}

#endregion

//add your code here

 

}

 

public override void OnBattleStoped()

{

#region stats

base.OnBattleStoped();

try

{

stats.battleStopped();

// Loop through list of AiActors and destroy them all

List<string> keys = new List<string>(allActors.Keys);

for (int i = 0; i < keys.Count; i++)

{

AiActor a = allActors[keys];

AiAircraft aircraft = a as AiAircraft;

if (aircraft != null)

{

aircraft.Destroy();

}

else

{

AiGroundActor aiGroundActor = a as AiGroundActor;

if (aiGroundActor != null)

{

aiGroundActor.Destroy();

}

else

{

System.Console.WriteLine("Stats.OnBattleStoped - Unknown Actor (" + a.Name()+") ShortName ("+keys+")");

}

}

}

// stats.disconnectStats();

}

catch (Exception ex)

{

System.Console.WriteLine("Stats.OnBattleStoped - Exception: " + ex);

}

#endregion

//add your code here

}

//////////////////////////////////////////////////////////////////////////////////////////////////

 

 

 

}

 

 

Repito que estos peazo de triggers son solo para el clod commander.

 

Editado para que funcione bien, que cometi un pequeño error en la edición principal.

Edited by sandokito
Link to comment
Share on other sites

Bueno, ya he conseguido que funcione bien bien fino.

No si al final aprenderé a programar en c.

 

Dejo para descarga los scrips base, recordar que teneis que renombrarlos con el nombre de la misión, si quereis integrar las misiones en el il2 cod comander.

 

Si no usamos lanzadores de ia usar este.

 

Si usamos lanzadores de ia usar este otro.

 

Mas adelante implementare los scrip necesarios para poder crear misiones y que se carguen submisiones.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Some pretty cookies are used in this website