2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-08-04 02:49:56 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* Toggle speed limiter for Driver in Vehicle.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Driver <OBJECT>
|
|
|
|
* 1: Vehicle <OBJECT>
|
2022-03-17 18:06:32 +00:00
|
|
|
* 2: Cruise Control <BOOL>
|
2023-06-28 14:17:14 +00:00
|
|
|
* 3: Preserve Speed Limit <BOOL>
|
2015-08-04 02:49:56 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2022-03-17 18:06:32 +00:00
|
|
|
* [player, car, true] call ace_vehicles_fnc_speedLimiter
|
2015-08-04 02:49:56 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2023-06-28 14:17:14 +00:00
|
|
|
params ["_driver", "_vehicle", ["_cruiseControl", false], ["_preserveSpeedLimit", false]];
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2015-11-27 14:48:03 +00:00
|
|
|
if (GVAR(isSpeedLimiter)) exitWith {
|
2022-03-17 18:06:32 +00:00
|
|
|
switch ([GVAR(isCruiseControl), _cruiseControl]) do {
|
|
|
|
case [true, true]: {
|
|
|
|
[localize LSTRING(OffCruise)] call EFUNC(common,displayTextStructured);
|
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
_vehicle setCruiseControl [0, false];
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
case [true, false]: {
|
|
|
|
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
_vehicle setCruiseControl [GVAR(speedLimit), false];
|
|
|
|
GVAR(isCruiseControl) = false;
|
|
|
|
};
|
|
|
|
case [false, true]: {
|
|
|
|
[localize LSTRING(OnCruise)] call EFUNC(common,displayTextStructured);
|
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
_vehicle setCruiseControl [GVAR(speedLimit), true];
|
|
|
|
GVAR(isCruiseControl) = true;
|
|
|
|
};
|
|
|
|
case [false, false]: {
|
|
|
|
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
|
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
_vehicle setCruiseControl [0, false];
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
};
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
|
|
|
|
2021-10-13 21:58:09 +00:00
|
|
|
(getCruiseControl _vehicle) params ["_speedLimit"];
|
|
|
|
if (_speedLimit != 0) exitWith { TRACE_1("speed limit set by external source",_speedLimit); };
|
|
|
|
|
2022-03-17 18:06:32 +00:00
|
|
|
[localize (
|
|
|
|
[LSTRING(On), LSTRING(OnCruise)] select _cruiseControl
|
|
|
|
)] call EFUNC(common,displayTextStructured);
|
2015-01-16 13:20:41 +00:00
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
GVAR(isSpeedLimiter) = true;
|
2022-03-17 18:06:32 +00:00
|
|
|
GVAR(isCruiseControl) = _cruiseControl;
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2023-06-28 14:17:14 +00:00
|
|
|
if (!_preserveSpeedLimit) then {
|
|
|
|
GVAR(speedLimit) = round (speed _vehicle max 5);
|
|
|
|
};
|
2022-03-17 18:06:32 +00:00
|
|
|
GVAR(speedLimitInit) = true;
|
2015-01-16 13:20:41 +00:00
|
|
|
|
|
|
|
[{
|
2015-08-04 02:49:56 +00:00
|
|
|
params ["_args", "_idPFH"];
|
2018-07-05 16:32:40 +00:00
|
|
|
_args params ["_driver", "_vehicle"];
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2023-06-28 14:17:14 +00:00
|
|
|
private _role = _driver call EFUNC(common,getUavControlPosition);
|
2015-11-26 22:39:17 +00:00
|
|
|
if (GVAR(isUAV)) then {
|
2023-06-28 14:17:14 +00:00
|
|
|
if (_role == "") then {
|
2015-11-26 22:39:17 +00:00
|
|
|
GVAR(isSpeedLimiter) = false;
|
2023-06-28 14:17:14 +00:00
|
|
|
TRACE_1("UAV controller changed, disabling speedlimit",_vehicle);
|
2015-11-26 22:39:17 +00:00
|
|
|
};
|
|
|
|
} else {
|
2023-06-28 14:17:14 +00:00
|
|
|
if (_driver != driver _vehicle || {_role != ""}) then {
|
2015-11-26 22:39:17 +00:00
|
|
|
GVAR(isSpeedLimiter) = false;
|
2021-10-28 14:03:09 +00:00
|
|
|
TRACE_3("Vehicle driver changed, disabling speedlimit",_driver,driver _vehicle,_vehicle);
|
2015-11-26 22:39:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-06-28 14:17:14 +00:00
|
|
|
if (call CBA_fnc_getActiveFeatureCamera != "") then {
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
|
2015-11-26 22:39:17 +00:00
|
|
|
if (!GVAR(isSpeedLimiter)) exitWith {
|
2021-10-13 21:58:09 +00:00
|
|
|
_vehicle setCruiseControl [0, false];
|
2015-08-04 02:49:56 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
|
|
|
|
2022-03-17 18:06:32 +00:00
|
|
|
getCruiseControl _vehicle params ["_currentSpeedLimit", "_cruiseControlActive"];
|
|
|
|
if (GVAR(isCruiseControl) && {!GVAR(speedLimitInit) && {!_cruiseControlActive}}) exitWith {
|
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
[localize LSTRING(OffCruise)] call EFUNC(common,displayTextStructured);
|
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
};
|
2021-10-28 14:03:09 +00:00
|
|
|
if (round _currentSpeedLimit != GVAR(speedLimit)) then {
|
|
|
|
TRACE_2("Updating speed limit",GVAR(speedLimit),_vehicle);
|
2022-03-17 18:06:32 +00:00
|
|
|
_vehicle setCruiseControl [GVAR(speedLimit), GVAR(isCruiseControl)];
|
|
|
|
GVAR(speedLimitInit) = false;
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
2018-07-05 16:32:40 +00:00
|
|
|
}, 0, [_driver, _vehicle]] call CBA_fnc_addPerFrameHandler;
|