By way of example, how would I combine the following two scripts:
Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
public class Mission : AMission
{
public override void OnTickGame()
{
// loads the 1st sub-mission in 10 min and repeates it every 60 min.
if (Time.tickCounter() % 108000 == 18000) // 108000 = 60 min repeat. 18000 = 10 min delay.
// pls. note!!! the 1st figure above must be always larger than 2nd!
{
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/My_mis1/mission1.mis");
// prints message on screen after mission load
GamePlay.gpHUDLogCenter("Hello, world! Mission1.mis loaded!");
// prints message on screen in 10 minutes / 600 seconds
double initTime = 0.0;
Timeout(initTime += 600, () =>
{
GamePlay.gpHUDLogCenter("10 minutes into the 1st mission! Wow! It works!!!");
});
// prints message on screen in 5 minutes / 300 seconds
Timeout(initTime += 300, () =>
{
GamePlay.gpHUDLogCenter("Wholy s.. it works!!!");
});
}
// loads the 2nd sub-mission, etc. the same way
if (Time.tickCounter() % 108000 == 54000) // 108000 = 60 min repeat, 54000 = 30 min delay.
{
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/My_mis1/mission2.mis");
GamePlay.gpHUDLogCenter("Mission2.mis loaded!");
double initTime = 0.0;
Timeout(initTime += 600, () =>
{
GamePlay.gpHUDLogCenter("Mission2 10 min message!");
});
Timeout(initTime += 300, () =>
{
GamePlay.gpHUDLogCenter("Mission2 15 min message!");
});
}
// loads the 3rd sub-mission
if (Time.tickCounter() % 108000 == 90000) // 60 min repeat, 50 min delay
{
GamePlay.gpPostMissionLoad("missions/Multi/Dogfight/My_mis1/mission3.mis");
GamePlay.gpHUDLogCenter("Mission3.mis loaded!");
double initTime = 0.0;
Timeout(initTime += 600, () =>
{
GamePlay.gpHUDLogCenter("Mission3 10 min message!");
});
Timeout(initTime += 300, () =>
{
GamePlay.gpHUDLogCenter("Now it really works! You are a genius! Have fun!");
});
}
}
}
with
Code:
using System;
using maddox.game;
using maddox.game.world;
using System.Collections.Generic;
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); }
);
}
}
Can i just paste the second piece of code (minus the namespace declarations and the first public class declaration) onto the end of the first piece of code?
I think it should work but I'm still a little hazy on class declarations etc at the moment.
Cheers,
WB.