Smart spawn controller
Mod changes the vanilla algorithm of spawning bots. Allows you to improve the performance of the game without the tedious tuning of bot waves.
Checked on EFT version EFT 0.12.10.12192, 0.12.11.1.13487, 0.12.11.2.13615, 0.12.11.13725 / AKI 1.4.0 - 2.0.0-A8 BLEEDINGEDGE
Features
- Limit the number of alive bots on the map
- Spawn new bots within a certain radius from the player
- Despawn bots when they too far from the player
- Setting the probability of spawn in the available zones and limiting the number of bots in the zone
- Customize the zones available for bosses
- Setting the maximum number of alive bots in the zone (does not apply to bosses and their followers)
- Setting the roles of bots that are being changed (by default, marksman-bots is not affected by the mod)
- Setting parameters separately for each map
- For now mod is using map waves settings, so you need enough scav waves if you plan using despawn mechanism (there is a solution to quick create a lot of scav waves)
The Idea
The vanilla spawn algorithm works according to a predetermined wave config and spawns bots in time, adding a little randomness to the number of bots and the spawn zone for bosses (as far as I understand from the code, the choice of a random spawn zone from several predefined ones is available only to bosses). Plus we have a hard-coded upper bound of 40 live bots and unoptimized code for the bots themselves. Which leads to either empty maps or low performance.
For a long time I had an idea to make the bot manager that uses the player's position on the map and turn off bots that are too far from the player. Unfortunately, the implementation showed that this does not help and the bots either do not turn off or turn on)), and the performance remains the same as before. But the accidentally discovered algorithm for despawning scavs when cultists are spawned in a zone suggested to different idea. This is how the spawn and despawn manager appeared, which takes into account the distance to the player.
A couple of disadvantages that have not yet been fixed (and maybe never at all): bots take a long time to spawn. I did not measure the exact time, but from the moment when the game invokes the spawn method and until the bot appears on the map, it takes about 30 seconds, sometimes more, there is still a load of resources due to which the initial waves become queued. The second disadvantage is that bots that have been despawned are not added back to the spawn queue. It seems to me that if you return them back (when spawning, only the role / difficulty is taken into account, the state of health and equipment will be new), then you can control the number of waves a little better. Teleporting a bot to another zone will most likely not work because the bot is quite tightly tied to the spawn zone, but I have not tried it. A teleport would also solve the problem of long waiting times for spawn.
In general, the spawn algorithm in the radius is ideal for maps like customs, shoreline. On these maps, you can achieve good gameplay without looking for bots by location. Bots will be almost everywhere and distributed according to the configuration. I think you can add woods here if you configure it.
The reserve is a fairly compact map, and since a lot of time passes between the moment the wave begins to spawn and the appearance of bots on the map, it is difficult to adjust the spawn / despawn radius. But you can limit the number of bots in zones (for example, underground levels).
The interchange is also difficult for spawn / despawn as the shopping center itself is located at a long distance from the edges of the map where the player can spawn. This leads to the fact that either bots will appear in a zone with a joint exit, or in random zones throughout the map. the algorithm simply cannot find the nearest zone.
The laboratory and both factories do not use spawn / despawn by default. They are limited by the number of live bots. At the factory, my algorithm is generally useless. there is one zone and a small map. Labs has not been tested, not my map, but it is also not large and multilevel - I don't think that the algorithm will work well, except to use it for distribution into zones.
For debugging, you can use my bot monitor, which shows the distance to each bot and the zone in which it spawned.
Installation
Copy astealz-SmartSpawnController into user/mods folder
Configuration
All settings are contained in the config.json file
Section "game"
- DEBUG - output of debug messages to the log SmartSpawnController.txt and the console in the game. Use only when mod is not working.
- VERBOSE - output of detailed messages to the log SmartSpawnController.txt and the console in the game. Use for configuring.
- ScavWaveRetryInterval (seconds) - if the game cannot spawn a wave of bots (resources are not loaded, the limit of alive bots is exceeded, the zone is occupied by cultists, no spawn points are available), then all or part of the bots of this wave will be queued. This parameter changes the time after which the game will try to spawn this wave of bots again. The default is 3 seconds.
- Maps - setting for each map, _Id maps are used as keys
- MaxBotsAliveOnMap - limit the number of alive bots on the map. By default, the game is hardcoded to 40, the value from globals.json is ignored.
- EnableSpawnControl - enables spawn control
- MaxDistanceToSpawn (meters) - the maximum distance from the player to the zone's center of mass (the middle point among all the spawn points in the zone). The choice of the spawn point remains with the game, so bots can spawn both closer and further than this value.
- ForceChooseNewZone - enable forced change of the spawn zone. It is recommended to turn it on for even spawn. When the parameter is off, the distance to the spawn zone is analyzed first, if the distance is less than MaxDistanceToSpawn - there will be no zone change.
- BotsPerZoneBase - base value of the number of bots in the zone, used to calculate the "weight" of the zone
- ScavRoles and BossRoles - the roles of scavs and bosses for which the spawn zone will change. Marksmans are not supported by the mod, standard bosses and their followers by default are not changed (they are supported, but not tested).
- EnableUnspawn - enable the despawn mechanism when moving away from the player. The calculation is done separately for each bot and, unlike the midpoint in the spawn manager, the actual distance to the bot is used here.
- MaxDistanceToUnspawn (meters) - the maximum distance after which the bot will despawn
- RolesToUnspawn - only these roles will be analyzed and despawned
- Zones - setting map zones
- CanSpawnBoss - boss spawn permission flag (it's not very clear how it works, but the game filters the available zones for bosses by this flag, you can change it)
- SnipeZone - flag of the sniper zone. This is for information only, the change will not affect the game. All sniper zones are excluded from the zones that are available to normal scavs and bosses
- MaxPersonsOnPatrol - the maximum number of alive bots in the zone, does not affect the spawn of the boss and followers. Can be changed (not tested)
- MultiplicativeCoef (float) - zone multiplicative coefficient (see zone selection algorithm)
- AdditiveCoef (int, may be negative) - zone additive coefficient (see zone selection algorithm)
"server" section
JS module parameters:
- Add_IgnoreMaxBots_ToBossWaves - Adds IgnoreMaxBots parameter for all bosses in all locations. This parameter allows you to bypass the MaxBotsAliveOnMap limit for boss spawns, i.e. with a limit of 12, after the spawn of the boss, there will be 12 + boss + followers. For vanilla bosses, it is not particularly needed. Their spawn time is '-1' i.e. at the very beginning of the raid. Very useful for raiders and PMC bosses.
- ChangeWaveCoefs - allows you to change the coefficients of the number of bots in the wave. It is recommended to set WAVE_COEF_MID to 1. The explanation will be below.
- ReplaceLocationsWaves - allows you to replace standard / modified scav waves with simple ones, but in larger quantities. The main idea is to make a lot of waves consisting of 1 bot. Because the maximum number of bots is limited, new ones will queue up and wait for free space. This also allows you to fill the zones more evenly: if you use zones with a random number of bots from 1 to 4, then a situation is possible when in a zone with a low weight and a limit of 2 bots will appear 4 at a time, and in a zone with a high weight there will be 4 waves of 1 bot. This rule does not apply to bosses.
- ScavWaveCount - number of scav waves
- ScavInstaWaveCount - number of scav waves at the start of the location (unfortunately the game does not want to spawn them BEFORE entering the location, so they appear in a minutes)
- ScavDifficultyWeight - setting the difficulty of the scav waves. A simplified version of the weight-based probability. The higher the value, the more likely that difficulty will be selected. Zero - excludes this difficulty from the selection.
Zone selection algorithm
- Among the available zones (for scav - all zones except sniper, for bosses - all zones of scavs with the CanSpawnBoss flag) select those in which the distance to the midpoint falls within the MaxDistanceToSpawn
- The weight of each zone is calculated:
Formula: Round ((Base - Min (Base, BotCount)) * M + A), where
Round - rounding to the nearest integer,
Base - BotsPerZoneBase,
BotCount - the number of spawned bots in the zone, not including bots from the new wave,
M - MultiplicativeCoef,
A - AdditiveCoef.
If weight <= 0, then the zone is bypassed - If for some reason the list of zones is empty, then a random zone will be selected from all available ones and added to the list
- The total weight of all zones is calculated
- In the range [1..Total_weight] a random number is selected
- A zone is selected in the range of which a random number falls
The multiplicative coefficient allows you to increase the weight (probability) of bots spawning in a given zone. The additive coefficient controls the maximum number of bots in the zone.
Examples:
- Base = 4, M = 1, A = 1 => Empty zone weight = 5, zone weight with 4 or more bots = 1
- Base = 4, M = 1, A = 0 => Empty zone weight = 4, zone weight with 4 bots 0 (4 bots limit)
- Base = 4, M = 2, A = 1 => Weight of an empty zone = 9, weight of a zone with 4 or more bots = 1 (the zone is more likely to spawn)
- Base = 4, M = 1, A = -1 => Empty zone weight = 3, zone weight with 3 or more bots = 0 (limit for 3 bots)
- Base = 4, M = 0.5, A = 0 => Empty zone weight = 2, zone weight with 4 more bots = 0 (zone less likely to spawn)
Examples from logs:
For the 5th wave:
[5] [Zones] ZoneRailStrorage [1], ZonePTOR1 [6], ZonePTOR2 [11], ZoneBarrack [16], ZoneBunkerStorage [18], ZoneSubStorage [22], ZoneSubCommand [26] [5] [Selected] 5 @ ZonePTOR1
[5] - wave number (internal total counter for scav, bosses and followers) [Zones] - available zones for this wave and their weight [Selected] - selected random number in the range [1..26] and the zone in the range of which this number falls
For wave 67:
[67] [Zones] ZoneRailStrorage [1], ZonePTOR1 [2], ZonePTOR2 [3], ZoneBarrack [4], ZoneSubCommand [5] [67] [Selected] 1 @ ZoneRailStrorage
since in all zones, the limit of bots for the zone has already been exceeded, there are only zones where "eternal" spawn is possible.
Debug messages
Debugging messages can be enabled both in the config file and through the console (spawner-debug command).
When loading a map, the mod shows the zones wired into the game and their parameters, as well as the changed zones from the mod's configuration. New zones cannot be added. Can be used for configuration, output is in json.
For each wave of bots, messages are displayed about the wave number, the initial zone, zone change, a mark that the wave is put in the waiting queue, or possible errors.
Version history
- 1.0.0 - Initial release
- 1.0.1 - fixed bug when boss with inexistent zone was tried to spawn, server side fixes
- 1.0.2 - fixed broken bots bug