Jump to content
Nixx57

[Release] Generic Ambient Combat (first script)

Recommended Posts

Hi all

 

I just wrote a "Generic" ambient combat script.

This is my first script, and is open to the contribution. (maybe I'll create a git repository for it if it's necessary)

 

I can also post a demo mission if you wish so.

 

Why "Generic" ? :

Because it generates vanilla units but also those of your installed mods.

And it works on any mission (in theory).

 

Introduction :

This script can randomly generate any groups of any type (armoured, air, naval, infantry etc...) in an area around the players (like AmbientCombat module in A2) and create waypoints in an area of 500 meters around the players.

For performance reasons, it is possible to limit the maximum number of groups easily.

 

In short, this script is ideal for sandbox missions or test vehicles/weapons/mods elsewhere than in the virtual garage

And, it work in SP and MP missions.

 

How it work ? :

- The script chosen randomly (without distinction) in the CfgGroups which group to generate.
- If a "naval" type vehicle (submarine or boat) is in a group, the group spawn in the water.

 

Others Random Features :

Groups and units have :

- Random skill (from 0 to 1, for each units in a group);

- Random behaviour ("SAFE", "AWARE", "COMBAT", "STEALTH");

- Random formation

- Yes, i love random 😁

 

Configurable settings:

- Maximum group spawning distance

- Maximum radius of waypoints around players

- Maximum number of groups

- Which sides would you like to spawn (BLUFOR, OPFOR, INDEPENDENT)

- Interval between spawning

- Show the number of active groups (in a "hint")

- Disable groups that contain vehicles

- Limit the size of groups

- Use only specific groups (Only these groups will spawn)

 

This is my first script, please bear with me 😅

 

Known Issues :

- If the players are too far away from each other, some units may disappear.
Possible solutions:

1) Create an instance of the script for each players, but may affect performance (lots of units).

2) Check to see if a player is within the radius of a group, but can prevent the spawning of a group near a distant player.

 

Screenshot of spawn repartition (with default values)

Capture-d-cran-2020-11-20-010835.png

 

Credits : 

Thanks to "DayZ Medic" for base code in his video : 

 

 

EDIT 1: Add _DisableVehicles;

EDIT 2: Add Limit Group Size;

EDIT 3: Allow to use specific groups and waypoints area can be changed

 

Code :

 

Insert in init.sqf

execVM "NixxGenericAC.sqf";
call bis_fnc_music; //if you want to listen cool musics :D (optional of course)

NixxGenericAC.sqf :

//////////////////////////////////////////////////////////////////////////////////////////////////////
//											CONFIG													//
//////////////////////////////////////////////////////////////////////////////////////////////////////

_SpawnAreaAroundPlayers = 2000; //Maximum group spawning distance (default: 2000)

_WaypointsArea = 500;			//Maximum radius of waypoints around players (default: 500)

_GroupsLimit = 12; 				//Maximum number of groups (default: 12)

_SpawnBLUFOR = true;			
_SpawnOPFOR = true;				//Which sides would you like to spawn (default: all true)
_SpawnINDEPENDENT = true;		

_Interval = 30; 				//Interval between spawning (default: 30)

_ShowActiveGroups = true; 		//Show the number of active groups (default: true)

_DisableVehicles = false; 		//Delete groups that contain vehicles (default: false)

_GroupSizeLimited = false;		//Limit the size of groups (default: false)
_GroupSizeMax = 4;				//Maximum size of groups (require _GroupSizeLimited = true)

_UseSpecificGroupBLUFOR = false;				
_UseSpecificGroupOPFOR = false;				//Use only specific groups (Only these groups will spawn)
_UseSpecificGroupINDEPENDENT = false;

_SpecificGroupsBLUFOR = [];
_SpecificGroupsOPFOR = [];					//Only these groups (put CfgGroups) can spawn (require _UseSpecificXXXXXX = true)
_SpecificGroupsINDEPENDENT = [];			

/*
Specific Group Example:
_SpecificGroupsBLUFOR =
[
	(configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfSquad"),
	(configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Mechanized" >> "BUS_MechInfSquad"),
	(configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Armored" >> "BUS_TankPlatoon")
];
*/

//////////////////////////////////////////////////////////////////////////////////////////////////////
//											END CONFIG												//
//////////////////////////////////////////////////////////////////////////////////////////////////////
private _atSpawnedFnc = 
{
	_this setVariable ["isSpawned",true];
 	_this setBehaviour (selectRandom _Behaviour);
 	_this setSpeedMode "NORMAL";
 	_this setCombatMode "RED";
 	_this setFormation (selectRandom _Formations);
	_this deleteGroupWhenEmpty true;
	
	{
		_randomNum = [0,1] call BIS_fnc_randomNum;
		_x setSkill _randomNum;
	} forEach units _this;
};

private _RemoveVehicles =
{
	_IndexArray = [];

	{
		_Group = _x;
		_Index = _ForEachIndex;
		{
			_unit = _x;

			_vehicle = (_unit >> "vehicle") call BIS_fnc_getCfgData;
			_vehicleType = (configFile >> "CfgVehicles" >> _vehicle >> "vehicleClass") call BIS_fnc_getCfgData;
			if (_vehicleType != "Men") then 
			{
				_IndexArray pushBack _Index;
				diag_log format ["Group removed : %1", _this # _Index];
			};
		} forEach ("true" configClasses _x);
	} forEach _this;

	_IndexArrayIntersect = _IndexArray arrayIntersect _IndexArray;
	{
		_this set [_x, configNull];
	} forEach _IndexArrayIntersect;

	_this = _this - [configNull];
	diag_log _this;
};

private _LimitGroupSize =
{
	_IndexArray = [];

	{
		_Group = _x;
		_GroupCount = 0;
		{
			_GroupCount = _GroupCount + 1;
		} forEach ("true" configClasses _Group);
		diag_log format ["Count : %1 Group : %2",str count _Group, _Group];
		_Index = _ForEachIndex;

		if(_GroupCount > _GroupSizeMax) then
		{
			_IndexArray pushBack _Index;
			diag_log format ["Group removed : %1", _this # _Index];
		};
	} forEach _this;

	{
		_this set [_x, configNull];
	} forEach _IndexArray;

	_this = _this - [configNull];
	diag_log _this;
};

_groupsE = [];
if(!_UseSpecificGroupOPFOR) then
{
	{
		_faction = _x;
		{
			_type = _x;
			{
				_groupsE pushBack _x;
			} forEach ("true" configClasses _type);
		} forEach ("true" configClasses _faction);
	} forEach ("true" configClasses (configFile >> "CfgGroups" >> "East"));
}
else
{
	_groupsE = _SpecificGroupsOPFOR;
};

_groupsW = [];
if(!_UseSpecificGroupBLUFOR) then
{
	{
		_faction = _x;
		{
			_type = _x;
			{
				_groupsW pushBack _x;
			} forEach ("true" configClasses _type);
		} forEach ("true" configClasses _faction);
	} forEach ("true" configClasses (configFile >> "CfgGroups" >> "West"));
}
else
{
	_groupsW = _SpecificGroupsBLUFOR;
};

_groupsI = [];
if(!_UseSpecificGroupINDEPENDENT) then
{
	{
		_faction = _x;
		{
			_type = _x;
			{
				_groupsI pushBack _x;
			} forEach ("true" configClasses _type);
		} forEach ("true" configClasses _faction);
	} forEach ("true" configClasses (configFile >> "CfgGroups" >> "Indep"));
}
else
{
	_groupsI = _SpecificGroupsINDEPENDENT;
};

_Behaviour =
[
	"SAFE",
	"AWARE",
	"COMBAT",
	"STEALTH"
];

_Formations =
[
	"COLUMN",
	"STAG COLUMN",
	"WEDGE",
	"ECH LEFT",
	"ECH RIGHT",
	"VEE",
	"LINE",
	"FILE",
	"DIAMOND"
];



_Sides = [];
if(_SpawnBLUFOR) then {_Sides pushBack BLUFOR};
if(_SpawnOPFOR) then {_Sides pushBack OPFOR};
if(_SpawnINDEPENDENT) then {_Sides pushBack INDEPENDENT};

if(_DisableVehicles) then {_GroupsW call _RemoveVehicles; _GroupsE call _RemoveVehicles; _GroupsI call _RemoveVehicles;};
if(_GroupSizeLimited) then {_GroupsW call _LimitGroupSize; _GroupsE call _LimitGroupSize; _GroupsI call _LimitGroupSize;};

_SpawnedGroups = 0;

while {true} do 
{
	if (_SpawnedGroups < _GroupsLimit) then 
	{
		_SelectedSide = selectRandom _Sides;

		_selectedPlayer = selectRandom allPlayers;

		_SpawnPos = [[[position _selectedPlayer, _SpawnAreaAroundPlayers]],["water"]] call BIS_fnc_randomPos;

		_SelectedGroup = nil;
		
		switch(_SelectedSide) do
		{
			case BLUFOR:
			{
				_SelectedGroup = _groupsW select (floor (random (count _groupsW)));
			};
			case OPFOR:
			{
				_SelectedGroup = _groupsE select (floor (random (count _groupsE)));
			};
			case INDEPENDENT:
			{
				_SelectedGroup = _groupsI select (floor (random (count _groupsI)));
			};
			default
			{hint "Error : no side selected"};
		};

		if(!_DisableVehicles) then
		{	
			{
				_vehicle = (_x >> "vehicle") call BIS_fnc_getCfgData;
				_vehicleType = (configFile >> "CfgVehicles" >> _vehicle >> "vehicleClass") call BIS_fnc_getCfgData;
				if (_vehicleType == "Ship" || _vehicleType == "Submarine") then 
				{
					_SpawnPos = [[[position _selectedPlayer, _SpawnAreaAroundPlayers]],["ground"]] call BIS_fnc_randomPos;
				};
			} forEach ("true" configClasses _SelectedGroup);
		};
		_NewGroup = [_SpawnPos, _SelectedSide, _SelectedGroup] call BIS_fnc_spawnGroup;
		_NewGroup call _atSpawnedFnc;
	};

	_SpawnedGroups = 0;
 	{
 		for "_i" from count waypoints _x - 1 to 0 step -1 do  
		{
			deleteWaypoint [_x, _i];
		};

		_selectedPlayer = selectRandom allPlayers;

		_randomPos = [[[position _selectedPlayer, _WaypointsArea]],[]] call BIS_fnc_randomPos;

  		_NewGroupWayPoint = _x addWaypoint [_randomPos, 0];
  		_NewGroupWayPoint setWaypointType "MOVE";
		  
		{
   			if (_selectedPlayer distance _x > _SpawnAreaAroundPlayers) then 
			{
				if(vehicle _x != _x) then
				{
					deleteVehicle objectParent _x;
				};
				deleteVehicle _x;
			};
  		} forEach units _x;

		_SpawnedGroups = _SpawnedGroups + 1;
 	} forEach (allGroups select {_x getVariable "isSpawned" && { alive _x } count units _x > 0});

	if(_ShowActiveGroups) then {hint format ["Active groups = %1", _SpawnedGroups]};

 	sleep _Interval;
};

 

  • Like 7
  • Thanks 2

Share this post


Link to post
Share on other sites

Really not too bad for your 1st script!  Looks like what I did in a former version of my modules.

Just a point: As you spawn some armored/mechanized groups, you will experience  vehicles blowing and bouncing into air, while trying to spawn them in cities with the poor bis_fnc_spawnGroup. I had to script my own functions.

Good work and have fun scripting.

  • Like 1
  • Thanks 1

Share this post


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

Great work!
May i recommend an option to disable vehicles ect.

 

Added !

  • Thanks 1

Share this post


Link to post
Share on other sites

It's a very good script, keep it up!

How can i change size of groups? for example...i would like to spawn 2-4 units in 6 groups.

 

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, dbun30 said:

It's a very good script, keep it up!

How can i change size of groups? for example...i would like to spawn 2-4 units in 6 groups.

 

 

Yes, it's done (it was quick)

 

Finally, this script may have a future 😅

Share this post


Link to post
Share on other sites

This looks great.

 

Check this ai spawner.  Its probably one of the best made during arma 3 peak player numbers.

 

 

If you like to script this guy is definitely someone to learn from.

 

And of course this 

 

 

Enjoy and it looks good.

 

The funny thing about arma scripting is you ways want to add more. 

  • Like 1

Share this post


Link to post
Share on other sites

This script is getting better and better. 😀
These are some of my suggestions, maybe if you have some free time to implement them...

 

Spawn specific units, for example spawn "unit name, unit name, unit name" (true/false)
Spawn units only from specific mod. (true/false)
Spawn boats when player is on water. (true/false)
Spawn air units when player is in the air. (true/false)
Spawn infantry units when player is on ground. (true/false)
Spawn vehicles when player is on ground. (true/false)
Spawn empty vehicles (true/false).
Spawn empty boats (true/false).
Spawn empty air units (true/false).

 

Change size of groups independently for infantry (true/false)
Change size of groups independently for vehicles (true/false)
Change size of groups independently for airplanes (true/false)
Change size of groups independently for boats (true/false)

Random size of groups, example 1-10.
Random amount of groups, example 1-10.

 

Spawn static units such as mortars and turrets. (true/false)
Spawn specific units without patrol path. (true/false)
Spawn infantry units that will automatically occupy nearby buildings. (true/false)
Random amount of units that will occupy nearby buildings, example 1-10.

When enemy units are killed they don't spawn anymore (true/false)
Random amount of chance that the enemy will call artillery towards the player location, example 0%-100%. (true/false)

Random time amount which will maybe activate (by chance amount) hunt for a player.
Means...all units will have paths directed towards player.


Keep up the good work!

Share this post


Link to post
Share on other sites
6 hours ago, dbun30 said:

This script is getting better and better. 😀
These are some of my suggestions, maybe if you have some free time to implement them...

 

Spawn specific units, for example spawn "unit name, unit name, unit name" (true/false)
This script can spawn only the groups from CfgGroups. But it is possible to put specific groups, i'll do that today (It will be quick).

Spawn units only from specific mod. (true/false)

I don't think it's possible to recognize which group belongs to which mod, but you can use the option to implement specific groups (see above).


Spawn boats when player is on water. (true/false)

Currently, boats appear if the player is near the water (or IN the water).


Spawn air units when player is in the air. (true/false)
Spawn infantry units when player is on ground. (true/false)
Spawn vehicles when player is on ground. (true/false)

I don't plan to implement this kind of condition. But there are many other scripts that do it better than me


Spawn empty vehicles (true/false).
Spawn empty boats (true/false).
Spawn empty air units (true/false).

This project aims to simulate a large-scale war, there are scripts that make empty vehicles appear.

 

Change size of groups independently for infantry (true/false)
Change size of groups independently for vehicles (true/false)
Change size of groups independently for airplanes (true/false)
Change size of groups independently for boats (true/false)

Random size of groups, example 1-10.
Random amount of groups, example 1-10.

The groups present in the CfgGroups are of a fixed size, the implemented option to limit the maximum size will remove the groups that have a size greater than the limit, although it is possible to remove units manually, it would take a lot of work, even to filter by type.

 

Spawn static units such as mortars and turrets. (true/false)
Spawn specific units without patrol path. (true/false)
Spawn infantry units that will automatically occupy nearby buildings. (true/false)
Random amount of units that will occupy nearby buildings, example 1-10.

When enemy units are killed they don't spawn anymore (true/false)
Random amount of chance that the enemy will call artillery towards the player location, example 0%-100%. (true/false)

Random time amount which will maybe activate (by chance amount) hunt for a player.
Means...all units will have paths directed towards player.

Other scripts more complex than mine do that very well, I don't want to reinvent the wheel 😅.

But I can implement the waypoints area option to direct them to an area more or less close to the player. I would do that today


Keep up the good work!

Thank you 😁

 

In summary, I want to keep this script as simple as possible to ensure maximum compatibility with other missions/scripts/mods while keeping good performance.

 

Check the jandrews's post, you will find there your happiness.

  • Thanks 1

Share this post


Link to post
Share on other sites

UPDATE :

- Possibility to use specific groups

Maximum radius of waypoints around players can now be set

 

Thank you dbun 🙂

  • Thanks 3

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

×