Jump to content
engima

[RELEASE] Engima's Traffic Script

Recommended Posts

@engima Would it be possible to define an array of possible drivers as well as possible vehicles?

 

It would be great for people using modded civilians and vehicles to mix and match what spawns.

Share this post


Link to post
Share on other sites
3 hours ago, dreadpirate said:

@engima Would it be possible to define an array of possible drivers as well as possible vehicles?

 

It would be great for people using modded civilians and vehicles to mix and match what spawns.

 

Yes, possible vehicles is an array that goes into the start parameter set as VEHICLES. And the default driver can be replaced using the ON_UNIT_CREATED callback (called after unit has been created).

 

And if you want some more control over spawned vehicle classes other than pure random, or number of vehicles during certain times of the day etc, use callback ON_UNIT_SPAWNING (called right before a unit is created).

Share this post


Link to post
Share on other sites
Just now, engima said:

 

Yes, possible vehicles is an array that goes into the start parameter set as VEHICLES. And the default driver can be replaced using the ON_UNIT_CREATED callback.

 

And if you want some more control over spawned vehicle classes other than pure random, or number of vehicles during certain times of the day etc, use callback ON_UNIT_SPAWNING.

I was going to use ON_UNIT_CREATED to delete the driver and add my own, but wouldn't that interfere with managing and despawning the vehicles and units?

Share this post


Link to post
Share on other sites
1 hour ago, dreadpirate said:

I was going to use ON_UNIT_CREATED to delete the driver and add my own, but wouldn't that interfere with managing and despawning the vehicles and units?

 

No. It should be no problem. The new driver will be handled like the old one.

  • Thanks 1

Share this post


Link to post
Share on other sites

@engima This is what I tried...... 

 

The driver is being replaced as I want, but when the vehicle leaves the spawn radius, only the vehicle is deleted and the civilian is either killed or severely injured as the car disappears from under him.....

 

ConfigAndStart.sqf

Spoiler

/* 
 * This file contains parameters to config and function call to start an instance of
 * traffic in the mission. The file is edited by the mission developer.
 *
 * See file Engima\Traffic\Documentation.txt for documentation and a full reference of 
 * how to customize and use Engima's Traffic.
 */
 
private ["_parameters"];

_possibleVehicles = [
	"C_Offroad_01_F"
	,"C_Offroad_01_repair_F"
	,"C_Quadbike_01_F"
	,"C_Hatchback_01_F"
	,"C_Hatchback_01_sport_F"
	,"C_SUV_01_F"
	,"C_Van_01_transport_F"
	,"C_Van_01_box_F"
	,"C_Van_01_fuel_F"
	,"C_Offroad_01_covered_F"
];

possibleCivilians = [
	"C_man_1"
	,"C_Man_casual_1_F"
	,"C_Man_casual_2_F"
	,"C_Man_casual_3_F"
	,"C_man_sport_1_F"
	,"C_man_sport_2_F"
	,"C_man_sport_3_F"
	,"C_Man_casual_4_F"
	,"C_Man_casual_5_F"
	,"C_Man_casual_6_F"
	,"C_man_polo_1_F"
	,"C_man_polo_2_F"
	,"C_man_polo_3_F"
	,"C_man_polo_4_F"
	,"C_man_polo_5_F"
	,"C_man_polo_6_F"
	,"C_man_shorts_1_F"
	,"C_man_1_1_F"
	,"C_man_1_2_F"
	,"C_man_1_3_F"
	,"C_Man_Fisherman_01_F"
	,"C_man_hunter_1_F"
];

replaceDriver = {
	_vehicle = _this select 0;
	_group = _this select 1;
	
	_newDriver = _group createUnit[selectRandom possibleCivilians, getPos _vehicle, [], 20, "NONE"];
	deleteVehicle (driver _vehicle);
	waitUntil {isNull (driver _vehicle)};
	_newDriver moveInDriver	_vehicle;
};

// Set traffic parameters.
_parameters = [
	["SIDE", civilian],
	["VEHICLES", _possibleVehicles],
	["VEHICLES_COUNT", 5],
	["MIN_SPAWN_DISTANCE", 800],
	["MAX_SPAWN_DISTANCE", 1200],
	["MIN_SKILL", 0],
	["MAX_SKILL", 0.1],
	["ON_UNIT_CREATED", replaceDriver],
	["DEBUG", true]
];

// Start an instance of the traffic
_parameters spawn ENGIMA_TRAFFIC_StartTraffic;

 

 

Share this post


Link to post
Share on other sites
2 hours ago, dreadpirate said:

@engima This is what I tried...... 

 

The driver is being replaced as I want, but when the vehicle leaves the spawn radius, only the vehicle is deleted and the civilian is either killed or severely injured as the car disappears from under him.....

 

Ok, sorry. Try removing him in ON_UNIT_REMOVING then, which is executed right before the vehicle is removed.

  • Thanks 1

Share this post


Link to post
Share on other sites
27 minutes ago, engima said:

 

Ok, sorry. Try removing him in ON_UNIT_REMOVING then, which is executed right before the vehicle is removed.

 

Success! Thank you @engima!!! I'm also experimenting with your Civilian, Ambient Infantry and Patrolled Areas scripts. Everything is working well!

 

For the record, here is my ConfigAndStart.sqf. I don't know if what I've done will work in a dedicated or headless client environment, but for single player and listen servers it does the job.....

 

ConfigAndStart.sqf

Spoiler

/* 
 * This file contains parameters to config and function call to start an instance of
 * traffic in the mission. The file is edited by the mission developer.
 *
 * See file Engima\Traffic\Documentation.txt for documentation and a full reference of 
 * how to customize and use Engima's Traffic.
 */
 
private ["_parameters"];

_possibleVehicles = [
	"C_Offroad_01_F"
	,"C_Offroad_01_repair_F"
	,"C_Quadbike_01_F"
	,"C_Hatchback_01_F"
	,"C_Hatchback_01_sport_F"
	,"C_SUV_01_F"
	,"C_Van_01_transport_F"
	,"C_Van_01_box_F"
	,"C_Van_01_fuel_F"
	,"C_Offroad_01_covered_F"
];

possibleCivilians = [
	"C_man_1"
	,"C_Man_casual_1_F"
	,"C_Man_casual_2_F"
	,"C_Man_casual_3_F"
	,"C_man_sport_1_F"
	,"C_man_sport_2_F"
	,"C_man_sport_3_F"
	,"C_Man_casual_4_F"
	,"C_Man_casual_5_F"
	,"C_Man_casual_6_F"
	,"C_man_polo_1_F"
	,"C_man_polo_2_F"
	,"C_man_polo_3_F"
	,"C_man_polo_4_F"
	,"C_man_polo_5_F"
	,"C_man_polo_6_F"
	,"C_man_shorts_1_F"
	,"C_man_1_1_F"
	,"C_man_1_2_F"
	,"C_man_1_3_F"
	,"C_Man_Fisherman_01_F"
	,"C_man_hunter_1_F"
];

replaceDriver = {
	_vehicle = _this select 0;
	_group = _this select 1;
	
	_newDriver = _group createUnit[selectRandom possibleCivilians, getPos _vehicle, [], 20, "NONE"];
	deleteVehicle (driver _vehicle);
	waitUntil {isNull (driver _vehicle)};
	_newDriver moveInDriver	_vehicle;
};

deleteCrew = {
	_vehicle = _this select 0;
	
	{
		deleteVehicle _x;
	} forEach (crew _vehicle);
};

// Set traffic parameters.
_parameters = [
	["SIDE", civilian],
	["VEHICLES", _possibleVehicles],
	["VEHICLES_COUNT", 5],
	["MIN_SPAWN_DISTANCE", 800],
	["MAX_SPAWN_DISTANCE", 1200],
	["MIN_SKILL", 0],
	["MAX_SKILL", 0.1],
	["ON_UNIT_CREATED", replaceDriver],
	["ON_UNIT_REMOVING", deleteCrew],
	["DEBUG", true]
];

// Start an instance of the traffic
_parameters spawn ENGIMA_TRAFFIC_StartTraffic;

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Nice script!

 

Would be nice if we had an option for blacklist areas by using a marker.

I'm using ALiVE and have placed different markers for each area. So I can't whitelist them.

Only the marker for the greenzone is the same every time and could therefore be blacklisted.

Share this post


Link to post
Share on other sites

Used this script in a TvT mission where Blufor were hunting for Redfor insurgents who could move around in civilian cars, so to make it not to obvious i needed to have random civilians driving around as well. Script worked great and had some great reactions from the players that the inclusion of them was great.

 

Have to warn everyone to at least define a good area for the civilians to spawn in because they are murderous bastards.

 

See this clip: (warning loud!)
https://clips.twitch.tv/VibrantGoodDillSaltBae

Share this post


Link to post
Share on other sites

Hi

confirmed it works with Frame work v5.0

Also it does support air vehicles....

One question how would i make the AI drive on the left side of the road please.

 

I am using the Australia map and would like them to drive on the left. 

 

Also if i want the AI to be hostile to all players on the map would i just change to this?

 

 ["SIDE", sideEnemy],

 

Using this as a guide - https://community.bistudio.com/wiki/Side

 

Thank you

 

 

Share this post


Link to post
Share on other sites
On 4/22/2020 at 6:32 PM, Steel_Dragon said:

Hi

confirmed it works with Frame work v5.0

Also it does support air vehicles....

One question how would i make the AI drive on the left side of the road please.

 

I am using the Australia map and would like them to drive on the left. 

 

Also if i want the AI to be hostile to all players on the map would i just change to this?

 

 ["SIDE", sideEnemy],

 

Using this as a guide - https://community.bistudio.com/wiki/Side

 

Thank you

 

 

 

AI driving on left side of the road is probably impossible. Ask Bohemia to fix that.

 

I’d be surprised if sideEnemy makes AI hostile

to all players. I’d give them side guerilla instead, assuming players are east and west. And then make sure guerilla as side is enemy to both east and west (can be set in the Eden editor).

  • Thanks 1

Share this post


Link to post
Share on other sites
15 hours ago, engima said:

 

AI driving on left side of the road is probably impossible. Ask Bohemia to fix that.

 

I’d be surprised if sideEnemy makes AI hostile

to all players. I’d give them side guerilla instead, assuming players are east and west. And then make sure guerilla as side is enemy to both east and west (can be set in the Eden editor).

Thanks for the reply... i assume setting the AI "guerilla as side is enemy to both east and west (can be set in the Eden editor)." these would be already on the map? and use the init field to make them hostile? how would i do this if they are spawned through this script? I will test by changing  ["SIDE", "GUER"],  but as for setting the spawned AI as an enemy in the editor i am not really sure what you mean.

 

looking into something like this - 

 

independent setFriend [civilian, 0];

independent setFriend [blufor, 0];

resistance setFriend [civilian, 0];

resistance setFriend [blufor, 0];

opfor setFriend [civilian, 0];

opfor setFriend [blufor, 0];

civilian setFriend [blufor, 0];

civilian setFriend [civilian, 0];

blufor setFriend [blufor, 0];

blufor setFriend [civilian, 0];

 

execute this from init.sqf 

 

as i am not sure which side the AI spawn as i will use all these. EDIT - changed the side back to civilian

so i will try - 

 

civilian setFriend [blufor, 0];

civilian setFriend [civilian, 0];

civilian setFriend [opfor , 0];

 

Cheers

Share this post


Link to post
Share on other sites

No citations. Use this syntax:

[”SIDE”, guer]

 

Then all spawned units will belong to side guer.

 

Then in init.sqf I guess you can do:

guer setFriend [east, 0];

guer setFriend [west, 0];

 

But this scripting can also be done with a setting in the Eden Editor (Arma’s mission editor). Somewhere in ”settings” or ”scenario” somewhere in the menus. It’s names ”Independence allience” or something.

  • Thanks 1

Share this post


Link to post
Share on other sites

FYI...

 

Here is what I use to spawn civilian boat traffic. I haven't done a lot of testing on path finding, and how the boats move. But so far so good. At least this gets them on the water and moving. 

 

_civSea = [
	["SIDE", civilian],
	["VEHICLES", [
		"C_boat_civil_01_F", 
		"C_boat_civil_01__boat_F", 
		"C_boat_civil_01__rescue_F", 
		"C_rubberboat_F", 
		"C_boat_transport_02_F", 
		"C_scooter_Transport_01_F" 
		]],
	["VEHICLES_COUNT", 10],
	["MIN_SPAWN_DISTANCE", 2000],
	["MAX_SPAWN_DISTANCE", 5000],
	["MIN_SKILL", 0.4],
	["MAX_SKILL", 0.6],
	["AREA_MARKER", ""],
	["HIDE_AREA_MARKER", false],
	["ON_UNIT_CREATING",{}],
	["ON_UNIT_CREATED", {
		_ranPos = [nil, ["ground"]] call BIS_fnc_randomPos;		
		(_this select 0) setVehiclePosition [_ranPos, [],50, "NONE"];
		0 = [(_this select 0), "ColorBlue",true,2000] execVM "Scripts\JBOY_boatRandomPatrol.sqf";
		}],
	["ON_UNIT_REMOVING", {}],
	["DEBUG", false]
];

CHANGE 1: Changed position commands to not use markers. Working on using FindSafePos as well. 

 

Edited by Blackheart_Six
Updated code
  • Like 2

Share this post


Link to post
Share on other sites

Another item I was working on is getting patrolling insurgent units in boats. I tried using JBOY Longboat script to convert the boats, and create crews, but it just wouldn't work. So this is what I came up with for this. 

 

This will create a syndicate rhib, add crew to all positions. With this method, when the boat gets destroyed, the crew will get cleaned up as well. Additionally the position code puts the boat in deep water off shore. 

 

I am by no means a scripter, programmer, and coder. If you have a better way, more optimized please feel free to correct. I just read the biki's and guess. 

 

_pirates = [
	["SIDE", resistance],
	["VEHICLES", ["I_C_Boat_Transport_02_F"]],
	["VEHICLES_COUNT", 5],
	["MAX_GROUPS_COUNT", 0],
	["MIN_SPAWN_DISTANCE", 0],
	["MAX_SPAWN_DISTANCE", 15000],
	["MIN_SKILL", 0.4],
	["MAX_SKILL", 0.6],
	["AREA_MARKER", ""],
	["ON_UNIT_CREATING",{}],
	["ON_UNIT_CREATED", {
		private ["_centerposition","_pos","_radius","_exp","_prec","_bestplace","_spot","_spot2"];
		_centerposition = [worldSize/2, worldsize/2,0];
		_pos = _centerPosition;
		_radius = worldSize/2;
		_exp = "(4 * (WaterDepth interpolate [1,15,0,1]))";
		_prec = 100;
		_bestplace = selectBestPlaces [_pos,_radius,_exp,_prec,1];
		_spot = _bestplace select 0;
		_spot2 = _spot select 0;
		(_this select 0) setVehiclePosition [_spot2, [],0, "NONE"];


		if (canMove (_this select 0)) then {
		_pirate2 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate2 moveInCargo [(_this select 0), 2];(units _pirate2) join (_this select 1);
		_pirate3 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate3 moveInCargo [(_this select 0), 3];(units _pirate3) join (_this select 1);
		_pirate4 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate4 moveInCargo [(_this select 0), 4];(units _pirate4) join (_this select 1);
		_pirate5 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate5 moveInCargo [(_this select 0), 5];(units _pirate5) join (_this select 1);
		_pirate6 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate6 moveInCargo [(_this select 0), 7];(units _pirate6) join (_this select 1);
		_pirate7 = (_this select 1) createUnit ["I_C_Soldier_Bandit_1_F",(_this select 0), [], 0, "CARGO"];_pirate7 moveInCargo [(_this select 0), 7];(units _pirate7) join (_this select 1);
		};
		0 = [(_this select 0),"colorBlue",true,2000] execVM "Scripts\JBOY_boatRandomPatrol.sqf";
	}],
	["ON_UNIT_REMOVING", {
	}],
	["DEBUG", false]
];

_pirates spawn ENGIMA_TRAFFIC_StartTraffic;

 

  • Like 2

Share this post


Link to post
Share on other sites

_refPosX = (_refPlayerPos select 0) + (_minSpawnDist>

15:57:03 Error position: <_refPlayerPos select 0) + (_minSpawnDist>

15:57:03 Error Undefined variable in expression: _refplayerpos

15:57:03 File mpmissions\__cur_mp.Altis\Engima\Traffic\Server\Functions.sqf..., line 278

15:57:03 Error in expression < true;

_dir = random 360;

 

 

is there away to fix this spamming errors

Share this post


Link to post
Share on other sites

Hey guys, so I am fond of this script and wondering if anyone knows if there is a Group version for the mod? Such as turning this into a convoy version

I am looking for something like this script, but being able to instead random between different vehicles, instead random with different groups, how many vehicles, and what vehicles that would be amazing

Just the same, the random convoy reaches the maximum range and de-spawn, and then another spawn within the maximum range range

 

I was peeking at this script

 

 

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

×