PDA

View Full Version : Sal's useful scripts [plane types in map labels]



Salmo
Feb-12-2014, 18:11
It frustrates me to join a mission, select an army, & see the spawn spawn bases, but I see base names but no indication of what planes are at those bases. In some cases mission builders include the planeset in the base name, but what if the mission builder wants to change the planeset around? They would have to rename all their spawn bases. I have an easier solution. Just name your bases in FMB when you build your mission & run this script with the mission. All bases are automatcally renamed to include their current planeset in the map label.



public class Mission : AMission
{
bool PlaneTypesInMapLabels = true; // include spawn-base plane types within the base label on the map screen

public override void OnBattleStarted()
{
base.OnBattleStarted();

if (PlaneTypesInMapLabels)
{
Timeout(10.0, () =>
{ // wait for bases to 'spawn-in' to battle then rename them all
PutPlaneTypesInMapLabels(); // put plane types in the spawn-base map labels
});
}
}

public void PutPlaneTypesInMapLabels()
{
// put plane types in the spawn-base map labels
foreach (AiBirthPlace bp in GamePlay.gpBirthPlaces())
{
string OldMapLabel = bp.Name();
string[] Planeset = bp.GetAircraftTypes();
string[] words = bp.Name().Trim().Split('(');
string MapLabel = words[0] + " (";
foreach (string aircraftname in Planeset)
{
if (aircraftname.Contains("Spit")) MapLabel = MapLabel + "Spitfire, ";
if (aircraftname.Contains("Hurr")) MapLabel = MapLabel + "Hurricane, ";
if (aircraftname.Contains("Blenheim")) MapLabel = MapLabel + "Blenheim, ";
if (aircraftname.Contains("DH82A ")) MapLabel = MapLabel + "Tiger Moth, ";
if (aircraftname.Contains("88")) MapLabel = MapLabel + "Ju88, ";
if (aircraftname.Contains("87")) MapLabel = MapLabel + "Ju87, ";
if (aircraftname.Contains("109")) MapLabel = MapLabel + "Bf109, ";
if (aircraftname.Contains("BR")) MapLabel = MapLabel + "BR20, ";
if (aircraftname.Contains("G50")) MapLabel = MapLabel + "G50, ";
if (aircraftname.Contains("111")) MapLabel = MapLabel + "He111, ";
if (aircraftname.Contains("110")) MapLabel = MapLabel + "Bf110, ";
if (aircraftname.Contains("CR")) MapLabel = MapLabel + "CR42, ";
}
MapLabel = MapLabel.Remove(MapLabel.LastIndexOf(',')) + ")"; ; // get last occurance of , character
RenameSpawnbase(bp, MapLabel);
//Console.WriteLine("Renamed " + OldMapLabel + " to " + MapLabel);
}

public void RenameSpawnbase(AiBirthPlace bp, string name)
{
// write a temporary mission file with the new base name
try
{
ISectionFile f = GamePlay.gpCreateSectionFile();
string line = '"' + name + '"' + bp.Army().ToString() + " " + bp.Pos().x.ToString() + " " +
bp.Pos().y.ToString() + " 0 " + bp.MaxPlanes().ToString() + " " + "1" + " " +
"1" + " " + bp.Country() + " " + bp.Hierarchy() + " " + bp.Regiment();
f.add("BirthPlace", line, null); // write a line of text to the file
string[] planeset = bp.GetAircraftTypes();
foreach (string aircraft in planeset) f.add("BirthPlace0", aircraft, null);
bp.destroy();
GamePlay.gpPostMissionLoad(f);
}
catch (NullReferenceException n)
{ }
catch (Exception e)
{
Console.WriteLine("ERROR: [RenameSpawnbase] " + e.Message);
}
}

}

Kling
Feb-13-2014, 07:17
yes this would be really helpful!!
Well done!

ATAG_Lolsav
Feb-13-2014, 10:45
Thanks for Reddogs and Salmos scripts i hope to see a "boom" of mission making, with more people understanding how scripts works by looking at examples.

Thank you very much boys!

I would like to ask 2 thing, if any of you can reply:

1 - Cautions to have in multiplayer scripting (what can and cannot be done)

2 - Is the use of libraries "at will", or can they make the missions performance worse?

Salmo
Feb-13-2014, 16:12
1 - Cautions to have in multiplayer scripting (what can and cannot be done) - Virtually every aspect of gameplay, except flight models, can be controled or changed using scripts.

2 - Is the use of libraries "at will", or can they make the missions performance worse? - I use a large number of libraries & it does seem to adversely affect mission performance. I use most of the game built-in libraries & am increasingly using more standard c# libraries to perform some of the more complex tasks.

SoW Reddog
Feb-13-2014, 17:06
- I use a large number of libraries & it does seem to adversely affect mission performance.

Did you really mean that bold bit, or should there be a NOT somewhere in that sentence ie "it does NOT seem":recon:

Salmo
Feb-14-2014, 02:38
Woops, correction to my statement 2 posts up ....

2 - Is the use of libraries "at will", or can they make the missions performance worse? - I use a large number of libraries & it does NOT seem to adversely affect mission performance. I use most of the game built-in libraries & am increasingly using more standard c# libraries to perform some of the more complex tasks.[/QUOTE]

ATAG_Lolsav
Mar-04-2014, 16:43
Just reporting i was able to port this script to my test mission and to make it work with the other scripts. Whoever trys the same remember to move declarations on top and to put the required info of "public override void OnBattleStarted()" in its place.