Jump to content
engima

[RELEASE] Engima's Traffic Script

Recommended Posts

@engima,

18 hours ago, engima said:

A broken hard drive sector? Try on another computer. :)

I don't think this is the problem.  I have three separate missions trying to produce traffic, in three different scenarios, by two different authors.  I tend to believe the malfunction is with Arma & all its problems with vehicles following waypoints.

 

@ anfo

Thanks for popping in & verifying:

17 hours ago, anfo said:

Engima\Civilians\Common\common.sqf

is an actual empty file.  That is what I thought after examining that file in the updated download.

 

20 hours ago, anfo said:

Have you changed any parameters in the configandstart.sqf?

In the beginning, yes.  The three parameters highlighted in bold in my first post.

 

But then I followed the video from Type.sqf with just a player & no changes to the configandstart.sqf..  Neither script would produce their corresponding units.  Running both scripts at the same time introduced the windows busy cursor for about 20 seconds, freezing mouse input & preventing access to the player unit.  It appears something is loading.  Have you ever run the Civilian & Traffic Scripts at the same time??

 

Just to be safe, I verified the game files today.  There were no errors detected.

 

Will experiment some more & check back later.... 

 

Share this post


Link to post
Share on other sites

Success!!  Watching the vids again cleared up some of my errors.  Especially the type of marker I was using.

Also my placement of the player unit in the middle of town was flawed.  Vehicles just never went past him.  When I placed the unit on the hillside, I could see the random traffic moving around.

 

Knew I was doing something wrong. By trying to utilize your script in an existing 3rd party mission,  no matter what I tried, it would not work.  By using type.sqf to check a couple of the scripts in the mission for errors, it reported some undeclared variables pertaining to vehicles.  This is probably what kept your script from functioning properly.  Not being a scripter, as long as the script in the mission performed as advertised, what did I know.  Just have to figure out how to repair that script.

 

 Thank you both for all your assistance....

Share this post


Link to post
Share on other sites
On 02/08/2017 at 5:36 PM, engima said:

The marker was implemented as an idea to have different traffic zones on the map, and not to micromanage things.

 

So multiple markers are actually permitted? Is this ok?

["AREA_MARKER", "traffic_1", "traffic_2],

 

Share this post


Link to post
Share on other sites
59 minutes ago, anfo said:

 

So multiple markers are actually permitted? Is this ok?


["AREA_MARKER", "traffic_1", "traffic_2],

 

No. Only one per traffic instance. If you want traffic in more than one "zone" you will need to call the start function twice.

Share this post


Link to post
Share on other sites
On 2017-08-02 at 3:33 AM, JD Wang said:

Wow thanks, I'm using your civilian traffic script as part of my latest ALiVE mission because your script does traffic better than any other I've come across.

What I was hoping to achieve is the normal civilian traffic, but occasionally have an enemy truck with supplies or soldiers on board.

I was hoping to run the script multiple times as I've done before, once just normally and the second time I thought if I made the vehicle array full of 9 empty items, and the 10th and enemy truck, I'd essentially have a 10% chance of the enemy truck spawning. 

 

I was then hoping to be able to use the callback somehow to add supplies to the vehicle, or populate it with 10 guys.

 

It's great when you're clearing a town and a random civilian vehicle rolls through, was hoping to somehow have there be a chance for an enemy truck to do the same thing.

I hope that makes sense.

Now there's a new version release as a CPack:

http://typesqf.no-ip.org/cpack/details/Engima.Traffic

 

You can achieve what you're after by editing the new callback ON_UNIT_CREATING. If that one returns true the vehicle will be created, otherwise not. When not all vehicles have spawned this callback is called like once every 5th second. The following code will initialize a traffic instance with one vehicle, and once per minute - if the vehicle is not present - it will spawn in one with 25% chance.

 

_parameters = [
    ["SIDE", east],
    ["VEHICLES", ["O_APC_Wheeled_02_rcws_F"]],
    ["VEHICLES_COUNT", 1],
    ["MIN_SPAWN_DISTANCE", 800],
    ["MAX_SPAWN_DISTANCE", 1200],
    ["ON_UNIT_CREATING", { 
        private _doSpawnVehicle = false; 

        if (isNil "ME_lastTryTime") then { ME_lastTryTime = 0; }; 

        if (time - ME_lastTryTime > 60) then {
            _doSpawnVehicle = random 100 < 25;
            ME_lastTryTime = time;
        }; 

        _doSpawnVehicle
    }],
    ["DEBUG", true]
];

 

And like you suggest, the ON_UNIT_CREATED callback is the best place to edit the vehicles loadout etc.

  • Like 1

Share this post


Link to post
Share on other sites

guys...Engima surpassed himself!
this script is an ESSENTIAL MASTERPIECE for anyone who wants to make any kind of mission!
Its so versatile that i use it to spawn every kind of "ambient population", civs vehicles (obviously), civs on foot, enemy patrols of different factions on foot and on vehicles, even mines on the roads (IEDs) !!
now with the new commands like "ON_UNIT_CREATED" it adds even more versatility, i cant even think at all the possibilieties it allows!
...and performance are really good, on my server the impact is related just to the amount of spawned units!
really, really congratulations Engima, a huge thanks, that script really gives life to ARMA3 !!

  • Like 1

Share this post


Link to post
Share on other sites

Wow that's awesome, thank you. I'll give that a try this weekend :)

Share this post


Link to post
Share on other sites

Here are the fixes:

 

v1.6.1
- Adjusted vehicle spawn distances.
- Improved traffic flow by removing immobile vehicles outside visual range.
- Fixed: Many traffic units not moving at all on maps with several small islands (like Tanoa).
- Fixed: Units get stuck on small paths in the woods (like on Tanoa). Paths are now ignored.
- Fixed: Number of vehicles not relative to traffic area coverage in some cases.
- Added callback ON_UNIT_CREATING which fires right before a vehicle spawns.
- Replaced callback ON_SPAWN_CALLBACK with ON_UNIT_CREATED.
- Replaced callback ON_REMOVE_CALLBACK with ON_UNIT_REMOVING.
- Fixed: Vehicles tend to spawn more often behind the players than ahead of them.
- Added support for headless client.
- Script no longer tries to terminate scripts executed in spawn callback.

  • Like 3

Share this post


Link to post
Share on other sites

Love this script, been using it for a long time on my Takistan server, good work!

  • Like 1

Share this post


Link to post
Share on other sites

Hi, thanks for this great script!!!

 

Quick question: I plan to use this "on the go" in zeus missions. Should I expect any troubles while using spawn and terminate to run/stop the ENGIMA_TRAFFIC_StartTraffic script during a mission?

 

Thanks again.

Share this post


Link to post
Share on other sites

Yes, unfortunately. The script starts a thread to find "edge road segments", and to do that without too much load, that will take some minutes to complete (depending on map size). Thus, all traffic instances must be started before this thread is starting, so the edge segments is kategorized correctly. I think you have a window of 5 seconds if I remember correctly. It's also in the documentation.

 

But there are a callback that could be used I suppose. If you have the ON_UNIT_CREATING callback return false, no vehicles will spawn. Maybe you can create a switch there, to turn spawning of vehicles on and off?

Share this post


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

Yes, unfortunately. The script starts a thread to find "edge road segments", and to do that without too much load, that will take some minutes to complete (depending on map size). Thus, all traffic instances must be started before this thread is starting, so the edge segments is kategorized correctly. I think you have a window of 5 seconds if I remember correctly. It's also in the documentation.

 

But there are a callback that could be used I suppose. If you have the ON_UNIT_CREATING callback return false, no vehicles will spawn. Maybe you can create a switch there, to turn spawning of vehicles on and off?

 

That's a shame. I was hoping to create custom modules for Ares Mod - Achilles Expansion that would allow to dynamically create areas with different vehicles/factions. I've managed to successfully create at least one instance with a module. Better than nothing :)

 

Btw should I expect similar issues with your Civilians Script? (While creating "pockets" of populated areas dynamically using custom modules)

 

Edit: Since "Script cannot run in more than one instance." I assume so :)

Edited by kimsterN7

Share this post


Link to post
Share on other sites

Hi @engima

 

May I ask your expertise on the ON_UNIT_CREATED parameter please? First, do you think adding:

setbehavior safe

Could work to keep cars on the road? If so, can you please show how I would add to below?

["ON_UNIT_CREATED", {(_this select 0) limitSpeed 30}],

 

Share this post


Link to post
Share on other sites

Great Script.... your stuff is very easy to use. Form certainly follows function.  I am building the civ world first with your traffic and civilian scripts. These and Phronks furniture script, it is looking pretty good. 

 

I would like to request adding a boat traffic, and civil air traffic. I think that would really top it off. 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Actually I have started Engima's Ambient Naval Units, but I'm only half way in that. So if I find some inspiration it's not imossible...

  • Like 2

Share this post


Link to post
Share on other sites

I contributed a random boat patrol script that may have something useful  for you.  It does not do caching and spawning based on player presence, but it does solve some real problems with AI boats (boats getting stuck on shore, boats refusing to obey commandMove periodically, etc. ).  Feel free to pluck any code from there if you find it useful.

 

  • Like 2

Share this post


Link to post
Share on other sites

Hi guys , love the script! I am struggling with one issue however.I have tried everything I can think of but cannot fix this. I need to change the driver of vehicles spawned via traffic. I am running a Post Apoc scenario and drivers in Bermuda shorts and Blue Polo shirts is very immersion breaking...Ideally I need the script to randomly pick a driver from an Array with my selected units in it. I am sorry to ask for help but I cannot get anything to work using the ["ON_UNIT_CREATED", I have even delved into the code (very limited knowledge here) but cannot find an array referencing the drivers.

 

I have managed to get Zenophen to add random loot to vehicles (From an Array) and I think I can make the vehicles salvageable.......but I cannot change the drivers of the vehicles. This needs to be done for all factions ...not just civilian factions. Any help or input is much appreciated.

Share this post


Link to post
Share on other sites

Husker-71, that should be quite easy.

 

Check the documentation. All callbacks take some useful parameters that you can use.

 

Quote

ON_UNIT_CREATED (Code): Code that is executed when a vehicle has spawned. Parameter _this is an array:
    0 (Object): The vehicle that was created.
    1 (Group): The group that the vehicle belongs to.
    2 (Scalar): Number of vehicles spawned and currently controlled by the script.
    3 (Scalar): Calculated maximun number of units that the script will try to spawn (depends on spwn markers
    etc.).
  Example: { hint ("Vehicle of type " + typeOf (_this select 0) + " created!")

 

So if you just reads the parameters with params like this:


params ["_vehicle", "_group", "_vehicleCount", "_calculatedMaxVehicles"];

 

Then you can reference the driver by doing:


private _theDriver = driver _vehicle;

 

Remove it, create another one, and put the new on in:


deleteVehicle _theDriver;

createUnit ... ;

...

 

Don't have time to do the job, but maybe that will be enough?

  • Thanks 2

Share this post


Link to post
Share on other sites
On 1/9/2018 at 11:16 AM, engima said:

Husker-71, that should be quite easy.

 

Check the documentation. All callbacks take some useful parameters that you can use.

 

 

So if you just reads the parameters with params like this:

 


params ["_vehicle", "_group", "_vehicleCount", "_calculatedMaxVehicles"];

 

 

Then you can reference the driver by doing:

 


private _theDriver = driver _vehicle;

 

 

Remove it, create another one, and put the new on in:

 


deleteVehicle _theDriver;

createUnit ... ;

...

 

 

Don't have time to do the job, but maybe that will be enough?

Hi Enigma , thanks for the reply, I am upto my eyeballs with work at the moment but I will give that a try this weekend. Appreciate it!

Share this post


Link to post
Share on other sites

@engima Wow, I never saw this until now. I spent a good chunk of 2016 writing my own vehicle spawn and traffic flow system (on my github in the footer below). Had I know about your work, I could have saved myself a lot of aggravation LOL.

  • Like 1

Share this post


Link to post
Share on other sites

Hey

 

 

After last update i get a lot of this in my RPT

 

 

_refPosX = (_refPlayerPos select 0) + (_minSpawnDist>
 9:44:12   Error position: <_refPlayerPos select 0) + (_minSpawnDist>
 9:44:12   Error Undefined variable in expression: _refplayerpos
 9:44:12 File mpmissions\__cur_mp.chernarus_summer\Engima\Traffic\Server\Functions.sqf, line 278
 9:44:12 Error in expression < true;

_dir = random 360;

 

over 11000

  • Like 1

Share this post


Link to post
Share on other sites
On 2018-05-15 at 11:22 AM, loopdk said:

Hey

 

 

After last update i get a lot of this in my RPT

 

 

_refPosX = (_refPlayerPos select 0) + (_minSpawnDist>
 9:44:12   Error position: <_refPlayerPos select 0) + (_minSpawnDist>
 9:44:12   Error Undefined variable in expression: _refplayerpos
 9:44:12 File mpmissions\__cur_mp.chernarus_summer\Engima\Traffic\Server\Functions.sqf, line 278
 9:44:12 Error in expression < true;

_dir = random 360;

 

over 11000

Ok, now I've checked, and I cannot find anything wrong. Created a new mission and added traffic. Is it possible that you are getting a conflict with something else? Please PM your mission to me if you want me to check further.

  • Thanks 1

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

×