Jump to content
Sign in to follow this  
laxemann

L_Civs - Dynamic AI traffic ...MP compatible and customizable!

Recommended Posts

L_Civs
Dynamic and MP-compatible ai traffic


Hey folks,

I was home sick today and wheeehey, actually had some time to do some scripting for a mission I'm planning to do. :)

What does L_Civs do?
It dynamically spawns and deletes AI driving around. Yup. That's it.
It comes with just an initServer.sqf and a folder including three .sqfs.

Here's a small showcase:




How do I use it?
Beginners:
Drop the content of the archive into your mission folder. That's all!

Advanced users:
Currently you've got a few parameters to control:
• You can determine which civilians are spawned via the "classes.sqf"
• You can determine which cars are spawned, also via the "classes.sqf"
• There are three parameters in the initServer.sqf: The maximum amount of civilians driving around at the same time, the minimum spawn distance and the maximum distance to the players before it gets deleted again.
• You can blacklist areas with markers, just check the "blacklist.sqf" - it's pretty much self-explaining.

The standard values are
[78, 1500, 2400] spawn L_fnc_spawnCivs;


Meaning there will be 78 civilian vehicles spawned over the time.
The minimum distance to any player has to be at least 1500m.
The maximum distance to any player before it gets deleted is 2400m.


Download
Download (v1.20)

or

news_download_a3_3.png
L_Civs v1.20




Changelog


1.20

Fixed: Sudden stopping of spawning. This was caused by accidentally not deleting all groups. (A3 has a group limit of 145)
The script now uses allPlayers instead of constantly updating an array
Removed CBA_fnc_randPos, the script now uses a more lightweight, self-written routine. Cars should spawn _much_ faster now
Completely reworked script structure

1.15

Added: Debug options (L_civs_debug = 1, 2 or 3);
Fixed: Cars won't automatically despawn if their owner dies and players are nearby
Fixed: Cars and civilians will only despawn if no players are nearby
Fixed: Never ending loop in a function
Fixed: There should be no cars that are just standing around anymore
Fixed: Improved the waypoint search routine
Fixed: Civilians sometimes wouldn't spawn after all players were within blacklisted markers
Fixed: Some slight code and performance improvements
Fixed: Road detection
Fixed: Built in some safety mechanisms, never ending (unwanted) loops should be gone forever


1.1

Added: Blacklisting via markers. Blacklisted markers simply have to be entered into the "blacklist.sqf" (example included)


1.0

Initial release




Requirements
CBA A3


Credits
ARJay for showing us how to get a road direction!
BI for ArmA
The moderators that keep the community goin'!

Edited by laxemann
  • Like 2

Share this post


Link to post
Share on other sites

I knew it was going to be something good when I saw your name ;).

[b][size=4][color=#000080]L_[/color][/size][/b] == _quality

officially returns true for me.

EDIT: Curious to see what this + VCOM Driving will do. Benchmarking time!

EDIT2: Also if you're dumbing down AI to save performance, whould setting driving AI's behavior to "Careless" help? From my experience they don't react to any near combat anyway.

Edited by 654wak654

Share this post


Link to post
Share on other sites

I'll definitely try this out on my dedicated server.

I stopped using COS for driving vehicles because they'd either instantly explode upon spawning or would drive into the first nearby obstacle and pop their tires. Does this suffer from terrible driver AI less, or about the same? Might try with VCOM AI Driving mod, actually, to see if it helps.

Share this post


Link to post
Share on other sites
I'll definitely try this out on my dedicated server.

I stopped using COS for driving vehicles because they'd either instantly explode upon spawning or would drive into the first nearby obstacle and pop their tires. Does this suffer from terrible driver AI less, or about the same? Might try with VCOM AI Driving mod, actually, to see if it helps.

Should say this, VCOM AI has a small problem which caused me to get rid of it in my singleplayer mod set. AI won't go through bargates :p. At least until the next update...

Share this post


Link to post
Share on other sites

Yeah, just realized they drive around the bargates or crash into the concrete barriers on both sides of the road I placed along the pathway to the bargate. Would be nice to blacklist areas so they don't try to create waypoints into areas, such as bases, that may be fortified and block their routes. Aside from that, the traffic looks pretty nice. May use this for my Altis Insurgency mission for now.

Share this post


Link to post
Share on other sites

I unfortunately can't change the AI's driving behaviour. :/

The AI simply gets a waypoint on a road ~4km away, drives to it on it's own, gets another one (they usually despawn before reaching the first waypoint, though)... and so on.

As for the blacklisting: Good point, I'll look into it.

And thanks for the kind words!

Oh, regarding performance:

The script itself performed really well, having 80 civilians driving around at the same time might drop your frames though for obvious reasons :D

Keep that in mind if you want to use it in a mission that already is AI/performance heavy. :)

Sooo, my next to-dos:

• Blacklisting

• "Player oriented" mode. In this mode the waypoints should always be placed near players so that you'll run into traffic more often.

I did the initial version for a mission which requires to have the streets full of cars, this looks more natural but it might happen that you won't see any cars for a while in MP.

This is caused by the fact that the amount of cars gets splitted by the amount of players.

Share this post


Link to post
Share on other sites
Guest

Release frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means soon you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites
Hey! Nice script! Is it in your plan to add civilians on foot also?

Hmm, not really since doing so is possible with the exisiting modules fairly easilly :o

Also...

UPDATE

Download (v1.1)

Changelog:

1.1 - Added: Blacklisting via markers. Blacklisted markers simply have to be entered into the "blacklist.sqf" (example included)

I'd also like to point out a feature that comes along with blacklisting:

The script checks every 15 seconds if all players are within blacklisted marker areas.

If this is the case, the overall script will slow down and make it's checks every 7 seconds instead of every second, which increases performance.

This will be helpful if you have large blacklist areas since it prevents the script from trying to find positions all the time. :)

And here's a little showcase:

Edited by LAxemann

Share this post


Link to post
Share on other sites

Great. Can you do something like this, but with people, not vehicles?

Share this post


Link to post
Share on other sites
Guest

New version frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means soon you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites

How can I modify this so it just puts empty vehicles around the place (or along roads)?

Id just like the vehicles without the civilians :)

Also will it work in SP/Editor Preview?

Update: Tested in Editor. Works fine. Fun watching them drive around and avoid collisions or collide with things :)

Would be cool to have enemy forces driving around like this also.

Also, if the driver dies the vehicle disappears. I understand the deletion if too far, but i dont think its good to have the vehicle despawn on driver death.

Update: I've modified it so OPFOR units and vehicles spawn, and also killing the driver doesnt despawn the vehicle. But Im getting a strange bug where sometimes Empty copies of OPFOR units will occur, and also OPFOR units shooting at other OPFOR.

Heres the modified sections:

// Spawn the civilian
L_fnc_civSpawn =
{
private ["_spawnPos","_type","_grp","_civ"];
_spawnPos 	= _this select 0;
_type 		= L_civs_civClasses call BIS_fnc_selectRandom;
_grp 		= createGroup civilian;
_civ 		= _grp createUnit [_type, _spawnPos,[],0,""];				
_civ setSkill 50;							// Set skill to 0, saves performance :)
L_civs_currentCivs = L_civs_currentCivs + 1;
[_civ] joinSilent grpNull;
deleteGroup _grp;
_civ;
};


// Spawn a car
L_fnc_carSpawn =
{
private ["_spawnPos","_roadList","_connects","_connected","_type","_dir"];
_spawnPos 	= _this select 0;
_type 		= L_civs_carClasses call BIS_fnc_selectRandom;
_car 		= _type createVehicle _spawnPos;
_roadList 	= _spawnPos nearRoads 10;
_dir = (getDir _car);
if (count _roadlist >= 3) then
{
	_connects	= roadsConnectedTo (_roadList select 0);
	_connected 	= _connects select 0;
	_dir 		= [(_roadList select 0), _connected] call BIS_fnc_DirTo;
};

_car setDir _dir;
_car;
};


// Dynamically deletes the vehicles and civilians
L_fnc_civCheck =
{
private ["_civ","_car","_tooFar","_unit","_grp"];
_civ	= _this select 0;
_car	= _this select 1;
_grp	= group _civ;
_tooFar	= false;
while {!(_tooFar)} do
{
	_tooFar = true;
	sleep 7;
	{
		_unit = _x;
		if ((_civ distance _unit) <= L_civs_maxDist) exitWith
		{
			_tooFar = false;
		};
		sleep 0.002;	
	} foreach L_players;
};
{if (alive _x) then {deleteVehicle _x}} foreach [_civ, _car];
L_civs_currentCivs = L_civs_currentCivs - 1;
};

Also the modified classes.sqf to spawn OPFOR

// Unitclasses that will be spawned
L_civs_civClasses  	=
["O_Soldier_lite_F",
"O_medic_F",
"O_soldier_repair_F",
"O_Soldier_A_F",
"O_Soldier_AT_F",
"O_Soldier_AA_F"
];


// Vehicle classes that will be spawned
L_civs_carClasses 	=
[
"O_MRAP_02_F",
"O_MRAP_02_hmg_F",
"O_MRAP_02_gmg_F",
"O_G_Offroad_01_F",
"O_G_Offroad_01_armed_F",
"O_Quadbike_01_F",
"O_Truck_02_covered_F",
"O_Truck_03_repair_F",
"O_Truck_03_ammo_F",
"O_Truck_03_fuel_F",
"O_Truck_03_medical_F",
"O_Truck_02_box_F",
"O_Truck_02_medical_F",
"O_Truck_02_Ammo_F",
"O_Truck_02_fuel_F",
"O_APC_Wheeled_02_rcws_F",
"O_soldier_exp_F"
];

Also, Im guessing that static vehicle spawns wouldnt be good for performance. And it wouldnt work well with pseudo-virtualisation (spawn/despawn radius). If it was ambient vehicle with spawn/despawn radius, and you went out of range it would disappear but not respawn in the same place.

Edited by zyg0tic

Share this post


Link to post
Share on other sites
How can I modify this so it just puts empty vehicles around the place (or along roads)?

Ouff, that wouldn't be easy, I guess- That'd be another script then :D

Also, if the driver dies the vehicle disappears. I understand the deletion if too far, but i dont think its good to have the vehicle despawn on driver death.

That actually shouldn't be a thing, I'll look into it! :D

Share this post


Link to post
Share on other sites

BangaBob made a script called COS (Civilian Occupation System) which I use for spawning parked vehicles.

I was using L_Civ on the server, as a test on an insurgency mission I made, and it was causing the server's memory to max out. However, I use a very cheap Game Server and was also probably being limited by the service provider. Will definitely use this in operations though!

Share this post


Link to post
Share on other sites
BangaBob made a script called COS (Civilian Occupation System) which I use for spawning parked vehicles.

I was using L_Civ on the server, as a test on an insurgency mission I made, and it was causing the server's memory to max out. However, I use a very cheap Game Server and was also probably being limited by the service provider. Will definitely use this in operations though!

Did you take the default settings? If yes, keep in mind that the script will spawn 78 civilians and cars driving around. For a mission that already is script and ai heavy, I wouldnt set it to more than 10 or 15... especially on a low spec server :)

Share this post


Link to post
Share on other sites

Is possible to change script to have 3 unit in each groups ? I removed car part in script to change it to some kind ambient enemy random patrols in around of players at a dedicated server but i can't figure out how to change it to have 3 or a random number units in groups.

Share this post


Link to post
Share on other sites

I disabled pedestrians/drivers and only enabled parked cars (I spawn civilians through EOS instead, which is MUCH better for performance). I also made sure that the most cars that would spawn would be 25 and large towns would spawn around 2 or 3 cars. I can't tell if it hits performance at all with AI spawning a lot, but if it does have any impact, it's because it's counting all the buildings in the town to spawn a suitable amount of cars. It'd probably run better if SOMEONE *nudge nudge* made a script similar that just spawns a random integer between 1 and 3 cars per town, because it wouldn't have to check for so many objects and could probably reduce stutter/desync/memory usage. Just an assumption though. I'm just an idiot with scripting and understanding how that shit's handled. :p

Share this post


Link to post
Share on other sites

Tasty update!

Download v1.15

Changelog

1.15

Added: Debug options (L_civs_debug = 1, 2 or 3);

Fixed: Cars won't automatically despawn if their owner dies and players are nearby

Fixed: Cars and civilians will only despawn if no players are nearby

Fixed: Never ending loop in a function

Fixed: There should be no cars that are just standing around anymore

Fixed: Improved the waypoint search routine

Fixed: Civilians sometimes wouldn't spawn after all players were within blacklisted markers

Fixed: Some slight code and performance improvements

Fixed: Road detection

Fixed: Built in some safety mechanisms, never ending (unwanted) loops should be gone forever

Share this post


Link to post
Share on other sites

LAxemann, i was on a hill and was watching a car coming down the road, he went round a bend and then off the road. The thing is he just sat there and didn't move, no damage to the car, just his pride. Another car came along and drove past without problems, but the first car just sat there! Running 1.15. ;)

Share this post


Link to post
Share on other sites
Guest

New version frontpaged on the Armaholic homepage.

================================================

We have also "connected" these pages to your account on Armaholic.

This means soon you will be able to maintain these pages yourself if you wish to do so. Once this new feature is ready we will contact you about it and explain how things work and what options you have.

When you have any questions already feel free to PM or email me!

Share this post


Link to post
Share on other sites
LAxemann, i was on a hill and was watching a car coming down the road, he went round a bend and then off the road. The thing is he just sat there and didn't move, no damage to the car, just his pride. Another car came along and drove past without problems, but the first car just sat there! Running 1.15. ;)

Hey dude,

I unfortunately can't change anything about the way the AI drives, so if it feels like doing weird stuff, it'll do it! :D

By the way, I tested it with some guys today; Can anybody confirm that the script will spawn almost no civilians anymore after you shot one or two? Probably even without shooting anyone?

We couln't reproduce it afterwards but the debugger said it's spawning cars like crazy, but there were none. Hm?!

Share this post


Link to post
Share on other sites
Hey dude,

I unfortunately can't change anything about the way the AI drives, so if it feels like doing weird stuff, it'll do it! :D

No worries mate, thanks for replying though! Appreciated! ;)

Share this post


Link to post
Share on other sites

Can you confirm this works on dedi as could not see any cars at all driving around ? - could be a mod issue , but thought i would check first :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×