Jump to content
Lucky44

How to set factions for the BIS Spawn AI Module??

Recommended Posts

Looking for some help with the BIS Spawn AI Module.

 

I can't find any documentation on how to set the faction beyond the vanilla ones (e.g., AAF, CSAT) or otherwise shape the spawns beyond the basic infantry/vehicle/armor/air options. I'd like to be able to at least set the faction, like to an RHS infantry type. Anyone know how to do this?

Share this post


Link to post
Share on other sites

Thanks, Play3r. I tried using that approach with the SpawnAI modules, but I couldn't get it to work. The problem was with the way the script was called from the module:

 

[_this] execVM "nameOfMyScript.sqf";

 

It threw an error on the _this part, and then the script was this:

 

params ["_unit"]; if !(isServer) exitWith {}; _unitToCopy = selectRandom [c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14]; _unit setUnitLoadout (getUnitLoadout _unitToCopy); lockIdentity _unit; [_unit, (speaker _unitToCopy)] remoteExec ["setSpeaker", 0, true]; [_unit, (face _unitTOCopy) ] remoteExec ["setFace", 0, true];

 

-I have to admit I'm not real clear on this/_this and thisList, etc. And I don't know how the params command works either. (I did set up units for the array to choose from, though. I was able to jimmy it into working via a script on a trigger, but that's not a very efficient way to do it.)

 

Does anyone know how to use the code right with the init box of the SpawnAI module?

 

Share this post


Link to post
Share on other sites

And you did make 15 units to test from?

 

i have just tried your line and it works fine to me.

Share this post


Link to post
Share on other sites

The spawnAI module uses CfgGroups to decide what  to spawn. Dependent on the side and faction chosen it will look under these for Infantry, Motorized, Mechanized and Armored all which contain several defined groups of which it uses to spawn.

The problem with custom addons like RHS is that they do not follow the BI naming conventions. Luckily the scripts for the module use BIS_fnc_loadClass, so it looks for CfgGroups in missionConfigfile, then campaign and finally global config.

So you will need to make up your own groups from RHS assets within the description.ext.

 

description.ext

class CfgGroups {

    class west { //Side, must be one of East, West or Indep for spawnAI module to recognise it

        class myCustomFaction { //Name for your custom faction

            class Infantry {    //SpawnAI module looks for this class

                class myCustomInfGroup {    //Can be called anything, name also used for blacklisting

                    class unit0 {
                        vehicle = "rhsusf_army_ocp_squadleader";    //Class name of unit/vehicle
                        side = 1;                                   //index of unit side being [ east, west, independent, civilian ]
                        rank = "SERGEANT";                          //rank name from CfgRanks
                        position[] = { 0, 0, 0 };                   //offset position unit spawns from spawn point
                    };

                    class unit1 {
                        vehicle = "rhsusf_army_ocp_rifleman";   //Class name of unit/vehicle
                        side = 1;                               //index of unit side being [ east, west, independent, civilian ]
                        rank = "PRIVATE";                       //rank name from CfgRanks
                        position[] = { 5, -5, 0 };              //offset position unit spawns from spawn point
                    };

                    class unit2 {
                        vehicle = "rhsusf_army_ocp_rifleman";   //Class name of unit/vehicle
                        side = 1;                               //index of unit side being [ east, west, independent, civilian ]
                        rank = "PRIVATE";                       //rank name from CfgRanks
                        position[] = { -5, -5, 0 };             //offset position unit spawns from spawn point
                    };

                };
            };

            class Motorized {};     //SpawnAI module looks for this class
            class Mechanized {};    //SpawnAI module looks for this class
            class Armored {};       //SpawnAI module looks for this class
        };
    };
};

SpawnAI Module init

this setVariable[ "side", "West", true ]; //Must be one of East, West or Indep for spawnAI module, Case and spelling are important!!!
this setVariable[ "faction", "myCustomFaction", true ];

TEST_MISSION

 

Create groups as needed for each subclass Infantry, Motorized, Mechanised etc see BI's CfgGroups in config viewer to get an idea of how to set out.

Edited by Larrow
Updated with information from rest of thread
  • Like 4
  • Thanks 6

Share this post


Link to post
Share on other sites
4 hours ago, Play3r said:

And you did make 15 units to test from?

 

i have just tried your line and it works fine to me.

(Yes, I made 15 units to pull loadouts from and named them accordingly.)

 

How did you use it? Did you use it in SpawnAI module? If so, where did you put that line?

 

Thanks

 

 

Share this post


Link to post
Share on other sites

Larrow, 

 

Thanks for your help, again! I will try this out right now and let you know how it goes.

 

I think you may have solved my issue just by the way you used "this" in the init box. But the additional info on using CfgGroups is even more helpful.

Share this post


Link to post
Share on other sites

OK, Great! It's working nicely! 

 

The one thing that's curious is that it won't randomize the units at all. It always spawns the same squad, with the same number of units (although the clothing is randomized within the proper type). It's ignoring the maximum group size specified in the SpawnAI module. Is there an easy way to add some randomness to the group size?

 

EDIT: I did notice that the AI no longer pursue the Sector Control objective that I had them using. This is a change since I switched from AAF units to a custom group of LOP ISTS units - and yes, I have them all still Independents, like the AAF were. What would cause that?

 

AND, now they only spawn at the main SpawnAI module location, not at the other spawnpoints connected to it.

Share this post


Link to post
Share on other sites
On 1/4/2019 at 8:04 AM, Lucky44 said:

BUMP: I did notice that the AI no longer pursue the Sector Control objective that I had them using. This is a change since I switched from AAF units to a custom group of LOP ISTS units - and yes, I have them all still Independents, like the AAF were. What would cause that?

 

AND, now they only spawn at the main SpawnAI module location, not at the other spawnpoints connected to it.

 

Share this post


Link to post
Share on other sites
On 1/4/2019 at 4:04 PM, Lucky44 said:

The one thing that's curious is that it won't randomize the units at all. It always spawns the same squad, with the same number of units

The number of units is never randomised. All groups are spawned with the exact number of units defined in the group, capped at 'maximum group size' set in the spawnAI module.

So if you were to define three groups that have 1, 3, 6 units defined and then set "maximum group size" to 5. All groups have a chance of spawning, except the group of 6 units will be capped at 5 when spawned.

If you wish to have different size groups spawning you need to define a bunch of groups with different unit amounts.

 

On 1/4/2019 at 4:04 PM, Lucky44 said:

AND, now they only spawn at the main SpawnAI module location, not at the other spawnpoints connected to it.

Are you sure you have also set the variables (side and faction) on SpawnAI point modules? They need to match.

 

On 1/4/2019 at 4:04 PM, Lucky44 said:

I did notice that the AI no longer pursue the Sector Control objective that I had them using.

Likely due to the group spawning as civilians. You have to make sure the side variable you set on the spawnAI/spawnPoint modules follow one of the following...

  • "West"
  • "East"
  • "Indep"

Capitalisation is important. If they do not match then the group will be spawned as civilians.

 

TEST_MISSION

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

You are the best, Larrow. Thanks for your help, again.

 

I'll take a look at this right now.

Share this post


Link to post
Share on other sites

OK, good news and bad news. 

 

SpawnAI "Randomizing" units within a custom group: working. -By that I mean, by adding multiple groups into the description.ext CfgGroups, I get a randomized choice from the groups listed. So, effectively, that works fine. What I meant originally (and hoped for) was just listing, say, 10 units in a custom group and having the SpawnAI module pick each one from the group randomly. That works with the default/BIS units, but not once you start using custom groups, I guess. Not a big deal. -Thanks.

 

Spawning at multiple locations: works fine. I didn't realize I had to add the custom Side and Faction info into those like I do for the SpawnAI module. -Thanks.

 

The bad news is that I can't get my custom groups to pursue the Sector Control. I see it working fine in your demo mission. I just can't get it to work with my LOP ISTS units/groups. Here's a demo mission I've made showing how the units just spawn and stand there, ignoring the Sector Control. Of course, you need the LOP ISTS mod to see those units (from Project OpFor, https://steamcommunity.com/sharedfiles/filedetails/?id=735566597).

 

I would guess that using any 3rd-party mod units would have the same issue.

 

And I am betting that there's a simple fix, but I can't figure it out!

Edited by Lucky44
fixed wrong link

Share this post


Link to post
Share on other sites

Share your mission. Your link above a demon mission just takes me to a screenshot.

Share this post


Link to post
Share on other sites
4 hours ago, Lucky44 said:

What I meant originally (and hoped for) was just listing, say, 10 units in a custom group and having the SpawnAI module pick each one from the group randomly. That works with the default/BIS units,

No it does not. Set up a default spawnAI using BLUFOR and NATO for Side and Faction, set 'max group size' to 1 and add...

params[ "_grp", "_module", "_grpData" ];
_grpData params[ "_grpCfg", "", "", "", "_units" ];
hint format[ "%1 units from Infantry %2 where spawned\nGrp Units are %3\nData Units are %4",
	count units _grp,
	configName _grpCfg,
	units _grp apply{ typeOf _x },
	_units
];
{
	_unitType = typeOf _x;
	_unitCfgType = getText( _grpCfg >> format[ "unit%1", _forEachIndex ] >> "vehicle" );
	systemChat format[ "Unit %1 isEqualto Cfg Unit%2 %3 : %4",
		_unitType,
		_forEachIndex,
		_unitCfgType,
		_unitType == _unitCfgType
	];
}forEach units _grp;

...to the modules expression field. Every time a unit is spawned it will tell you whether its type matches the corresponding type from the CfgGroups (systemChat). It will always be true. It is not a random unit from the group. If just one spawns then it will always be unit0 from the config. If you increase 'Max group size' it will always be unit0, unit1, unit2 ....etc from the CfgGroup upto unit 'Max group size'.

For instance taking BI's vanilla Infantry groups for BLUFOR NATO..

configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "B_InfTeam_Light" >> "Unit0" >> "vehicle" == "B_soldier_TL_F";

configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfAssault" >> "Unit0" >> "vehicle" == "B_Soldier_SL_F";

configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfSentry" >> "Unit0" >> "vehicle" == "B_soldier_GL_F";

                                                    ^^Side      ^^Faction                          ^^Different groups     ^^First unit                   ^^Different unit class

etc

Setting BLUFOR and NATO is not picking just one group from CfgGroups. Every spawn it will pick a random group under the Sides Factions Infantry.

So every time one of these groups is spawned the unit will be different as unit0 of the groups config is of a different class type.

 

Now if you only want one unit to spawn at a time, and that unit to be random every time. There are two ways to go about it.

1. Create multiple custom groups under the Side and Faction that consist of one unit, that unit being of a different type in each group ("B_soldier_F" or "B_soldier_TL_F" etc).

2. Create one custom group that consist of one unit, and use the modules expression field to changes his loadout. (granted not actually a different type, but made to look different). Module expression field...

params[ "_grp" ];
{
	_randomUnitLoadoutClass = selectRandom[ "B_soldier_F", "B_soldier_TL_F", "B_soldier_GL_F" ];
	[ _x, _randomUnitLoadoutClass ] call BIS_fnc_loadInventory;
	hint format[ "Spawned %1 dressing up as %2", typeOf _x, _randomUnitLoadoutClass ];
}forEach units _grp;

Doing it this way you may not even need to create your own custom groups. Just make sure the spawnAI module is creating vanilla units from the correct Side and Faction and then dress them up as your addons units classes.

  • Thanks 2

Share this post


Link to post
Share on other sites

I see what you mean. I apologize for not being clearer.


Here's what I meant: when you use just the default settings for the Spawn AI module, it picks from ALL the BIS units for that side and faction. So for NATO, for instance, it can pick from 13 at least different groups, ranging from 2-man teams to 9-man squads (and that's not including Support Infantry groups, etc.). So it seemed like the group SIZE was randomized. But it's not, and I see that now.

Share this post


Link to post
Share on other sites
On 1/8/2019 at 5:04 AM, Lucky44 said:

The bad news is that I can't get my custom groups to pursue the Sector Control.

You have both the side in the CfgGroups and the setVariable set incorrectly, so you units are spawning as civilians.

On 1/7/2019 at 7:18 AM, Larrow said:

You have to make sure the side variable you set on the spawnAI/spawnPoint modules follow one of the following...

  • "West"
  • "East"
  • "Indep"

Capitalisation is important.

This is also true for the CfgGroups side class name (Capitalisation does not matter in the config, only for the setVariable ).

 

Spoiler

class CfgGroups {

    class Indep { //Side

        class IS1 { //Name for your custom faction

         //Snip  
          
        };
    };
};

Module Init


this setVariable[ "side", "Indep" ];  
this setVariable[ "faction", "IS1" ];

Although you shouldn't really need to set the side variable, as you can just use the setting on the module. So you can just get away with using the init to set your custom faction.

 

  • Like 1

Share this post


Link to post
Share on other sites

Wow, it was that simple. Thanks!

 

I was doing that wrong because I didn't realize you had meant that it should be abbreviated like that. That's kind of crazy - why would it not work to write INDEPENDENT in those places? Oh well.

 

Thanks for getting this all solved. I hope this thread can be useful for others too.

Share this post


Link to post
Share on other sites
8 hours ago, Lucky44 said:

That's kind of crazy - why would it not work to write INDEPENDENT in those places?

As there is a switch statement in one of the spawnAI scripts that particularly looks for the abbreviations as per my post. As a switch statement on strings is case sensitive, hence the need to make sure the case is correct on the setVariable.

  • Like 1

Share this post


Link to post
Share on other sites

OK, one more question on the SpawnAI module: while everything I'm trying to do is now working right locally, on a dedicated server, no units spawn. Any ideas why that would be?

 

I went to https://community.bistudio.com/wiki/BIS_fnc_moduleSpawnAI, but it was useless.

 

Here's a demo mission that I tested on a dedicated server.

Share this post


Link to post
Share on other sites

Make sure the variables are set globally for multiplayer.

this setVariable[ "side", "Indep", true ]; 
this setVariable[ "faction", "IS1", true ];

 

Share this post


Link to post
Share on other sites

AWESOME!

 

Thanks so much.

 

And by the way, how did you know that? -I ask so that I can try to look it up myself and not have to ask you!

Share this post


Link to post
Share on other sites
2 hours ago, Lucky44 said:

how did you know that?

 

TBH I have no idea why it works.

The module is flagged as server execution only in the config, and as far down as I have read into the modules functions, maybe 75% of it, I see no reason as to why it would be needed. Also if your setting the variables in the modules init surely every client already has the variables anyway?

Yet when I checked how the variables where being saved by the editor in the mission sqm they are PVed. So I tried it out and it worked :shrug:

  • Like 2

Share this post


Link to post
Share on other sites
On 1/4/2019 at 5:10 AM, Larrow said:

The spawnAI module uses CfgGroups to decide what  to spawn. Dependent on the side and faction chosen it will look under these for Infantry, Motorized, Mechanized and Armored all which contain several defined groups of which it uses to spawn.

The problem with custom addons like RHS is that they do not follow the BI naming conventions. Luckily the scripts for the module use BIS_fnc_loadClass, so it looks for CfgGroups in missionConfigfile, then campaign and finally global config.

So you will need to make up your own groups from RHS assets within the description.ext.

 

description.ext


class CfgGroups {

    class west { //Side, must be one of East, West or Indep for spawnAI module to recognise it

        class myCustomFaction { //Name for your custom faction

            class Infantry {    //SpawnAI module looks for this class

                class myCustomInfGroup {    //Can be called anything, name also used for blacklisting

                    class unit0 {
                        vehicle = "rhsusf_army_ocp_squadleader";    //Class name of unit/vehicle
                        side = 1;                                   //index of unit side being [ east, west, independent, civilian ]
                        rank = "SERGEANT";                          //rank name from CfgRanks
                        position[] = { 0, 0, 0 };                   //offset position unit spawns from spawn point
                    };

                    class unit1 {
                        vehicle = "rhsusf_army_ocp_rifleman";   //Class name of unit/vehicle
                        side = 1;                               //index of unit side being [ east, west, independent, civilian ]
                        rank = "PRIVATE";                       //rank name from CfgRanks
                        position[] = { 5, -5, 0 };              //offset position unit spawns from spawn point
                    };

                    class unit2 {
                        vehicle = "rhsusf_army_ocp_rifleman";   //Class name of unit/vehicle
                        side = 1;                               //index of unit side being [ east, west, independent, civilian ]
                        rank = "PRIVATE";                       //rank name from CfgRanks
                        position[] = { -5, -5, 0 };             //offset position unit spawns from spawn point
                    };

                };
            };

            class Motorized {};     //SpawnAI module looks for this class
            class Mechanized {};    //SpawnAI module looks for this class
            class Armored {};       //SpawnAI module looks for this class
        };
    };
};

SpawnAI Module init


this setVariable[ "side", "West", true ]; //Must be one of East, West or Indep for spawnAI module, Case and spelling are important!!!
this setVariable[ "faction", "myCustomFaction", true ];

TEST_MISSION

 

Create groups as needed for each subclass Infantry, Motorized, Mechanised etc see BI's CfgGroups in config viewer to get an idea of how to set out.

 

Following your instructions, I was able to get this working with infantry on both sides; however, I'm seriously struggling with mechanized and armor.

 

How do I do this the entries in "Class Motorized {}:" , "Class Mechanized {};" , and "Class Armored {};"  ???

 

I tried the same format as infantry with unit0 being the tank itself, but none of it is working.

 

Thanks for all the help, I really benefited from all of this, so did the guys I play with.

 

 

Share this post


Link to post
Share on other sites
4 hours ago, DirtyDel said:

I tried the same format


Share your code.

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

×