Jump to content
Sign in to follow this  
metallicafan33

warfare ai buy air units

Recommended Posts

hello all,

I am currently making a warfare mission.

But I know from playing previous warfare games that ai does not buy helicopters.

I would love to see the ai do this, so my question is, does anybody know how to do this?

Greetings metallicafan

Share this post


Link to post
Share on other sites

By default AI teams in WF won't use aircraft, they're not configured for it. But they will buy and fly aircraft if you configure an Air Team. It takes a custom init and some patience working in the Teams and Squads config. Darren Brant shows how to rework the Aircraft config, you would be working with the Teams and Squads config in a similar manner to create the Air Team.

http://sandbox.darrenbrant.com/arma_ii/customizing-the-warfare-aircraft-factory-part-1

http://sandbox.darrenbrant.com/arma_ii/customizing-the-warfare-aircraft-factory-part-2

http://sandbox.darrenbrant.com/arma_ii/customizing-the-warfare-aircraft-factory-part-3

They won't land for capture missions unless scripted for it, just hover over a strongpoint until captured by ground units; but they can be set to do the recon missions pretty easily by adding the team to one of the Recon mission scripts. I've had an AI Air Team flying in my Warfare mission for some time now. They work pretty well, the only real nuisance being they often get shot down quick, and knuckleheaded AI Base Commanders sometimes place the Aircraft Factory in a wooded area which makes for a lot of exploding aircraft.

As I recall there was another script besides the Team and Squads config that had to be worked with in custom init, but I have to dig through my mission to find which one. I think it had to do with Aircraft factory missing from the factory search, but not certain on that.

---Edit --

A note regarding Darren Brant's part2 above - he includes a custom Town Path in his custom init example. In your custom init, don't include the line for a custom Town Path unless you have scripts in the mission folder for configuring towns, it causes an error. The line only gets added to the init when you configure towns and include the scripts. He had demonstrated adding custom towns earlier in his blog, which is why I think he included it.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Thanks for the reply!

I am immediately going to try this out and I will post the results in a couple of minutes here.

Again thank you!

---------- Post added at 18:25 ---------- Previous post was at 17:19 ----------

I followed the tutorial and got it all working.

I have already tried a lot of things to get the ai to buy them but with no luck yet.

I hope you can help me with it

another edit:

I added this to the config_teams file

_n = _n + ["Air"];
_d = _d + ["Air Team"];
_t = _t + [_AIR];
_ab=_ab + [_TEAMTYPENORMAL];
_ai=_ai + [false];
_f = _f + [Localize "STR_FN_USMC"];
_i = _i + [false];
_l = _l + [false];
_h = _h + [false];
_a = _a + [true];
_u         = ["AH1Z"];
_u = _u + ["AH1Z"];
_c = _c + [_u];

and this:

//WEST
_n = _n + ["AirSquad"];
_d = _d + ["AH1Z Squad"];
_t = _t + [_AIR];
_ai = _ai + [false];
_f = _f + [Localize "STR_FN_USMC"];
_te = _te + ["Air"];
_s = _s + [_te];

to config_squad

I also added

_AIR = Localize "STR_WF_TEAMAIR";

to private where it also says specops and the others but it didn't do the trick

I have included both files so you can see what I have edited

https://www.mediafire.com/?inxcrbl1h601xv2

Edited by metallicafan33

Share this post


Link to post
Share on other sites

I just created a mission from scratch and got them flying. Didn't have to mess with the Squads config, I used that in my regular mission for creating an air assault team. You just need to do the Teams config to start with.

1) Lay down 8 units for each side, synch to Warfare module.

(Note: the only reason for placing eight units to a side is that it's how many AI Team Templates each side has listed in the config. If you were to list twelve AI Team Templates you could place up to twelve units for that side.)

2) In WF module init:

BIS_WF_Common SetVariable ["customInitMissionScript","InitMission.sqf"];
 

3) Save the mission.

4) In mission folder create InitMission.sqf:

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",""];
 

5) In mission folder create folder "Common". In this folder create subfolders "Init" and "Config".

6) In subfolder "Init" create Init_Common.sqf:

 

// This will run your custom Teams config.
[] Call Compile PreprocessFile ("Common\Config\Config_Teams.sqf");
// Needed for the base defense units.
[] Call Compile PreprocessFile (corepath + "Common\Config\Config_Squads.sqf");  // Added by edit (see subsequent post #10 below)

// Use these for testing purposes only.
// Gives huge funds and supplies so construction goes fast and aircraft can be afforded.
// Remove this when testing is finished and ready to gameplay your mission:

// Change player starting funds
//-----------------------------
_eastPlayerStartingFunds = 20000;
_westPlayerStartingFunds = 20000;
_ResistancePlayerStartingFunds = 20000;
for [{_count = 0},{_count < 32},{_count = _count + 1}] do
{
	Call Compile Format["EastPlayer%1Funds = _eastPlayerStartingFunds",_count + 1];
	Call Compile Format["WestPlayer%1Funds = _westPlayerStartingFunds",_count + 1];
	Call Compile Format["ResistancePlayer%1Funds = _resistancePlayerStartingFunds",_count + 1];
};

// Change AI starting funds
//-------------------------
_westAIStartingFunds = 20000;
_eastAIStartingFunds = 20000;
_resistanceAIStartingFunds = 20000;
for [{_count = 0},{_count < 32},{_count = _count + 1}] do
{
	Call Compile Format["EastAI%1Funds = _eastAIStartingFunds",_count + 1];
	Call Compile Format["WestAI%1Funds = _westAIStartingFunds",_count + 1];
	Call Compile Format["ResistanceAI%1Funds = _resistanceAIStartingFunds",_count + 1];
};

// Change AI Commander funds
//-----------------------
WestAICommanderFunds = 20000;
EastAICommanderFunds = 20000;
ResistanceAICommanderFunds = 20000;

// Change starting supplies
//-------------------------
WestSupplies = 50000;
EastSupplies = 50000;
ResistanceSupplies = 50000;

 

7) In subfolder "Config" place a copy of the Warfare script Config_Teams.sqf. In the copy do the following:

a. At the beginning of the script change this:

 

Private["_ARMOR","_INFANTRY","_MECHANIZED","_SPECOPS"];
_ARMOR = Localize "STR_WF_TEAMARM";
_MECHANIZED = Localize "STR_WF_TEAMMECH";
_INFANTRY = Localize "STR_WF_TEAMINF";
_SPECOPS = Localize "STR_WF_TEAMSPEC";
 

to this:

 

Private["_ARMOR","_INFANTRY","_MECHANIZED","_SPECOPS","_AIR"];
_ARMOR = Localize "STR_WF_TEAMARM";
_MECHANIZED = Localize "STR_WF_TEAMMECH";
_INFANTRY = Localize "STR_WF_TEAMINF";
_SPECOPS = Localize "STR_WF_TEAMSPEC";
_AIR = Localize "STR_WF_TEAMAIR";

 

b. In side West for USMC faction, find "TankHeavy" template and insert this:

 

_n = _n	+ ["TankHeavy"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "M1A2" >> "displayName")];
_t = _t + [_ARMOR];
_ab=_ab + [_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_USMC"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [true];
_a = _a	+ [false];
_u		= ["M1A2_TUSK_MG"];
_c = _c	+ [_u];

_n = _n	+ ["HeliAttack"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "AH1Z" >> "displayName")];
_t = _t + [_AIR];
_ab=_ab + [_TEAMTYPEAA+_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_USMC"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [false];
_a = _a	+ [true];
_u	= ["AH1Z"];
_c = _c	+ [_u];

_n = _n	+ ["HeliGunship"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "AH64D" >> "displayName")];
_t = _t + [_AIR];
_ab=_ab + [_TEAMTYPEAA+_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_USMC"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [false];
_a = _a	+ [true];
_u	= ["AH64D"];
_c = _c	+ [_u];

//Patrol teams for towns.

 

c. At the end of West config change this:

 

//AI commander preferences for AI teams.
_t		= ["InfantryFT"];
_t = _t	+ ["InfantryAT"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["Recon"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["BlackOps"];
WestAITeamTemplates = _t;
 

to this:

 

//AI commander preferences for AI teams.
_t		= ["InfantryFT"];
_t = _t	+ ["InfantryAT"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["Recon"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["HeliAttack"];
WestAITeamTemplates = _t;

 

d. In side East for RU faction, find "TankHeavy" template and insert this:

 

_n = _n	+ ["TankHeavy"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "T90" >> "displayName")];
_t = _t + [_ARMOR];
_ab=_ab + [_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_RU"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [true];
_a = _a	+ [false];
_u		= ["T90"];
_c = _c	+ [_u];

_n = _n	+ ["HeliAttack"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "Mi17_rockets_RU" >> "displayName")];
_t = _t + [_AIR];
_ab=_ab + [_TEAMTYPEAA+_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_RU"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [false];
_a = _a	+ [true];
_u	= ["Mi17_rockets_RU"];
_c = _c	+ [_u];

_n = _n	+ ["HeliGunship"];
_d = _d	+ [GetText (configFile >> "CfgVehicles" >> "Mi24_V" >> "displayName")];
_t = _t + [_AIR];
_ab=_ab + [_TEAMTYPEAA+_TEAMTYPEAT];
_ai=_ai	+ [false];
_f = _f	+ [Localize "STR_FN_RU"];
_i = _i	+ [false];
_l = _l	+ [false];
_h = _h	+ [false];
_a = _a	+ [true];
_u	= ["Mi24_V"];
_c = _c	+ [_u];

//Patrol teams for towns.

 

e. At end of East config change this:

 

//AI commander preferences for AI teams.
_t		= ["InfantryFT"];
_t = _t	+ ["InfantryAT"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["ReconLight"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["Sniper"];
EastAITeamTemplates = _t;
 

to this:

 

//AI commander preferences for AI teams.
_t		= ["InfantryFT"];
_t = _t	+ ["InfantryAT"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["ReconLight"];
_t = _t	+ ["TankLight"];
_t = _t	+ ["MechanizedMedium"];
_t = _t	+ ["HeliAttack"];
EastAITeamTemplates = _t;

 

That should get you started, use it for a test basis to build into your mission. I tested on Utes with and without Corepatch addon. Worked under both.

Edited by opusfmspol
Removed old color indicators in code

Share this post


Link to post
Share on other sites

It's working.

I really can't thank you enough for your help

Edit: the helicopters are working, but now the 2 riflemen that are supposed to defend and patrol base don't recruit men anymore.

I probably have to edit something for it but I don't know what.

Can you help me with this too?

Edited by metallicafan33

Share this post


Link to post
Share on other sites
the 2 riflemen that are supposed to defend and patrol base don't recruit men anymore.

I'm not encountering it, but two things that come to mind are:

1) Synchronization. They get synchronized with the WF module just like the other units.

2) It's a group assignment. Maybe you assigned the mission to the unit instead of the unit's group. Their init in editor should be:

Base Defense Team:

Group this SetVariable["dedicatedMission","DefendBase"];

Base Patrol Team:

Group this SetVariable["dedicatedMission","PatrolBase"];

Share this post


Link to post
Share on other sites

I just created a small test mission for it.

The unit did recruit when I didn't initialize the config_teams.sqf file.

And the unit did not recruit units anymore when I did initialize the file, so there is definitely something there causing the problem for me.

I will take a good look at the file again because maybe I am missing something.

Just to be clear for this mission I only edited what you told me to in the posts before.

Share this post


Link to post
Share on other sites

:eh: I don't understand why, but in my regular mission (which I've been building out for almost a year now) it doesn't happen; but when I added the base defense and patrol teams to the scratch air mission it did happen... ?!?!? :exclamation:

I'm going to have to dig through my mission's scripts to figure this one out. Apparently I dealt with it at some point and didn't bother to make a note of it. :dozingoff:

Share this post


Link to post
Share on other sites

I know a quick workaround for it, but it still doesn't work when building a FSB.

for base defense you can just add some more soldiers to the group, but then again I don't think the leader is going to recruit more units.

I'm really curious to see what is causing this and how it can be fixed

Share this post


Link to post
Share on other sites

Found it.

The Team and Squad configs need to be recompiled together, even if you're not amending the Squads.

When the configs are compiled the Squads get amended to the Teams arrays to provide an "upgrade" feature when the team leader can afford it. Included are two "Special" squads which are used only by the base teams. By recompiling Teams and not Squads, the "Special" squads which the base teams use are left out of the array.

There are three ways of dealing with it, depending on whether or not you use Corepatch by Goliath86, or want to configure additional squads:

1) Not using Corepatch, not configuring squads:

In Init_Common.sqf run this:

[] Call Compile PreprocessFile ("Common\Config\Config_Teams.sqf");[] Call Compile PreprocessFile (corepath + "Common\Config\Config_Squads.sqf");

2) Using Corepatch, not configuring squads:

In Init_Common.sqf run this:

[] Call Compile PreprocessFile ("Common\Config\Config_Teams.sqf");[] Call Compile PreprocessFile ("\CorePatch\CorePatch_WF\Scripts\Common\Config\Config_Squads.sqf");

3) Configuring squads (with or without Corepatch):

(You'll be doing this if you want to configure an air squadron, or just want to avoid switching paths when activating or deactivating Corepatch.)

a. Place a copy of WF's Config_Squads.sqf in your mission's "Config" folder.

b. Run this in your Init_Common.sqf:

[] Call Compile PreprocessFile ("Common\Config\Config_Teams.sqf");[] Call Compile PreprocessFile ("Common\Config\Config_Squads.sqf");

I edited the previous post to update.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

looks like it's all working now.

Maybe this is too much but a couple of days ago I also thought it would be cool if the ai also bought fixed wing units, I have already made the airports capturable and the player can buy units from there.

I was wondering if this is possible?

Share this post


Link to post
Share on other sites

Not without amending functions involved with reinforcing the teams. The functions only check base structures, which are the factories, within a certain range. Airports aren't included, they're fixed structures separated away from base structures. To my knowledge the only time an airport check is made is when a player is buying units.

I considered it at one point, and set it aside for easier goals after realizing how much was involved. But it remains a goal in my mission as well, to have the AI Air Team leaders purchase fixed-wing once an airport is captured, I just haven't started that part of the scripting yet.

--- Edit --

Though I do have AI fixed wing at one point. One of the "easier goals" (LOL) was adding a fixed wing defense team to the airport defense units, which I did complete. When enemies approach, planes spawn as part of the defense teams. They spawn at the hangars, taxi and take off, then patrol the skies over the airport (until shot down). It took some effort to configure and script, again amending functions, for the defense teams. Pretty pleased with the results though. It worked out well.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

It would be very awesome to actually see an enemy jet flying around.

I just played for a while and everything seems to be working.

Thanks for your help, couldn't have done it without you.

Edit: How do you disable diplomacy btw?

I now have a mission with 3 sides, but when I start the mission as resistance it immediately goes cease fire with bluefor. that's not what I want

nevermind about that, found it.

another edit: I found out that bluefor and resistance(cdf and Napa) are allies without me doing anything.

How can I remove this so that it's just normal 3 vs 3 with no allies?

just forget all of the above, I got it working by setFriend in init_common

Edited by metallicafan33

Share this post


Link to post
Share on other sites

What I did was use the ACM module to simulate air units.  Of course those units aren't under warfare command.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×