ACE3/addons/vehicles/functions/fnc_speedLimiter.sqf
SchmittAkaSmallfly d90f15ac7d Lower minimum speed limiter speed to 5 km/h (#5065)
* Update fnc_speedLimiter.sqf

* No minimum speed needed anymore

Minimum speed limit of 10 km/h was needed in the past due to engine limitations. Multiple user tests have shown that the minimum speed is not needed anymore. The new minimum of 0 km/h allows for example setting walking speed for vehicles (<10 km/h).

* Change minimum required speed for speed limiter to 3 km/h

To avoid problems with negative speeds (driving backwards) and zero speed, the current change switches from 10 km/h minimum speed to 3 km/h minimum speed. This seems to be the optimal solution to allow all relevant speeds including walking speed.

* Changed minimum required speed to 5 km/h

Officially the minimum required speed is 10 km/h in the master. Lower minimum needed to set car speed to walking speed of accompanying soldiers. Problems have been reported with 3 kmh/ using cars like ATVs.  Thus the new commit is set to 5 km/h minimum speed. Not tested with ATVs yet.
2017-05-31 15:45:02 -05:00

59 lines
1.5 KiB
Plaintext

/*
* Author: commy2
* Toggle speed limiter for Driver in Vehicle.
*
* Arguments:
* 0: Driver <OBJECT>
* 1: Vehicle <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, car] call ace_vehicles_fnc_speedLimiter
*
* Public: No
*/
#include "script_component.hpp"
params ["_driver", "_vehicle"];
if (GVAR(isSpeedLimiter)) exitWith {
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
playSound "ACE_Sound_Click";
GVAR(isSpeedLimiter) = false;
};
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
playSound "ACE_Sound_Click";
GVAR(isSpeedLimiter) = true;
private _maxSpeed = speed _vehicle max 5;
[{
params ["_args", "_idPFH"];
_args params ["_driver", "_vehicle", "_maxSpeed"];
if (GVAR(isUAV)) then {
private _uavControll = UAVControl _vehicle;
if ((_uavControll select 0) != _driver || _uavControll select 1 != "DRIVER") then {
GVAR(isSpeedLimiter) = false;
};
} else {
if (_driver != driver _vehicle) then {
GVAR(isSpeedLimiter) = false;
};
};
if (!GVAR(isSpeedLimiter)) exitWith {
[_idPFH] call CBA_fnc_removePerFrameHandler;
};
private _speed = speed _vehicle;
if (_speed > _maxSpeed) then {
_vehicle setVelocity ((velocity _vehicle) vectorMultiply ((_maxSpeed / _speed) - 0.00001)); // fix 1.42-hotfix PhysX libraries applying force in previous direction when turning
};
} , 0, [_driver, _vehicle, _maxSpeed]] call CBA_fnc_addPerFrameHandler;