Vehicles - Utilize setCruiseControl for speed limiter (#8273)

* Change speed limiter to utalize setCruiseControl
Kept setVelocity with a +2 to speed check to make vehicle slow down downhill and to slow it down when enabled.

* Update addons/vehicles/functions/fnc_speedLimiter.sqf

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* Update addons/vehicles/functions/fnc_speedLimiter.sqf

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>

* Update addons/vehicles/functions/fnc_speedLimiter.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

* Update addons/vehicles/functions/fnc_speedLimiter.sqf

Co-authored-by: PabstMirror <pabstmirror@gmail.com>

Co-authored-by: Filip Maciejewski <veteran29@users.noreply.github.com>
Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
Broström.A | Evul 2021-10-13 23:58:09 +02:00 committed by GitHub
parent 471cc59320
commit 0c85f5f339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,9 +21,13 @@ params ["_driver", "_vehicle"];
if (GVAR(isSpeedLimiter)) exitWith { if (GVAR(isSpeedLimiter)) exitWith {
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured); [localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
playSound "ACE_Sound_Click"; playSound "ACE_Sound_Click";
_vehicle setCruiseControl [0, false];
GVAR(isSpeedLimiter) = false; GVAR(isSpeedLimiter) = false;
}; };
(getCruiseControl _vehicle) params ["_speedLimit"];
if (_speedLimit != 0) exitWith { TRACE_1("speed limit set by external source",_speedLimit); };
[localize LSTRING(On)] call EFUNC(common,displayTextStructured); [localize LSTRING(On)] call EFUNC(common,displayTextStructured);
playSound "ACE_Sound_Click"; playSound "ACE_Sound_Click";
GVAR(isSpeedLimiter) = true; GVAR(isSpeedLimiter) = true;
@ -38,21 +42,24 @@ GVAR(speedLimit) = speed _vehicle max 5;
private _uavControll = UAVControl _vehicle; private _uavControll = UAVControl _vehicle;
if ((_uavControll select 0) != _driver || _uavControll select 1 != "DRIVER") then { if ((_uavControll select 0) != _driver || _uavControll select 1 != "DRIVER") then {
GVAR(isSpeedLimiter) = false; GVAR(isSpeedLimiter) = false;
_vehicle setCruiseControl [0, false];
}; };
} else { } else {
if (_driver != driver _vehicle) then { if (_driver != driver _vehicle) then {
GVAR(isSpeedLimiter) = false; GVAR(isSpeedLimiter) = false;
_vehicle setCruiseControl [0, false];
}; };
}; };
if (!GVAR(isSpeedLimiter)) exitWith { if (!GVAR(isSpeedLimiter)) exitWith {
_vehicle setCruiseControl [0, false];
[_idPFH] call CBA_fnc_removePerFrameHandler; [_idPFH] call CBA_fnc_removePerFrameHandler;
}; };
private _speed = speed _vehicle; getCruiseControl _vehicle params ["_currentSpeedLimit"];
if (_currentSpeedLimit != GVAR(speedLimit)) then {
if (_speed > GVAR(speedLimit)) then { _vehicle setCruiseControl [GVAR(speedLimit), false];
_vehicle setVelocity ((velocity _vehicle) vectorMultiply ((GVAR(speedLimit) / _speed) - 0.00001)); // fix 1.42-hotfix PhysX libraries applying force in previous direction when turning
}; };
}, 0, [_driver, _vehicle]] call CBA_fnc_addPerFrameHandler; }, 0, [_driver, _vehicle]] call CBA_fnc_addPerFrameHandler;