Jump to content
luckylegs

CPAuto: Civilian Presence Automated

Recommended Posts

Hello all,

 

Just wanted to share a little script I wrote to automate the placement of BI's Civilian Presence modules. The modules are nice and lightweight, but I do not have the time or patience to go around placing them all myself 😅

 

Download with included description.ext:

https://www.dropbox.com/s/x3e2nhqireqgfhf/LEGS_CPAuto.7z?dl=0

 

It's a simple script and could definitely be improved, but maybe this will help someone out who is after something similar.

 

Here's the script - along with a better description - so you can have a quick look:

Spoiler

/*

 

Civilian Presence Automated
by LuckyLegs

 

Released under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
http://creativecommons.org/licenses/by-nc/4.0/

 

This script sets up BI's Civilian Presence modules around the position you specify. It places a waypoint/cover module at every house/building within the radius, and randomly picks some of these buildings to serve as spawn points. Normally, you would have to place each waypoint and spawnpoint manually in the editor, so this saves a lot of time if you're not terribly fussed on how things are set up.

 

The script doesn't offer any features beyond what exists in the BI modules. This suits my purposes just fine, as all I wanted was a bit of window dressing in certain areas of my missions, where civilians were not a core focus of the scenario.

 

Parameters
1: Array, position used for center of zone
2: Scalar, radius of zone (optional, default 100)
3: Scalar, number of civilians to spawn (optional, default 10)
4: Code, code to run on unit spawn - requires curly brackets (optional, default {})
5: Code, code to run on unit deletion - requires curly brackets (optional, default {})

 

Returns the module object of the main civilian presence module. Because  of this:

 

Use call to run the script as a function. Ensure your description.ext defines the necessary class, as in the provided example, or that the script is otherwise somehow compiled.

 

Example usage:
[getMarkerPos "marker_1", 200, 10, {_this setUnitLoadout "C_IDAP_Man_AidWorker_02_F"}] call LEGS_fnc_CPAuto;

 

NB: Parameter 5 is probably completely unnecessary, as this script in its current state will not generate any terminal waypoints. Maybe that code runs when dead civilians are deleted; I'm not sure. The option's there if anyone needs it, anyway 🙂

 

*/

 

private _center = param [0, nil, [[]], 3];
private _radius = param [1, 100, [0]];
private _civCount = param [2, 10, [0]];
private _codeCreate = param [3, {}, []];
private _codeDelete = param [4, {}, []];

 

//show a message on screen if no center is provided
if ((isNil "_center") or {typeName _center != "ARRAY"}) exitWith {cutText ["<br/><br/>LEGS_civPresence.sqf requires a position<br/><br/>e.g. [getMarkerPos ""marker_1""] call LEGS_fnc_CPAuto", "PLAIN", 0, true, true]};

 

//create an array containing houses in the area
private _buildings = nearestObjects [_center, ["house"], _radius];

 

//create a CP "waypoint" at each house (the module actually takes care of exact placement of the waypoint itself, so this just plonks the module on the house's position)
{
    private _mWaypoint = "ModuleCivilianPresenceSafeSpot_F" createUnit [position _x, createGroup sideLogic];
} forEach _buildings;

 

//create spawn points at randomly selected houses up to the given amount
for "_i" from 1 to _civCount do {
    private _building = _buildings call BIS_fnc_selectRandom;
    private _mSpawnpoint = "ModuleCivilianPresenceUnit_F" createUnit [position _building, createGroup sideLogic];
    _buildings = _buildings - [_building];
};

 

//create the core module and set up its variables
private _mPresence = (createGroup sideLogic) createUnit ["ModuleCivilianPresence_F", _center, [], 0, "NONE"];
_mPresence setVariable ['BIS_fnc_initModules_disableAutoActivation', false];
_mPresence setVariable ["#area", [_center, _radius, _radius, 0, false, -1]];
_mPresence setVariable ["#onCreated", _codeCreate];
_mPresence setVariable ["#onDeleted", _codeDelete];
_mPresence setVariable ["#unitCount", _civCount];
_mPresence setVariable ["#usePanicMode", true];
_mPresence setVariable ["#useagents", true];
_mPresence setVariable ["#debug", false];

 

//return the core module for reference in other scripts, if needed
_mPresence

 

/*

 

Possible improvements:

- Use only buildings with valid buildingPos. Currently I am just including everything of type "house". No idea how Civilian Presence works on non-vanilla maps.
- Include support for terminal waypoints. I only realised as I was writing this potential to-do list that nearestObjects actually orders its array by proximity, which is awesome and would greatly simplify implementing this. You could just pick a few random buildings towards the end of the array or something.
- Actually test that an ON/OFF trigger will work with this. Theoretically this should work fine, as I am returning the module, but similar to the terminal waypoints it just didn't seem worth my time to try out just yet.
- There's probably a better way to do the error message I made near the start.

 

*/

 

This is my first public release of anything, so, feedback and constructive criticism welcome 🙂

 

P.S. Thanks to the folks in this thread for good examples on how to set up the modules via script.

 

  • Thanks 2

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

×