Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add speed limit attribute #699

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
48 changes: 48 additions & 0 deletions addons/attributes/initAttributes.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions addons/attributes/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions addons/attributes/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
<Chinese>狀態</Chinese>
<Italian>Stati</Italian>
</Key>
<Key ID="STR_ZEN_Attributes_SpeedLimit_Tooltip">
<English>Limit the maximum speed of the vehicle in km/h. Set to 0 to remove limit.</English>
</Key>
<Key ID="STR_ZEN_Attributes_SpeedLimit_Tooltip_Helicopter">
<English>Limit the maximum speed of the vehicle in km/h. Set to 0 to remove limit. AI helicopters will fly in reverse.</English>
</Key>
<Key ID="STR_ZEN_Attributes_LocalExec">
<English>Local Exec. This code will be executed in the unscheduled environment on this machine only.</English>
<German>Lokale Ausführung. Dieser Code wird in der unscheduled Environment für nur die lokale Maschine ausgeführt.</German>
Expand Down
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ PREP(serializeInventory);
PREP(serializeObjects);
PREP(setLampState);
PREP(setMagazineAmmo);
PREP(setSpeedLimit);
PREP(setTurretAmmo);
PREP(setVehicleAmmo);
PREP(setVehicleLaserState);
Expand Down
6 changes: 6 additions & 0 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
54 changes: 54 additions & 0 deletions addons/common/functions/fnc_setSpeedLimit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Sets the movement speed mode of the given vehicle(s).
*
* Arguments:
* 0: Vehicle <OBJECT|ARRAY>
* 1: Speed <NUMBER> (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);
Loading