Jump to content
engima

[RELEASE] Engima's Traffic Script

Recommended Posts

@wolkenbeisser

Actually there is callbacks for spawn and remove. It was missing in the overview above, but it is now added.

I choose whitelist markers instead of blacklist markers, because the movement is done with waypoints, and I'ts really hard to control the AI pathfinding, which would have resulted in vehicles moving in blacklisted areas anyway. I didn't want the vehicles to stop or to vanish in sight of players.

Share this post


Link to post
Share on other sites

@engima:

 

Cool! I tried traffic with a whitelist marker (didn't change the script at all, only the parameters in ConfigAndStart.sqf, as you proposed) and it works great! --> No longer civ traffic in restricted areas...

 

But one question is still left (as I'm not really a script crack): Within the civilians script I use this code to prepare the civilans for "counting the player murders on civilians" --->      ["ON_UNIT_SPAWNED_CALLBACK", {_unit = (_this select 0); _unit addEventHandler ["KILLED",{call GDT_fnc_civCounter}];}],

 

How do I have to change that code for the vehicles (resp. drivers) of the traffic script? My goal is, that the drivers of the cars spawned by the traffic script also count as victims if players kill too many civilians.

 

Thanks in advance everybody for your support :-)

Share this post


Link to post
Share on other sites

Here is the documentation:

 

* ON_SPAWN_CALLBACK (Code): Code that is executed when a vehicle has spawned. Parameter _this is an array: 0: created 
  vehicle (Object), 1: all crew (Array of Objects), 2: vehicle's group (Group). Default value is {}.
  Example: { hint ("Vehicle of type " + typeOf (_this select 0) + " created!")

 

So this should do it:


{

    _crew = (_this select 1);

    {

        _x addEventHandler ["KILLED", { call GDT_fnc_civCounter }];

    } foreach _crew;

}

  • Like 1

Share this post


Link to post
Share on other sites

Wow, thanks engima!

 

Now, everything works as expected. Thanks a lot for your great script - and for your support of course.  :rthumb:

 

Best regards from Switzerland

Wolkenbeisser

Share this post


Link to post
Share on other sites

Is there a parameter that I've missed to slow traffic down? At some intersections traffic will collide and I thought if I could just slow the AI down, they wouldn't get into pile-ups like they do.

Share this post


Link to post
Share on other sites

Unfortunately not. But it's a great idea for a future release.

 

But you can do it with the ON_SPAWN_CALLBACK:


(_this select 0) limitSpeed 20;

Share this post


Link to post
Share on other sites

Hey enigma, love the script!  Do you know if the 64-bit ArmA going to break the script?  

Share this post


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

Unfortunately not. But it's a great idea for a future release.

 

But you can do it with the ON_SPAWN_CALLBACK:

 


(_this select 0) limitSpeed 20;

 

 

Like this?

["ON_SPAWN_CALLBACK", (_this select 0) limitSpeed 20],

edit: all good, forgot the squiggly brackets {} :f:

 

["ON_SPAWN_CALLBACK", {(_this select 0) limitSpeed 20}],

 

  • Like 1

Share this post


Link to post
Share on other sites

Since 1.68 it throws an error:

 

 2:06:32 Error in expression <le "dre_scriptHandle";
if (!(scriptDone _scriptHandle)) then {
terminate _script>
 2:06:32   Error position: <_scriptHandle)) then {
terminate _script>
 2:06:32   Error Nicht definierte Variable in Ausdruck: _scripthandle 					// english: not defined variable in expression
 2:06:32 File mpmissions\__cur_mp.Takistan\Engima\Traffic\Server\Functions.sqf, line 490

I checked it, but actually cannot figure what's the reason for this. BIS might have changed some sqf commands, but I haven't researched it yet. Just wanted to let you know :)

I'm currently fixing all my own stuff which doesn't work since the update. 

BTW: The error isn't breaking the script. It still works, traffic is spawned arround the map like configured in call. 

Share this post


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

Since 1.68 it throws an error:

 


 2:06:32 Error in expression <le "dre_scriptHandle";
if (!(scriptDone _scriptHandle)) then {
terminate _script>
 2:06:32   Error position: <_scriptHandle)) then {
terminate _script>
 2:06:32   Error Nicht definierte Variable in Ausdruck: _scripthandle 					// english: not defined variable in expression
 2:06:32 File mpmissions\__cur_mp.Takistan\Engima\Traffic\Server\Functions.sqf, line 490

I checked it, but actually cannot figure what's the reason for this. BIS might have changed some sqf commands, but I haven't researched it yet. Just wanted to let you know :)

I'm currently fixing all my own stuff which doesn't work since the update. 

BTW: The error isn't breaking the script. It still works, traffic is spawned arround the map like configured in call. 

 

Thanks Godis_1.  I'm too much of a scripting noob to know what that error means as well.

Share this post


Link to post
Share on other sites

Can it be a script handle for a script that is already done executing? Maybe I should remove the terminate command completely and let the user handle that...

Share this post


Link to post
Share on other sites
On 20.3.2017 at 3:57 AM, kman_(kya) said:

 

Thanks Godis_1.  I'm too much of a scripting noob to know what that error means as well.

NP :) It was meant to Engima, so he can take care of it when updating - if he's planning to do so. But I can fix that too and throw the solution here then.. But will take some time as I have to fix my own project atm., 

  • Like 1

Share this post


Link to post
Share on other sites
On 20.3.2017 at 2:20 PM, engima said:

Can it be a script handle for a script that is already done executing? Maybe I should remove the terminate command completely and let the user handle that...

I will take a closer look into it. But I know for sure that this error wasn't shown before 1.68 update - OR it is related to one of my own scripts, but I cannot see any reference to that as I didn't change anything related to your traffic script. Anyways, let me try to find the reason before doing anything - unless you fix it before :)

Share this post


Link to post
Share on other sites
Cannot get Traffic Script to Work

I followed the directions & copied the Engima folder into the mission root folder. 
Created the init.sqf file with the code:  call compile preprocessFileLineNumbers "Engima\Traffic\Init.sqf";

Created a marker using the military square & named it Traffic1.  Sized it approximately 1.5 km square.  Placed it over a civilain vehicle designated player on the map of Altis.  It covered the town of Kavala & Aggelochori, the town above it.

This is the code in the ConfigAndStart.sqf:

 private ["_parameters"];
// Set traffic parameters.
_parameters = [
      ["SIDE", civilian],
      ["VEHICLES", ["C_Offroad_01_F", "C_Offroad_01_F", "C_Quadbike_01_F",  "C_Hatchback_01_F", "C_Hatchback_01_sport_F", "C_SUV_01_F",  "C_SUV_01_F",  "C_Van_01_transport_F", "C_Van_01_box_F", "C_Van_01_fuel_F"]],
      ["VEHICLES_COUNT", 10],
      ["MIN_SPAWN_DISTANCE", 800],
      ["MAX_SPAWN_DISTANCE", 1200],
      ["MIN_SKILL", 0.4],
      ["MAX_SKILL", 0.6],
      ["AREA_MARKER", "Traffic1"],
      ["HIDE_AREA_MARKER", false],
      ["ON_SPAWN_CALLBACK", {(_this select 0) limitSpeed 30}],

      ["DEBUG", false]
];

// Start an instance of the traffic
_parameters spawn ENGIMA_TRAFFIC_StartTraffic;
 
The first two lines of code in bold is what I added as per documentation. Changed the marker to visible.  The third I found in an above posting.

When I played the scenario, it loaded without any errors.  I noticed the arrow cursor changed to the windows busy cursor.  It disappeared after 30 seconds, returning control to the player.  Accessing the map revealed the marker being displayed, by changing the parameter, but there weren't any dots representing spawned vehicles. 
 
The only other thing I noticed was the marker did not retain its size when zooming in or out of the editor map.
Also, I tried the Civilian Script v0.90.40 & that does not work for me either.  Examination of the Common.sqf  file revealed the file was empty.  Both were downloaded from Armaholic.

Any assistance in resolving this problem will be greatly appreciated...  OleGreyGhost

Share this post


Link to post
Share on other sites

An error in the download?

 

Here's what you can do. Install TypeSqf and install the CPack Engima.Traffic and see if it works better (you will also get a later and better version of the script). If you prefer another editor you can just use TypeSqf to download the script. Here's the link:

www.typesqf.com

 

1. Open your mission in TypeSqf (File->Open Mission).

2. Go to the CPack console and write "install Engima.Traffic".

Share this post


Link to post
Share on other sites

Hey @engima thanks for both this and your civilian spawning script, they've been a staple of a lot of the mission I make for our group. 

 

Now I know I can use this to script in OPFOR traffic which is awesome and works great, but the 2 things I'm curious about are if I fill the vehicle array with 9 blank entries and 1 OPFOR classname will that in essence give me a 1 in 10 chance to spawn an OPFOR vehicle or would that cause issues with the script? I'm looking to use this as almost a random vehicle patrol script and don't want OPFOR vehicles constantly spawning around the player, more like 5-10% of the time. (I hope that makes sense)

 

Also is it possible to add inventory/passengers to the vehicles?

Share this post


Link to post
Share on other sites

Thanks for the response.  I will download type.sqf & give it a go, but I am not at all familiar with this procedure. 

Quote

An error in the download?

 

When I checked the files in Civilian Script v0.90.4, the one file Common.sqf  was empty.  There wasn't any scripting code in it.  This is what I was inquiring about, as to whether this was an error or not?

 

The same file name Common.sqf  in the Traffic Script had scripting code in it.

Share this post


Link to post
Share on other sites
22 hours ago, JD Wang said:

Hey @engima thanks for both this and your civilian spawning script, they've been a staple of a lot of the mission I make for our group. 

 

Now I know I can use this to script in OPFOR traffic which is awesome and works great, but the 2 things I'm curious about are if I fill the vehicle array with 9 blank entries and 1 OPFOR classname will that in essence give me a 1 in 10 chance to spawn an OPFOR vehicle or would that cause issues with the script? I'm looking to use this as almost a random vehicle patrol script and don't want OPFOR vehicles constantly spawning around the player, more like 5-10% of the time. (I hope that makes sense)

 

Also is it possible to add inventory/passengers to the vehicles?

It's not possible. But I can fix the script for you now when I know what you need. Thanks for the feedback. Expect a new version in a couple of days.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I was able to download & successfully install your Traffic & Civilian scripts thru Type.sqf..  Both are newer versions than what I have.

 

But, sadly, neither of them would produce any civilians or traffic.  I tried them singley & with both loading at the same time, without any success.  Watched the videos explanations.

 

I then removed the dozen  mods that are installed, just leaving the CBA A3 mod.  Created a test mission with just a player unit & an empty init.sqf file.  Downloaded both scripts & successfully installed them.  The init.sqf file was processed correctly.  Still the scripts would not produce the requisite civilians or traffic.

 

To be fair, I have tried other scripts to produce traffic and none have worked.  Ambient_Life.Altis by MAD_t has both a civilian & traffic script, like yours.  It will produce civilians, but the traffic script is inoperative.  Can't remember the other traffic script.

 

I also checked that Common.sqf file in the newer version of the Civilian Script v 1.0 with Type.sqf..  It is still an empty file without any code in it.

 

Hopefully, you can help me figure out what I might be doing wrong.

 

 

 

Share this post


Link to post
Share on other sites

Is there a dimension for the markers that is considered too small, like the width of a standard road? I just want the cars to use the road instead of offroad and I don't think they're spawning because marker may not be wide enough?

 

edit: dw, 15m seems to work as a good marker width.

edit2: I think only 1 area marker is allowed as well?

Share this post


Link to post
Share on other sites

@olegreyghost, working here ok for me. Have you changed any parameters in the configandstart.sqf? If you haven't altered anything then it should just work out of the box?

Share this post


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

Is there a dimension for the markers that is considered too small, like the width of a standard road? I just want the cars to use the road instead of offroad and I don't think they're spawning because marker may not be wide enough?

 

edit: dw, 15m seems to work as a good marker width.

edit2: I think only 1 area marker is allowed as well?

I would say that 100x100 is too small. The marker was implemented as an idea to have different traffic zones on the map, and not to micromanage things.

 

Vehicles spawn on roads, and the fact that they cannot stay there is an Arma issue, and not a script issue. Cars with "Safe" waypoints should stay on the road, and I don't know how to handle that if not Arma fixes it first.

Share this post


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

I was able to download & successfully install your Traffic & Civilian scripts thru Type.sqf..  Both are newer versions than what I have.

 

But, sadly, neither of them would produce any civilians or traffic.  I tried them singley & with both loading at the same time, without any success.  Watched the videos explanations.

 

I then removed the dozen  mods that are installed, just leaving the CBA A3 mod.  Created a test mission with just a player unit & an empty init.sqf file.  Downloaded both scripts & successfully installed them.  The init.sqf file was processed correctly.  Still the scripts would not produce the requisite civilians or traffic.

 

To be fair, I have tried other scripts to produce traffic and none have worked.  Ambient_Life.Altis by MAD_t has both a civilian & traffic script, like yours.  It will produce civilians, but the traffic script is inoperative.  Can't remember the other traffic script.

 

I also checked that Common.sqf file in the newer version of the Civilian Script v 1.0 with Type.sqf..  It is still an empty file without any code in it.

 

Hopefully, you can help me figure out what I might be doing wrong.

 

 

 

Well, I cannot explain why you end up with empty Common.sqf, but if it's empty it will not work. A broken hard drive sector? Try on another computer. :)

Share this post


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

Well, I cannot explain why you end up with empty Common.sqf, but if it's empty it will not work.

 

I have to concur with @olegreyghost on this one, my:

Engima\Civilians\Common\common.sqf

Is empty, but my civilians are spawning no problem. Traffic common.sqf however has code and that is working fine too.

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

×