BetterDeadThanZed

Adjusting speed of A3XAI vehicles

12 posts in this topic

Does anyone know how I'd set  a maximum speed for A3XAI land patrols? I've looked through some of the files but I just can't find anywhere that sets a maximum speed.

Share this post


Link to post
Share on other sites

I used A3XAI extensively a while back and I don't remember there being any such control. I quit using it because it causes bad memory leaks ever since one of the previous Arma3 updates, and since it's not updated anymore, it isn't likely to get fixed. Either way, I don't believe it has what you're looking for. Maybe you can do something with a global variable or something. 

Share this post


Link to post
Share on other sites
Advertisement

Something has to set the maximum speed somewhere in the code or there has to be a variable that sets the maximum speed an AI vehicle can go. 

Share this post


Link to post
Share on other sites

Of course. I just don't think there is anything in A3XAI that can configure that. I assume there is a global variable that controls it that you could stick into your init.sqf and override the default. But that's probably going to be a piece of Arma itself, not A3XAI. That's all I'm saying. 

Share this post


Link to post
Share on other sites

I knew there's no config option and that's the whole purpose of this post. To find out how I can achieve that. 

Share this post


Link to post
Share on other sites

I see. According to...

https://community.bistudio.com/wiki/limitSpeed

the variable is limitSpeed. I assume you can probably define it in your init.sqf as a global variable, tweak the value until you like it. I assume this only applies to AI vehicles, but there is a possibility of unwanted side effects. 

You'd have to write a bit of custom code, but you could also define it for the individual vehicles themselves wherever A3XAI spawns the vics. 

Share this post


Link to post
Share on other sites

Ok, got it worked out. For anyone else that may wish to do this:

Open your a3xai.pbo file.
Go to a3xai\compile\A3XAI_unit_spawning\A3XAI_spawnVehiclePatrol.sqf and find these lines:

			if !(_nextRoads isEqualTo []) then {
				_direction = [_vehicle,(_nextRoads select 0)] call BIS_fnc_relativeDirTo;
				_vehicle setDir _direction;

Under those, add this:

_vehicle limitSpeed 25;

Next, find these lines, just below:

				//diag_log format ["Debug: Reoriented vehicle %1 to direction %2.",_vehicle,_direction];
			};
		} else {
			_vehicle setDir (random 360);

Under those, add this:

_vehicle limitSpeed 25;

The whole section should look like this:

	if (_vehicle isKindOf "LandVehicle") exitWith {
		_nearRoads = _vehiclePosition nearRoads 100;
		if !(_nearRoads isEqualTo []) then {
			_nextRoads = roadsConnectedTo (_nearRoads select 0);
			if !(_nextRoads isEqualTo []) then {
				_direction = [_vehicle,(_nextRoads select 0)] call BIS_fnc_relativeDirTo;
				_vehicle setDir _direction;
				_vehicle limitSpeed 25;
				//diag_log format ["Debug: Reoriented vehicle %1 to direction %2.",_vehicle,_direction];
			};
		} else {
			_vehicle setDir (random 360);
			_vehicle limitSpeed 25;
		};
	};

Adjust the number after limitSpeed to reflect the maximum speed you want the AI vehicle to travel.

2 people like this

Share this post


Link to post
Share on other sites
7 hours ago, BetterDeadThanZed said:

Ok, got it worked out. For anyone else that may wish to do this:

Open your a3xai.pbo file.
Go to a3xai\compile\A3XAI_unit_spawning\A3XAI_spawnVehiclePatrol.sqf and find these lines:


			if !(_nextRoads isEqualTo []) then {
				_direction = [_vehicle,(_nextRoads select 0)] call BIS_fnc_relativeDirTo;
				_vehicle setDir _direction;

Under those, add this:


_vehicle limitSpeed 25;

Next, find these lines, just below:


				//diag_log format ["Debug: Reoriented vehicle %1 to direction %2.",_vehicle,_direction];
			};
		} else {
			_vehicle setDir (random 360);

Under those, add this:


_vehicle limitSpeed 25;

The whole section should look like this:


	if (_vehicle isKindOf "LandVehicle") exitWith {
		_nearRoads = _vehiclePosition nearRoads 100;
		if !(_nearRoads isEqualTo []) then {
			_nextRoads = roadsConnectedTo (_nearRoads select 0);
			if !(_nextRoads isEqualTo []) then {
				_direction = [_vehicle,(_nextRoads select 0)] call BIS_fnc_relativeDirTo;
				_vehicle setDir _direction;
				_vehicle limitSpeed 25;
				//diag_log format ["Debug: Reoriented vehicle %1 to direction %2.",_vehicle,_direction];
			};
		} else {
			_vehicle setDir (random 360);
			_vehicle limitSpeed 25;
		};
	};

Adjust the number after limitSpeed to reflect the maximum speed you want the AI vehicle to travel.

You could put it in a bit higher just the once, too:

if (_vehicle isKindOf "LandVehicle") exitWith {
		_nearRoads = _vehiclePosition nearRoads 100;
		_vehicle limitSpeed 25; // <--- Here..
		if !(_nearRoads isEqualTo []) then {
			_nextRoads = roadsConnectedTo (_nearRoads select 0);
			if !(_nextRoads isEqualTo []) then {
				_direction = [_vehicle,(_nextRoads select 0)] call BIS_fnc_relativeDirTo;
				_vehicle setDir _direction;
				//diag_log format ["Debug: Reoriented vehicle %1 to direction %2.",_vehicle,_direction];
			};
		} else {
			_vehicle setDir (random 360);			
		};
	};

 

1 person likes this

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.