Jump to content
Rydygier

Civilian Behavior Controller script

Recommended Posts

Recently had great fun creating something, that can be useful for some, I guess, so here it is, experimental version, as two demo missions:

CBC

What is it?

CBC could be described as ALICE module scripted replacer/enhancer. However - there are some differiencies. CBC is pure sqf, no fsms around. CBC do not spawn anything on map. It takes, what it finds. By default will control all civilians on foot (best if each civilian has own group) present on map at script init, in another mode will control units stored in special array (can be changed on-the-fly). Thanks to that, CBC can prove useful for those, who wants to have better control over civilian ambient in their missions and/or for those, who needs features provided by CBC, that are not present in ALICE.

My impression is, that this thing makes civilian ambient more dense and reacting on situations better, than ALICE's. On the other hand is lacking of kbTell chit chats and some minor ALICE features, as chimney smoke...

CBC has modular structure. Contains two parts, that can be used alone or together: normal pattern of life and danger awareness/panic mob reactions. Using danger awareness will make script much heavier due to fast looping, as code tries to detect some short living things, like explosions, bullets flying by and such. Performance depends on CPU, on mine works fine up to about 100 units.

Firstly code will find around pointed position(s) on map nearest town in 1000 meters radius. In that city will locate all buildings (cluster way), house positions (limited to the ground floor), some positions around each building and ALICE doors if present. For each controlled unit will assign persistent "home" location choosing from interiors of enterable buildings and ALICE doors (can be used with Alice, where Alice is eg set up that way, so will spawn it's special doors even far from player, but will not spawn any own units) and by default will move unit there initially. Next will assign to each unit several "places of interest". Unit will constantly travel between home and these points in random manner with some time spent at each point. There are possible also some dynamic interactions between civilians, as conversations (no kbTell however, so silent). Tendency of staying home depends on weather (rain) and daytime. If it is raining pedestrians will have bigger tendency to run instead to walk. The bigger rainfall, the bigger chance, that civilian will look for nearest interior to wait out rain there.

Danger awareness/panic behavior enhances normal pattern with reaction on seen/heard stimuli like bodies, wounded, explosions, vehicle destruction effects, particle sources, custom "panic sources" (eg player can be made very fearsome person easy way, same for any object, visible or not), shooters, ammo hits, ammo flying by... Each civilian is characterised by set of variables, assigned with gaussian-like randomized values (average most probable), one per stimuli, that determines sensitivity for given kind of stress source. One will easily go panic because of seen blood, another will affraid mostly explosions etc. If stress level will grow too high, and calm test will be failed, unit become "panicked". Will shout (are used ALICE shouts) and run far away until calm down again. Aside of described stress sources impact on that have also another panickers and runners nearby, so is possible classic mob panic chain reaction. On the other hand, if given source is visible/audible from big distancies, there is a chance of curiousity reactions - some people will come to see, what is going on.

Demos show, how to use it. Shortly by executing:

RydCBC_CivCenters = [Center1,Center2,...];
[] execVM "CBC\CBC_Init.sqf";

when all CBC's sqf files are in "CBC" subfolder of the mission folder, and rest (init.sqf, Description.ext, sounds folder) in the mission folder. There are also some config init variables, that can be used before execVM to set up some things:

RydCBC_CivCenters - is necessary array, that contains center objects or locations. Around each of it code will look for towns to populate.

RydCBC_Debug - if on, some map markers are displayed: home positions, each civilian with stress value...

RydCBC_PanicSource - array, that contains custom stress sources (any objects). Additionally for each of such objects can be set variable with fear value (default 1). The bigger, the more fearsome object is. Eg:

player setVariable ["RydCBC_FearValue",10000];

and value that determines, if source is audible (no LOS needed to affection, but without LOS lower fear):

player setVariable ["RydCBC_Audible",true]; (false by default)

RydCBC_Apathy - 1 by default. Divisor of stress affection. The bigger value, the lesser chance for panic. Must be positive.

RydCBC_Units - not defined by default. If defined (must be an array) instead of all civilian entities code will control units stored in this array.

RydCBC_PanicReactions - true by default. Activation of danger awareness. (high scheduler load).

RydCBC_BasicPattern - true by default. Activation of normal behavior.

RydCBC_MoveHome - true by default. If false, units at init will be not moved into their houses, instead will walk from its placement location towards home or first point of interest (if normal behavior is active).

RydCBC_Reload - false by default. If set to true at any moment, will switch back to false and all house/spots assigning will be repeated/reseted for all units.

RydCBC_ClusterRadius - 350 by default. Radius in meters in which code should search for new buildings around "cluster" center and each of cluster buildings. The lower value, the faster calculation and more limited areas to populate. Max recommended value is 350.

RydCBC_TownSearchRadius - equal to RydCBC_ClusterRadius. How far from each center code should look for nearest town to clusterize and populate. If set with non-positive value (0 and lower), center itself will be used as town center instead of nearest city location.

I think that's it for now. If someone interested - ask any question, let me know about any encountered issues, improvement ideas, requests and such.

Project was created "by player for players", source scripts you can freely modify, copy, "cannibalize", to use in your projects. It is released under APL-SA license. I'll be grateful for notification about each such usage.

Edited by Rydygier
1.1

Share this post


Link to post
Share on other sites

Hey Rydygier,

This looks pretty danm awesome :)

1 question, can i limit where the AI gets moved to?

if you look at this image: http://i.imgur.com/aeH4Zbu.png - you should see 4 RydCBC_CivCenters-triggers - but in this image: http://i.imgur.com/xGeJPnL.png it looks like the ai is all over the place.

i would love to have them around the areas where i placed the triggers. - i dont mind if they drive/walk between the areas. but keep them around it :)

Thanks for a great script.

Share this post


Link to post
Share on other sites

Ah, yes, I remember, had same effect on Lingor. It is because a way, script is calculating town clusters. It adds new buildings to the town as long, as there are some new buildings in certain radius around any building already added. This radius is adjusted mostly for Chernarus. On Lingor apparently distances between cities (buildings across the map) are so small, script thinks, it is one agglomeration. Now. Where I put this radius (it was long time ago), hmm. Probably found it. To fix your problem you should bouldly open CBC_fnc.sqf in any sqf editor or notepad, then find line 1250 inside RYD_FindAllLifeSpots function. It looks like:

_bld = [_pos,350] call RYD_TownBuildFind;

"350" is that radius, I believe. So, put there smaller value (eg 300) and check then. Descrease it gradually until you get desired effect. I hope this helps. Now just checked. For 150 effect seems to be fine on Lingor. Just be sure to set centers within 150 meters radius around nearest city location.

That's a limitation - some city location (where name is) must be in that radius around placed center, or script will not find any city. You can change that in line 1236:

_nearbyTowns = nearestLocations [_pos, ["NameCityCapital","NameCity","NameVillage"],_radius];

by replacing _radius variable with any suitable number in meters - how far around center script should check for closest town without affecting radius for building city clusters. Eg:

_nearbyTowns = nearestLocations [_pos, ["NameCityCapital","NameCity","NameVillage"],500];

My be also something like:

_nearbyTowns = nearestLocations [_pos, ["NameCityCapital","NameCity","NameVillage"],5 * _radius];

But anyway cluster will be build up starting from city location position, not placed center. If you want very precise locate center of the cluster (eg with low search radius to have very limited area populated - only chosen part of actual city), you may try to delete line 1247:

_pos = position _nearbyTown;

if so, also you may try to change line 1243:

if ((count _nearbyTowns) > 0) then

to the:

if ((count _nearbyTowns) > -1) then

so code will simply igonre, if there was any city location nearby, or not. Then only enterable building in radius around center matters.

Perhaps this will do the trick. Example for radius 30:

xjch.jpg

EDIT: ...or ignore all, I said above, and just download and test new version - Link updated. :) Note two new config variables described in the first post: RydCBC_ClusterRadius and RydCBC_TownSearchRadius. Use them to achieve same effect without any further messing with the code.

Edited by Rydygier

Share this post


Link to post
Share on other sites

I'm definitely going to give this a try. Sounds very promising...

Added after having a look:

So, if I want to use RydCBC_Units, I have to give a name to every Civilian?

Could there be a way to exclude certain Civilians instead?

Edited by DreadPirate
Questions...

Share this post


Link to post
Share on other sites
So, if I want to use RydCBC_Units, I have to give a name to every Civilian?

Not necessarily. There are scripting methods to sift off only part of civilians. Which is proper - depends on certain case.

Could there be a way to exclude certain Civilians instead?

Sure. For instance, if you define this variable that way:

RydCBC_Units = entities "Civilian";

it will do same, as default - will use all civilians on map. Now, eg name units to exclude c1,c2,c3 and instead above use such code:

RydCBC_Units = (entities "Civilian") - [c1,c2,c3];

Voila. All except these three are under control.

Share this post


Link to post
Share on other sites

I could've sworn I tried this yesterday and couldn't get it to work, but it's working now! :) Thank you.

So I can have some civilians standing still (shopkeepers, etc.), some following specific waypoints, some looping animations AND have your free-roaming civilians as well.

I think this will replace ALICE in my future missions. Good stuff...

Share this post


Link to post
Share on other sites

Does a script exist that would adjust AI vision "aggro" during the night vs. the day.   I get that A3 is a standard now, but we are on a Dayz server that has a heavy pop AI to make it interesting and would like to balance out day and night.,

Share this post


Link to post
Share on other sites

Any chance you will update this to a3, i use it in a3 as it is now, but im not shure it works as it should.

 

  • Like 1

Share this post


Link to post
Share on other sites

If there's interest, then who knows. Maybe someday I'll revisit this piece of code. For sure I did some tests with early A3 versions, but don't remember/know, if it needs some more work t work on 100% in A3 as for today. I didn't thought about CBC long time, considering it rarther closed chapter. 

 

In the dark corners of my HDD I found some A3 test of CBC from 2013, scenario, that includes A2's civilian shouts, but besides that I've no idea, if or what changes I applied to fit it into A3. Here:

 

A3 test

  • Like 1

Share this post


Link to post
Share on other sites

As i said i still use it in my a3 missions, i use it with Phronks civilian fleeing script, and i still think its one the best civlian behaviour script out there :-)

And thank you for the file, i will test it in my next arma session in my group :-)

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

×