Arma 3
A.E.S (Ambient Enemy Spawner)
 This topic has been pinned, so it's probably important
Lothebwyn  [developer] 28 Oct, 2020 @ 1:41am
A detailed explanation of what it does
Initialisation
When placed and the mission is started the module grabs the values inputted and options selected on the module menu. Firstly it checks if a trigger is synced and displays system chat messages if none is found. Then it checks that the values inputted are compatible so that units can spawn effectively without a impeded experience. System chat messages are then displayed and the values are changed if they are zero or less, or below the minimum stated in the tooltip. Then it checks if the faction selected in the menu returns a value (if the correct mod is installed), and if nothing is returned selects the CfgGroups config path for the CSAT infantry groups and displays a system chat message warning all users that the faction mod wasn't found. If a custom CfgGroups config path is inputted checks will be done to make sure it is a valid config path. Then if multiple faction groups are detected (most likely due to different camo patterns) 1 will be selected at random and the groups from that used, also a message on mission initialisation will be displayed telling you which random faction was selected. If at any point when if the config path entered is incorrect and no groups were found a message will be displayed and the faction will default back to whatever was selected in the faction drop down list.

Finally a custom chat message will be displayed confirming that the module has initialised.

Unit Spawn Position
Infantry Spawn Position
After initialisation the module will then get a safe position around the each player, excluding the safe areas defined by synced triggers and around each players safe area. From this position a check is done to make sure no enemies are already spawned in close to that position. If enemies are found then a new position is created until a safe one is found or until the max tries is reached.

Vehicle Spawn Position
For getting the vehicles spawn position the selected position from the above explanation is used to search for any roads nearby. The returned nearby road position is then used for the vehicle spawn.

Spawning Units
Enemy Count Check
After the spawn position is calculated a quick check where all east units within each players spawn radius are counted and compared to the max enemies option selected in the module menu. If the enemy count is greater than the max selected this spawning phase is skipped.

Spawning Phase
Inside the spawning phase 1 group and possibly 1 vehicle is spawned. There are multiple chances where either a hunter team, transport vehicle or tank can be spawned alongside a group. All groups spawned are assigned a variable so they can be identified for deletion when they go outside the spawn radius. Between each spawning phase there is a random delay provided by the inputted value in the module menu.

Hunter team
On the rare occasion a hunter team is spawned a 4 man team is selected from a base game faction (depending on whic module is placed) and then given an aggressive move waypoint to the position of any player. Every few seconds this waypoint is updated to the position of the player so you can't escape them. If you are the same side as the hunter team they will simply follow you around and help you take out any enemies you run into.

Regular Infantry Group
If a hunter team isn't spawned then a regular infantry group will be. These groups are randomly selected from CfgGroups which is defined from the selected faction in the module menu. When a group is spawned there is a chance that if they are in a building they will sit and guard it. If they don't spawn in a building or don't get the chance to guard, the group will be sent on a random patrol around their local area.

Tanks
After either a hunter team or infantry group is spawned there is a 2 chance path that could lead to a tank being spawned. The first chance is for a vehicle to spawn and the second is for a tank. The chance for a tank to spawn is put above the transport vehicle spawn in the code. When a tank is spawned a road position is found and then used to spawn it in. A tank is randomly chosen from CfgVehicles where the vehicle faction is equal to the selected faction, spawned and then crewed. A check is done to make sure the tank didn't spawn inside an object and explode or isn't able to move. If either it is destroyed or unable to move the tank and its crew are deleted. The now safely spawned tank is given a route along its nearby roads to patrol.

Transport Vehicles
Much like how tanks are spawned a near road is selected and on that position a randomly selected vehicle is chosen from CfgVehicles where the vehicle faction is equal to the selected faction, spawned and crewed. Unlike the tank spawning, the crew is selected from the faction that was selected in the module menu. This is because with RHS if I were to crew a vehicle using the 'createCrew' function it could create units there were of different camos or factions to the one selected. (Because instead of getting the vehicles from a config path I define them myself). Much like the tank spawning, a check is done to make sure it spawner correctly and then it is given a patrol path along its nearby roads.

Deleting Units
For improved performance over time a check is constantly being done to detect any units that exit the spawn radius and delete them. This is so that the whole map doesn't become over populated with units wondering around and cause a performance decrease. This is done by detecting all the units of faction east on the map and adding them to an array. Then all units of faction east inside the spawn radius of each player and adding them to another array. A comparison is then carried out of the 2 arrays and all units inside. All the units found inside the spawn radius are subtracted from the first array which creates an array of units that are only outside the spawn radius of each player. A check is done on these units outside to make sure they were spawned using this module and then deleted if they have been.
Last edited by Lothebwyn; 8 Nov, 2020 @ 11:06am