Simple ambient combat scriptby
A simple script for ambient combat generation that you can put in a trigger. You can use any groups, vehicles or units. The default is CUP_RU vs CUP_US vs CUP_I_TK_GUE ambient combat.
Installation / Usage:
Make sure you have CUP installed.
Put the script in a trigger ("on activation" field).
Set condition to true.
Name the player group's variable name "playerGroup".
Tweaking the script
Spawn control variables
_fnc_center: function that returns the object or the position which will be the center of ambient combat. By default it's leader playerGroup. This is convenient for multiplayer.
_fnc_IfTrueStopScript: function that will stop the script if true. For example if you need to stop the script when leader of a playerGroup reaches the trigger (named "ambStopTrigger"), change "false;" to "(leader playerGroup) inArea ambStopTrigger;"
_fnc_IfTrueDontSpawn: function that will prevent any groups from spawning while it returns true.
_maxDistance: maximum distance of spawn.
_minDistance: minimum distance of spawn.
_despawnDistance: alive groups spawned by script will despawn if further, unless a plane is a part of the group.
_sleepTime: time between group generation, in seconds.
_limit: max number of groups generated by script at any given time.
_patrolDistance: size of patrol area for each group.
_deadBodyDespawnDistance: all dead units spawned by script will despawn if further.
_defaultPlaneHeight: default height for spawning planes.
_defaultPlaneSpeed: default speed for planes, in m/s.
_planeDespawnDistance: alive groups spawned by script will despawn if further, even if a plane is a part of the group.
_zeusableSides: array of sides (can be west, east, resistance, civilian) that will show up in Zeus.
_forceZeusForget: for an unknown reason sometimes Zeus shows all sides instead of just _zeusableSides. Change this variable to "true" to force Zeus to ignore un-zeusable units.
_notifyOnScriptStop: notify in chat when script stops working.
_isMccEnabled: if true, will assign all units to move within MCC Zone #1 instead of assigning a default patrol task. Transferring groups to MCC will enable MCC smart task planning for them. If the zone #1 is not created at the time of group spawn, the group will be spawned with no tasks. You can create an MCC zone in editor by adding the "MCC Zones" module to map and sync it to a trigger that covers the zone of interest.
_armoredWeight: chance of armored/motorized/mechanized groups spawning, relative to chance of infantry groups spawning. For example, _armoredWeight=0.1 means that armored groups will be spawned 10 times less likely than infantry.
_airWeight: relative chance of air groups spawning.
_droneWeight: relative chance of drones spawning.
_mortarWeight: relative chance of mortars spawning.
_eastWeight, _westWeight, _guerWeight: ratio of sides spawning.
Unit control variables
The units and groups that will be spawned by the script are described in arrays: _east_infantry, _east_armored, _east_air, _east_drones, _east_mortars, _west_infantry, _west_armored, _west_air, _west_drones, _west_mortars, _guer_infantry, _guer_armored, _guer_air, _guer_drones, _guer_mortars.
Each element of these arrays might be:
a Config entry of one of the two possible categories: CfgVehicles or CfgGroups.
a String representing a CfgVehicles class name.
an array that contains any of the above.
Task control variables
_sleepBeforeStart: sleep before starting the script. Use if your group respawns at the beginning of the mission in order to prevent the tasks being generated around [0,0].
_totalTasks: total amount of tasks that will be consecutively generated by the script. 0 (off) by default.
_tasksWillMissionEnd: if true, script will end the mission after completing all the tasks.
_reconUpdateEvery: how often will task position update. If you have _sleepTime = 20 and _reconUpdateEvery = 3, task position will update every 20*3=60s.
_reconAccuracyPosition: how accurate is task marker position.
_tasksTargetSides: array of sides that will be set up for elimination.
_taskReceivingGroup: side/group/object/array that will receive the tasks.
_taskMinGroups: how many suitable groups should be present before new task will be assigned. By default 2.
All sides are listed in _unitSides as an array of entries that look like this: [side, [side_infantry, side_armored, ...etc]]. All sides should have the same amount of unit arrays. By default the script expects 5 unit arrays: infantry, armored, air, drones, mortars. So if you want a civillian side, you should either populate 5 arrays with something, or use a different copy of the script with different unit arrays.
Also you have to redefine _unitSideWeights: each entry of this array represent a relative weight for a side. _unitSides and _unitSideWeights must be the same size.
Known errors with spawn
If you see "_grp is nil at" in game chat it means that a group did not spawn. The possible reason is that one of the config lines is written with a mistake.
If, however, there's a config description after "at" it is likely that said config description is not a child of CfgGroups or CfgVehicles.
The garbage collecting routine will never despawn vehicles that are empty but not dead.
It might take as long as _sleepTime to register _fnc_IfTrueDontSpawn or _fnc_IfTrueStopScript. You will need a condition that will be true for at least that time. For example, a player might be required to stay inside the trigger for 20 seconds for script to completely stop.
Known errors (features) with tasks
It may take as long as _sleepTime between you killing the group and the script registering it. That could be improved, but for me 20s delay works fine.
Active battlefield might eliminate your targets before you have a chance to reach them, especially if you are surrounded and stuck for some time. Consider this a feature. Wars are messy or something.
Tasks are randomly placed. They may get you travelling back and forth. That is actually a good thing, since it despawns some forces, making room for new situations.
Other stuff about the script
If you redefine _unitSideWeights each iteration of the loop, you can change the power balance of the ambient combat with time. You can script it with relation to distance to the objects or just increment one side weight constantly, making the enemy stronger as time goes.
If you want to have several copies of the script, make sure these copies have different strings for _scriptControlVariable, _reconMarkerName, _taskPrefix.
Vanilla default units.
Currently the script is not being worked on anymore. I'll try to provide support on bugs for a while.
License / Disclaimer:
This script is licensed by Arma APL. Feel free to improve it.
Fully tweakable spawning system. Want to be able to spawn 2 planes, 1 tank and 5 infantry units as one team? No problem - scripts supports custom arrays of units, groups or both.
You don't need to specify Config paths to list units: only a class name (string) is enough.
Added a default Insurgent faction (CUP_I_TK_GUE).
Only sides defined by _zeusableSides will show up in Zeuses. See "Tweaking the Script".
Added two functions that will stop or pause spawning if the condition is true. Refer to "Tweaking the Script" for examples.
Added an option to guide units behavior by MCC instead of default patrolling logic.
Planes! Planes can be spawned and will have a bigger boundary for despawning.
Script is rewritten, bits of code are separated as functions. It became easier to change the center of spawn: change one line, not "search and replace".
Comments! Triggers only support "comment" statements and crash when I try to add // or /* type of comments. Nevertheless, the script is a bit more readable now.
Made it a bit easier to have several copies of the script.
All the relevant info about the script is now at bohemia forums.
Added task generation system.
Script generates random groups and units, despawns them if they are too far, despawns dead bodies.
- BI forums