From 20fb895b318759e45ca4ad314238573c98224abe Mon Sep 17 00:00:00 2001 From: Dystopian Date: Mon, 29 Aug 2022 03:24:24 +0300 Subject: [PATCH] Towing - Add rope to vehicle inventory (#8963) * Add rope to vehicle inventory * Use LINKFUNC * Make setting not need restart Co-authored-by: PabstMirror Co-authored-by: PabstMirror --- addons/towing/XEH_PREP.hpp | 1 + addons/towing/XEH_preInit.sqf | 2 ++ .../towing/functions/fnc_addRopeToVehicle.sqf | 27 +++++++++++++++++++ addons/towing/initSettings.sqf | 13 +++++++++ addons/towing/stringtable.xml | 4 +++ 5 files changed, 47 insertions(+) create mode 100644 addons/towing/functions/fnc_addRopeToVehicle.sqf create mode 100644 addons/towing/initSettings.sqf diff --git a/addons/towing/XEH_PREP.hpp b/addons/towing/XEH_PREP.hpp index f3937e01c3..d26b29e5f0 100644 --- a/addons/towing/XEH_PREP.hpp +++ b/addons/towing/XEH_PREP.hpp @@ -1,3 +1,4 @@ +PREP(addRopeToVehicle); PREP(attachRopePFH); PREP(canStartTow); PREP(detach); diff --git a/addons/towing/XEH_preInit.sqf b/addons/towing/XEH_preInit.sqf index b47cf6628d..9361d05015 100644 --- a/addons/towing/XEH_preInit.sqf +++ b/addons/towing/XEH_preInit.sqf @@ -6,4 +6,6 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +#include "initSettings.sqf" + ADDON = true; diff --git a/addons/towing/functions/fnc_addRopeToVehicle.sqf b/addons/towing/functions/fnc_addRopeToVehicle.sqf new file mode 100644 index 0000000000..09f9f03b6c --- /dev/null +++ b/addons/towing/functions/fnc_addRopeToVehicle.sqf @@ -0,0 +1,27 @@ +#include "script_component.hpp" +/* + * Author: Dystopian + * Adds rope to vehicle inventory. + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * None + * + * Example: + * cursorObject call ace_towing_fnc_addRopeToVehicle + * + * Public: No + */ + +if (!GVAR(addRopeToVehicleInventory)) exitWith {}; +params ["_vehicle"]; + +if (0 == getNumber (configOf _vehicle >> QEGVAR(cargo,hasCargo))) exitWith {}; + +private _ropeType = if ( + -1 < ["Tank", "Wheeled_APC_F", "Truck_F"] findIf {_vehicle isKindOf _x} +) then {"ACE_rope12"} else {"ACE_rope6"}; + +_vehicle addItemCargoGlobal [_ropeType, 1]; diff --git a/addons/towing/initSettings.sqf b/addons/towing/initSettings.sqf new file mode 100644 index 0000000000..8361dccccd --- /dev/null +++ b/addons/towing/initSettings.sqf @@ -0,0 +1,13 @@ +[ + QGVAR(addRopeToVehicleInventory), "CHECKBOX", + LSTRING(Setting_addRopeToVehicleInventory_DisplayName), + LELSTRING(OptionsMenu,CategoryLogistics), + true, + true, + { + if !(_this && {isServer} && {isNil QGVAR(addRopeToVehicleInventory_initialized)}) exitWith {}; + GVAR(addRopeToVehicleInventory_initialized) = true; + ["Tank", "initPost", LINKFUNC(addRopeToVehicle), true, [], true] call CBA_fnc_addClassEventHandler; + ["Car", "initPost", LINKFUNC(addRopeToVehicle), true, [], true] call CBA_fnc_addClassEventHandler; + } +] call CBA_fnc_addSetting; diff --git a/addons/towing/stringtable.xml b/addons/towing/stringtable.xml index 3f619f8ac5..2c0f37ed38 100644 --- a/addons/towing/stringtable.xml +++ b/addons/towing/stringtable.xml @@ -111,5 +111,9 @@ 解开牵引绳 견인줄 분리 + + Add Tow Rope to Vehicle Inventory + Добавить буксировочный трос в инвентарь машин +