Customizing The Warfare Aircraft Factory Part 2.

Scripting The Warfare Module.

Last post I placed the basic units in the mission editor and got everything setup for my Warfare mission. (See Customizing The Warfare Aircraft Factory Part 1.)

Now I’m going to create the custom scripting required to add a BAF lite CH-47 to the Warfare Aircraft Factory.

This is a basic example so I’m going to limit my customizations to just the Aircraft Factory and only the West side.

Overview Of The Script Logic Flow

If you have ever poked around in the Warfare module code or even the stripped down example missions you might have found it a bit overwhelming. The following illustration is my attempt to visualize the flow through each of the components we are concerned with for this simple mission.

  1. Warfare Editor Module: When I placed this in the mission editor (see step 3 of  Customizing The Warfare Aircraft Factory Part 1.) I added a line of code to the module’s initialization field telling it where to find my custom script. In my example I’m going to build a file called InitMission.sqf.
  2. InitMission.sqf: from this file the warfare module will get the names of all my custom initialization scripts.  I’ll be using the defaults except for my common init Init_Common.sqf
  3. Init_Common.sqf: here is where I will declare the variables I need as well as call the script Config_AircraftFactory.sqf.
  4. Config_AircraftFactory.sqf: This is where I’ll place all the details of the available units (names, costs etc.)

Step 1: Create Folders

When I saved my example mission Arma II created a mission folder called example.Chernarus in My Documents \ ArmA 2 \ missions. When I use Windows to navigate to this folder I see it contains only mission.sqm The first thing I’m going to do is create some folders to better organize my scripts. With such a simple mission this is not required, but if I ever decide to expand the mission later being organized from the start will make that easier. Also by using the Warfare module’s folder layout and naming conventions as a template for my mission it should make the inevitable debugging easier as well.

So inside your mission folder you will need to create a new folder called Common. This is where we will put all the initialization and configuration scripts.

Next open up the newly created Common folder. Inside it create two new folders called Init, and Config. Now that we have our folder layout ready we can create the first script.

Step 2: Create The InitMission.sqf

Open up Notepad or the basic text editor of your choice and copy paste the following code into it:

BIS_WF_Common SetVariable ["sidePlacement",[true,-1,-1]];
BIS_WF_Common SetVariable ["customInitClientScript",""];


BIS_WF_Common SetVariable ["customInitCommonScript","Common\Init\Init_Common.sqf"];


BIS_WF_Common SetVariable ["customInitServerScript",""];
BIS_WF_Common SetVariable ["customInitBasesScript",""];
BIS_WF_Common SetVariable ["customBaseLayoutsScript",""];
BIS_WF_Common SetVariable ["customTownsScript",""];
BIS_WF_Common SetVariable ["customTownPath",""];

 

Next save the document as InitMission.sqf in your mission folder (in my case example.Chernarus).

If you are using Notepad, make sure you select the file type as all files. If you save it as a text file, Notepad will append the file extension .txt to your file and Arma will just ignore it. For added confusion Windows by default will hide the file extension of files it recognizes. So Notepad will save it as  InitMission.sqf.txt but Windows will show you InitMission.sqf. Your Warfare mission wont work, but everything will look ok. You’ll get frustrated and write me a nasty email, and I’ll say “I told you so”.

Save yourself some head bashing and make sure you select the file type as all files.

Explanation of InitMission.sqf

All the above code in Black is for customizing features that I’m not interested in for this simple mission.

For example the customBaseLayoutsScript variable is used to call the script that configures custom base layouts. I don’t need that for my mission, the default settings are fine.

However even though I don’t need them, I’m setting the variables to “” (ie. blank). I have to do this, because if I don’t my Warfare mission will hang at “Recieving” when I start it. I don’t know why, I just know that I need to specifically set the variables to blank for the module to use the default settings.

I’ve highlighted the line of code that we are concerned with in Blue. The variable customInitCommonScript I’m going to assign with the path and file name of my custom initialization script (highlighted in Red) which we will create next.

Step 3: Create The Init_Common.sqf

In notepad again, I’m going to create the Init_Common.sqf file with the following code:

aircraftUnits = [];
[] Call Compile PreprocessFile ("Common\Config\Config_AircraftFactory.sqf");

 

Save the file as  Init_Common.sqf in the example.Chernarus\common\init\ folder. Again make sure you don’t save it as a .txt file type.

The first line of code in my Init_Common.sqf sets the aircraftUnits variable to a blank array. I’m doing this to clear out the default units the Warfare module may have placed in the array.

The second line of code calls my custom config file for the aircraft factory.

Note that I could have placed the custom aircraft factory code here in my Init_Common.sqf – I don’t have to create a separate file. If I ever plan on expanding this mission it makes things a lot less confusing and more manageable to separate the config code out into their own files.

Step 4: Create the Config_AircraftFactory.sqf

In this file I’m going to place all the config information for my aircraft factory units. (cost, number of crew, available units etc.) I open up Notepad and start with declaring the variables used I will use in the Config_AircraftFactory script.

Private["_c","_config","_m","_p","_pilotCost","_t","_total","_u"];

  • _c is the base cost of the helicopter
  • _config will hold information about the unit, pulled from the addon.
  • _m is the number of men a crewed unit will have when purchased
  • _p a value for each unit that will get stuffed into westAircraftPoints (I’m not clear on this one, more research required)
  • _pilotCost is the cost for each crew member.
  • _t is the time required to build the unit
  • _total a counter
  • _u an array of class names of our helicopter units

Next I’ll add the code for my first unit. I’ll start with a UH1.

_u            = ["UH1Y"];
_c            = [3500];
_m            = [2];
_t            = [35];
_p            = [20];

  • _u is the units class name as it appears in the addon’s configfile. You can find Arma II classnames on the Official Forums. If you are using a mod, hopefuly the mod’s author was kind enough to provide a readme with the unit names.
  • _c is the cost of an empty UH1
  • _m is the number of crew
  • _t is the construction time of the unit
  • _p is the number of points for the unit (?)

For the second available unit I’m going to add my CH-47. Note that _u, _c etc are arrays, so I’m just going to add the information about my CH-47 to my existing arrays.

_u = _u        + ["CH_47F_BAF"];
_c = _c        + [40];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

Next I’m going to initialize some the of the variables:

_pilotCost = 75;

 

westAircraftDescriptions = [];
westAircraftFactions = [];
westAircraftImages = [];
westAircraftMannedCosts = []

This next block of code will step though each of the units I’ve placed in the array _u and pull the unit’s information from the configfile

_total = Count _u;
for [{_count = 0},{_count < _total},{_count = _count + 1}] do
{
_config = configFile >> "CfgVehicles" >> (_u Select _count);
westAircraftMannedCosts = westAircraftMannedCosts + [(_c Select _count) + (_m Select _count) * _pilotCost];
westAircraftDescriptions = westAircraftDescriptions + [GetText (_config >> "displayName")];
westAircraftFactions = westAircraftFactions + [Localize "STR_FN_USMC"];
westAircraftImages = westAircraftImages + [GetText (_config >> "picture")];
};

The section I’ve highlighted in Blue is a bit different as I’m not pulling the information from the addon, but forcing all my aircraft to be of the USMC faction. I’m doing this as the CH-47 by default is BAF and I don’t plan on using that faction for this mission.

The next block of code stuffs my variables into the Warfare module’s global variables.

westAircraftUnits = _u;
westAircraftCosts = _c;
westAircraftCrews = _m;
westAircraftTimes = _t;
westAircraftPoints = _p;

 

aircraftUnits = westAircraftUnits;
aircraftUnitCosts = westAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions;

 

 

//Determine longest build time.
longestAircraftBuildTime = 0;
_t = westAircraftTimes;
for [{_count = Count _t - 1},{_count >= 0},{_count = _count - 1}] do
{
if (_t Select _count > longestAircraftBuildTime) then
{
longestAircraftBuildTime = _t Select _count;
};
};

Complete Config_AircraftFactory

So when I’m done typing my code looks like the following:

Private["_c","_config","_data","_m","_p","_pilotCost","_t","_total","_u"];

 

//WEST
_u            = ["UH1Y"];
_c            = [3500];
_m            = [2];
_t            = [35];
_p            = [20];

 

_u = _u        + ["CH_47F_BAF"];
_c = _c        + [40];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

_u = _u        + ["MV22"];
_c = _c        + [4000];
_m = _m        + [2];
_t = _t        + [40];
_p = _p        + [30];

 

_u = _u        + ["AH1Z"];
_c = _c        + [7500];
_m = _m        + [2];
_t = _t        + [55];
_p = _p        + [50];

 

_pilotCost = 75;

westAircraftDescriptions = [];
westAircraftFactions = [];
westAircraftImages = [];
westAircraftMannedCosts = [];

 

_total = Count _u;
for [{_count = 0},{_count < _total},{_count = _count + 1}] do
{
_config = configFile >> "CfgVehicles" >> (_u Select _count);
westAircraftMannedCosts = westAircraftMannedCosts + [(_c Select _count) + (_m Select _count) * _pilotCost];
westAircraftDescriptions = westAircraftDescriptions + [GetText (_config >> "displayName")];
westAircraftFactions = westAircraftFactions + [Localize "STR_FN_USMC"];
westAircraftImages = westAircraftImages + [GetText (_config >> "picture")];
};

 

westAircraftUnits = _u;
westAircraftCosts = _c;
westAircraftCrews = _m;
westAircraftTimes = _t;
westAircraftPoints = _p;

aircraftUnits = westAircraftUnits;
aircraftUnitCosts = westAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions;

 

 

//Determine longest build time.
longestAircraftBuildTime = 0;
_t = westAircraftTimes;
for [{_count = Count _t - 1},{_count >= 0},{_count = _count - 1}] do
{
if (_t Select _count > longestAircraftBuildTime) then
{
longestAircraftBuildTime = _t Select _count;
};
};

I save this file as Config_AircraftFactory.sqf and I place it in my example.Chernarus\common\config. Again, making sure I don’t save it as a .txt file.

Note that I’ve added code for the MV22 and AH1Z as well. Also to keep things simple I’ve only concerned myself with West units. To add East and Resistance units I would need to add a block of code for their units and stuff the information into the Warfare variables as follows

aircraftUnits = westAircraftUnits + eastAircraftUnits + resistanceAircraftUnits;
aircraftUnitCosts = westAircraftCosts + eastAircraftCosts + resistanceAircraftCosts;
aircraftUnitDescriptions = westAircraftDescriptions + eastAircraftDescriptions + resistanceAircraftDescriptions;

 

That is all the scripting required to do a basic customization of the Aircraft Factory in a Warfare mission. Everything should work well if I’ve made no typos.

Reference

PreprocessFile

Call

Compile

Arma II class names

Customizing The Warfare Aircraft Factory Part 1.

Customizing The Warfare Aircraft Factory Part 3.

custom_warfare_aircraftfactory.Chernarus example mission.

Customizing The Warfare Aircraft Factory Part 1.

Adding Units To A Warfare Aircraft Factory.

arma2 warfare aircraft factory

Aircraft Factory At Warfare HQ

A while back Atharol wrote a comment on the Creating An Airport Factory post asking how to customize the Warfare Aircraft Factory. The Aircraft Factory is where the players  can purchase rotary winged aircraft during a Warfare mission.

To illustrate how to change the units in the Aircraft Factory, I’m going to step through the creation of a simple Warfare mission with a purchasable CH-47 from the BAF Lite addon.

I’m going to try and strip my example down to the basics. To keep things organized I’ll split my explanation into two posts – one covering the mission editor and the second the required scripting.

So here we go with Part 1: the mission editor.

 

Step 1: Insert A Playable Unit

The first thing you have to do is open up the mission editor and insert a player unit. In my example I’m going to insert a USMC Riffleman on Chernaurus. It is important that you have a player unit inserted in the mission editor, because for step 2 I’m going to insert an empty unit. (Empty units are not available unless a player unit is present on the map.)

Select Units (F1) and double click on the map. Change the settings to the following:

Inserting A USMC Rifleman

Side: BLUFOR

Faction: USMC

Class: Men

Unit: Rifleman

By default the Warfare editor module only works with the default Arma II factions (USMC, Russian etc). For this example I’m only going to insert one unit with no custom factions. Again to try and keep things as simple as possible.

 

Step 2:  Insert An Empty Aircraft Factory

Next I’m going to insert an Empty Aircraft Factory.  Make sure you still have Units (F1) selected and double click on the map, but not too close to the rifleman – we don’t want the editor to group the two units together. Note the Warfare module will not reposition the Aircraft factory when the mission starts. Don’t put it too far from the playable rifleman or you may have a bit of a walk when you are testing the mission.

insert aircraft factory

Inserting An Aircraft Factory

Change the settings to the following:

Side: Empty

Class: Warfare Buildings

Unit: Aircraft Factory (USMC)

 

Once the empty Aircraft factory is inserted we can next insert the Warfare module itself.

 

 

 

Step 3: Insert A Warfare Editor Module

Select Modules (F7) and chose the Warfare module from the list. In the Initialization type the following line of code:
BIS_WF_Common SetVariable ["customInitMissionScript","InitMission.sqf"];

This tells the warfare module that we are going to use our own custom mission scripts, the details of which will be in InitMission.sqf.
We will build the InitMission.sqf and our other custom scripts in the next post.

Step 4: Synchronize The Units

I have the basics of my Warfare mission inserted into the editor, now I just need to tell the Warfare module that my rifleman & Aircraft Factory exist. To do this I need to synchronize these two units to the Warfare module by selecting Synchronize (F5). Then I can  click and hold my mouse button  on the rifleman and drag the synchronize line to the warfare module – then letting go of the mouse button. Once I’ve done the same thing with the Aircraft Factory, my mission should look like the following:

warfare_mission_editor

Warfare In The Mission Editor

 

Step 5: Limiting The Module With A Marker

By default the Warfare module will select a random start location on the map and move the player there on mission start. Normally this would be fine, but the module wont move the Aircraft factory.  I could end up having to walk to the other side of the map to test my new factory. Since I have better things to do, I’m going to limit the Warfare module to an area around my factory. To do this I have to insert a specially named marker.

Select Markers (F6) and double click on the map near the aircraft factory. I’m going to choose a rectangular map marker and I’m going to name it:

BIS_WF_InitRegion0

This specially named marker tells the warfare module to only use the built-in map locations that are covered by the marker. Since my marker doesn’t have any locations within it’s boundaries, the module will just spawn my rifleman where he was placed in the editor. As an added bonus, there will be no city locations; so no AI to complicate my testing.

That is all I need in the editor, so I’ll save the mission.

In Customizing The Warfare Aircraft Factory Part 2 I’ll break out notepad and do some custom scripting.

 

Reference

Customizing The Warfare Aircraft Factory Part 2.

Customizing The Warfare Aircraft Factory Part 3.

db’s Twitter Digest for 2011-06-06 to 2011-06-12

db’s Sandbox Gets A New Look.

New Layout For My Arma Blog.

It was a matter of necessity, not style. The WordPress theme I had been using previously was a bit heavy and slowing down the whole blog. This wasn’t a problem back when I was the only one reading it, but last month my little blog served up almost 9000 pages. Not bad for a site that is essentially notes to myself. (I know of meatloaf recipes that get more traffic than my site, so I don’t let it go to my head.)

Procrastination, Blogging and the Approach of Winter.

Time is a funny thing. I’m going about my life and then I notice that three months have passed without me posting anything new. I swear it felt like one week had passed since my last post.

I could offer up the usual excuses, apologies and promises. Really it’s just the standard mix of priorities and procrastination. (Too much of one, not enough of the other).

db in construction safety gear

db Under Construction

Right now my top priority is to finish my home renovation. I’m currently at the “gut the entire house down to the studs” phase. I have to get this finished quickly because the thought of only plywood sheeting between myself and a Canadian winter does not appeal to me.

I do have a bunch of Arma II related stuff I’ve been working on though. It’s just a matter of less procrastination and more typing. My plan then is to get at least one post a month finished until I get my renovations to a more winter ready state.

Having said that you know I’m going to use my ongoing construction project as an excuse when I don’t post regularly.

db’s Twitter Digest for 2011-05-16 to 2011-05-22