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
|
|
|
#include "script_component.hpp"
|
|
|
|
|
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";
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _maxSpeed = speed _vehicle max 10;
|
2015-01-16 13:20:41 +00:00
|
|
|
|
|
|
|
[{
|
2015-08-04 02:49:56 +00:00
|
|
|
params ["_args", "_idPFH"];
|
|
|
|
_args params ["_driver", "_vehicle", "_maxSpeed"];
|
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;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (_driver != driver _vehicle) then {
|
|
|
|
GVAR(isSpeedLimiter) = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!GVAR(isSpeedLimiter)) exitWith {
|
2015-08-04 02:49:56 +00:00
|
|
|
[_idPFH] call CBA_fnc_removePerFrameHandler;
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
|
|
|
|
2016-01-06 21:42:02 +00:00
|
|
|
private _speed = speed _vehicle;
|
2015-01-16 13:20:41 +00:00
|
|
|
|
|
|
|
if (_speed > _maxSpeed) then {
|
2015-04-18 15:42:13 +00:00
|
|
|
_vehicle setVelocity ((velocity _vehicle) vectorMultiply ((_maxSpeed / _speed) - 0.00001)); // fix 1.42-hotfix PhysX libraries applying force in previous direction when turning
|
2015-01-16 13:20:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} , 0, [_driver, _vehicle, _maxSpeed]] call CBA_fnc_addPerFrameHandler;
|