2018-09-17 19:19:29 +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>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player, car] call ace_vehicles_fnc_speedLimiter
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2015-08-04 02:49:56 +00:00
|
|
|
params ["_driver", "_vehicle"];
|
2015-01-16 13:20:41 +00:00
|
|
|
|
2015-11-27 14:48:03 +00:00
|
|
|
if (GVAR(isSpeedLimiter)) exitWith {
|
2015-05-28 19:59:04 +00:00
|
|
|
[localize LSTRING(Off)] call EFUNC(common,displayTextStructured);
|
2015-01-16 13:20:41 +00:00
|
|
|
playSound "ACE_Sound_Click";
|
2021-10-13 21:58:09 +00:00
|
|
|
_vehicle setCruiseControl [0, false];
|
2015-01-16 13:20:41 +00:00
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
|
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); };
|
|
|
|
|
2015-05-28 19:59:04 +00:00
|
|
|
[localize LSTRING(On)] call EFUNC(common,displayTextStructured);
|
2015-01-16 13:20:41 +00:00
|
|
|
playSound "ACE_Sound_Click";
|
|
|
|
GVAR(isSpeedLimiter) = true;
|
|
|
|
|
2021-10-28 14:03:09 +00:00
|
|
|
GVAR(speedLimit) = round (speed _vehicle max 5);
|
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
|
|
|
|
2015-11-26 22:39:17 +00:00
|
|
|
if (GVAR(isUAV)) then {
|
|
|
|
private _uavControll = UAVControl _vehicle;
|
2015-11-27 14:48:03 +00:00
|
|
|
if ((_uavControll select 0) != _driver || _uavControll select 1 != "DRIVER") then {
|
2015-11-26 22:39:17 +00:00
|
|
|
GVAR(isSpeedLimiter) = false;
|
2021-10-28 14:03:09 +00:00
|
|
|
TRACE_1("UAV driver changed, disabling speedlimit",_vehicle);
|
2021-10-13 21:58:09 +00:00
|
|
|
_vehicle setCruiseControl [0, false];
|
2015-11-26 22:39:17 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_driver != driver _vehicle) then {
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
2021-10-28 14:03:09 +00:00
|
|
|
TRACE_3("Vehicle driver changed, disabling speedlimit",_driver,driver _vehicle,_vehicle);
|
2021-10-13 21:58:09 +00:00
|
|
|
_vehicle setCruiseControl [0, 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
|
|
|
};
|
|
|
|
|
2021-10-13 21:58:09 +00:00
|
|
|
getCruiseControl _vehicle params ["_currentSpeedLimit"];
|
2021-10-28 14:03:09 +00:00
|
|
|
if (round _currentSpeedLimit != GVAR(speedLimit)) then {
|
|
|
|
TRACE_2("Updating speed limit",GVAR(speedLimit),_vehicle);
|
2021-10-13 21:58:09 +00:00
|
|
|
_vehicle setCruiseControl [GVAR(speedLimit), false];
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
|
|
|
|
2021-10-13 21:58:09 +00:00
|
|
|
|
2018-07-05 16:32:40 +00:00
|
|
|
}, 0, [_driver, _vehicle]] call CBA_fnc_addPerFrameHandler;
|