diff --git a/addons/attributes/initAttributes.sqf b/addons/attributes/initAttributes.sqf index d74dfd1f8..18cf5e953 100644 --- a/addons/attributes/initAttributes.sqf +++ b/addons/attributes/initAttributes.sqf @@ -83,6 +83,54 @@ {GVAR(enableAmmo) && {alive _entity} && {_entity call EFUNC(common,getVehicleAmmo) != -1}} ] call FUNC(addAttribute); +[ // Helicopter + "Object", + [ELSTRING(Modules,ModuleConvoyParameters_Speed), LSTRING(SpeedLimit_Tooltip_Helicopter)], + QGVAR(slider), + [-50, 300, 5, false, 0], + { + private _vehicles = [] call EFUNC(common,getSelectedVehicles) select { + alive _x && {!isPlayer driver _x} && {_x isKindOf "Helicopter"} + }; + { _x setVariable [QGVAR(speedLimit), _value, true]; } forEach _vehicles; + [QEGVAR(common,setSpeedLimit), [_vehicles, _value], _vehicles] call CBA_fnc_targetEvent; + }, + {_entity getVariable [QGVAR(speedLimit), 0]}, + {GVAR(enableSpeedLimit) && {alive _entity} && {!isPlayer driver _entity} && {_entity isKindOf "Helicopter"}} +] call FUNC(addAttribute); + +[ // LandVehicle and Ship + "Object", + [ELSTRING(Modules,ModuleConvoyParameters_Speed), LSTRING(SpeedLimit_Tooltip)], + QGVAR(slider), + [0, 100, 5, false, 0], + { + private _vehicles = [] call EFUNC(common,getSelectedVehicles) select { + alive _x && {!isPlayer driver _x} && {_x isKindOf "LandVehicle" || {_x isKindOf "Ship"}} + }; + { _x setVariable [QGVAR(speedLimit), _value, true]; } forEach _vehicles; + [QEGVAR(common,setSpeedLimit), [_vehicles, _value], _vehicles] call CBA_fnc_targetEvent; + }, + {_entity getVariable [QGVAR(speedLimit), 0]}, + {GVAR(enableSpeedLimit) && {alive _entity} && {!isPlayer driver _entity} && {_entity isKindOf "LandVehicle" || {_entity isKindOf "Ship"}}} +] call FUNC(addAttribute); + +[ // Plane + "Object", + [ELSTRING(Modules,ModuleConvoyParameters_Speed), LSTRING(SpeedLimit_Tooltip)], + QGVAR(slider), + [0, 1000, 5, false, 0], + { + private _vehicles = [] call EFUNC(common,getSelectedVehicles) select { + alive _x && {!isPlayer driver _x} && {_x isKindOf "Plane"} + }; + { _x setVariable [QGVAR(speedLimit), _value, true]; } forEach _vehicles; + [QEGVAR(common,setSpeedLimit), [_vehicles, _value], _vehicles] call CBA_fnc_targetEvent; + }, + {_entity getVariable [QGVAR(speedLimit), 0]}, + {GVAR(enableSpeedLimit) && {alive _entity} && {!isPlayer driver _entity} && {_entity isKindOf "Plane"}} +] call FUNC(addAttribute); + [ "Object", "STR_3DEN_Object_Attribute_Rank_displayName", diff --git a/addons/attributes/initSettings.sqf b/addons/attributes/initSettings.sqf index 960270a9f..1ccbaf719 100644 --- a/addons/attributes/initSettings.sqf +++ b/addons/attributes/initSettings.sqf @@ -45,6 +45,15 @@ false ] call CBA_fnc_addSetting; +[ + QGVAR(enableSpeedLimit), + "CHECKBOX", + ELSTRING(Modules,ModuleConvoyParameters_Speed), + [LSTRING(DisplayName), "STR_3DEN_Object_textPlural"], + true, + false +] call CBA_fnc_addSetting; + [ QGVAR(enableRank), "CHECKBOX", diff --git a/addons/attributes/stringtable.xml b/addons/attributes/stringtable.xml index 30b57de13..b94092a84 100644 --- a/addons/attributes/stringtable.xml +++ b/addons/attributes/stringtable.xml @@ -121,6 +121,12 @@ 狀態 Stati + + Limit the maximum speed of the vehicle in km/h. Set to 0 to remove limit. + + + Limit the maximum speed of the vehicle in km/h. Set to 0 to remove limit. AI helicopters will fly in reverse. + Local Exec. This code will be executed in the unscheduled environment on this machine only. Lokale Ausführung. Dieser Code wird in der unscheduled Environment für nur die lokale Maschine ausgeführt. diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 1754d7b7c..bda2aa67c 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -67,6 +67,7 @@ PREP(serializeInventory); PREP(serializeObjects); PREP(setLampState); PREP(setMagazineAmmo); +PREP(setSpeedLimit); PREP(setTurretAmmo); PREP(setVehicleAmmo); PREP(setVehicleLaserState); diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index eaf9c38ab..8881e5bfc 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -229,6 +229,11 @@ _vehicle limitSpeed _speed; }] call CBA_fnc_addEventHandler; +[QGVAR(forceSpeed), { + params ["_vehicle", "_speed"]; + _vehicle forceSpeed _speed; +}] call CBA_fnc_addEventHandler; + [QGVAR(forceFollowRoad), { params ["_vehicle", "_mode"]; _vehicle forceFollowRoad _mode; @@ -350,6 +355,7 @@ [QGVAR(loadMagazineInstantly), LINKFUNC(loadMagazineInstantly)] call CBA_fnc_addEventHandler; [QGVAR(setLampState), LINKFUNC(setLampState)] call CBA_fnc_addEventHandler; [QGVAR(setMagazineAmmo), LINKFUNC(setMagazineAmmo)] call CBA_fnc_addEventHandler; +[QGVAR(setSpeedLimit), LINKFUNC(setSpeedLimit)] call CBA_fnc_addEventHandler; [QGVAR(setTurretAmmo), LINKFUNC(setTurretAmmo)] call CBA_fnc_addEventHandler; [QGVAR(setVehicleLaserState), LINKFUNC(setVehicleLaserState)] call CBA_fnc_addEventHandler; [QGVAR(showMessage), LINKFUNC(showMessage)] call CBA_fnc_addEventHandler; diff --git a/addons/common/functions/fnc_setSpeedLimit.sqf b/addons/common/functions/fnc_setSpeedLimit.sqf new file mode 100644 index 000000000..91870ffc7 --- /dev/null +++ b/addons/common/functions/fnc_setSpeedLimit.sqf @@ -0,0 +1,54 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Sets the movement speed mode of the given vehicle(s). + * + * Arguments: + * 0: Vehicle + * 1: Speed (default: 0) + * Man: Speed modes + * Vehicles: km/h + * + * 2.12 | forceSpeed | limitSpeed + * _speed | neg zero pos | neg zero pos -(_man getSpeed "SLOW") + * -------|-------------------------|--------------------------------------------------------------------- + * man | reset stop yes | reset stop yes reverse, doesn't work if combat mode + * car | reset stop yes | reset reset yes + * tank | reset stop yes | reset reset yes + * heli | no-eff no-eff no-eff | reverse stop yes + * plane | reset reset yes | min min yes + * vtol | reset reset yes | min min yes + * boat | reset stop yes | reset stop yes + * + * Return Value: + * None + * + * Example: + * [_vehicle, 1] call zen_common_fnc_setSpeedLimit + * + * Public: No + */ + +params ["_vehicle", "_speed"]; + +if (_vehicle isEqualType []) exitWith { + { + [_x, _speed] call FUNC(setSpeedLimit); + } forEach _vehicle; +}; + +if (!local _vehicle) exitWith {}; + +if (_vehicle isKindOf "Helicopter") exitWith { + if (_speed == 0) exitWith { + _vehicle limitSpeed (getNumber (configOf _vehicle >> "maxSpeed")); // Reset + }; + _vehicle limitSpeed _speed; // Allow reverse +}; + +// Planes, LandVehicle, Ship +if (_speed == 0) then { + _speed = -1; // Reset +}; + +_vehicle forceSpeed (_speed / 3.6);