From 60cab0af6b64921e530d77c2d1639a6325ba2fb1 Mon Sep 17 00:00:00 2001 From: JoramD Date: Sat, 1 May 2021 05:48:02 +0200 Subject: [PATCH] Parachute - Add failure chance (#8226) * Initial push * disable forgotten define * Improve exitWith check * Requested/suggested changes * Requested changes * Requested changes --- addons/parachute/CfgVehicles.hpp | 1 + addons/parachute/XEH_PREP.hpp | 1 + addons/parachute/XEH_postInit.sqf | 2 ++ addons/parachute/XEH_preInit.sqf | 9 +++++++ .../functions/fnc_handleFailureChance.sqf | 26 +++++++++++++++++++ addons/parachute/stringtable.xml | 3 +++ docs/wiki/framework/parachute-framework.md | 14 +++++++++- 7 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 addons/parachute/functions/fnc_handleFailureChance.sqf diff --git a/addons/parachute/CfgVehicles.hpp b/addons/parachute/CfgVehicles.hpp index 5f1b750377..245d1a73be 100644 --- a/addons/parachute/CfgVehicles.hpp +++ b/addons/parachute/CfgVehicles.hpp @@ -21,6 +21,7 @@ class CfgVehicles { }; }; MACRO_HASRESERVE + GVAR(failureDelay) = 2; }; class ParachuteWest: ParachuteBase { MACRO_HASRESERVE diff --git a/addons/parachute/XEH_PREP.hpp b/addons/parachute/XEH_PREP.hpp index 6edd22c260..916aa1ccdb 100644 --- a/addons/parachute/XEH_PREP.hpp +++ b/addons/parachute/XEH_PREP.hpp @@ -1,4 +1,5 @@ PREP(cutParachute); +PREP(handleFailureChance); PREP(handleInfoDisplayChanged); PREP(handleReserve); PREP(hideAltimeter); diff --git a/addons/parachute/XEH_postInit.sqf b/addons/parachute/XEH_postInit.sqf index 06e02f0757..1217fa3cab 100644 --- a/addons/parachute/XEH_postInit.sqf +++ b/addons/parachute/XEH_postInit.sqf @@ -38,3 +38,5 @@ if (!hasInterface) exitWith {}; // Don't show vanilla speed and height when in expert mode ["ace_infoDisplayChanged", {_this call FUNC(handleInfoDisplayChanged)}] call CBA_fnc_addEventHandler; + +["vehicle", {_this call FUNC(handleFailureChance)}] call CBA_fnc_addPlayerEventHandler; diff --git a/addons/parachute/XEH_preInit.sqf b/addons/parachute/XEH_preInit.sqf index b01263d60b..1ec8ff20d6 100644 --- a/addons/parachute/XEH_preInit.sqf +++ b/addons/parachute/XEH_preInit.sqf @@ -18,4 +18,13 @@ PREP_RECOMPILE_END; {[QGVAR(hideAltimeter), _this, false] call EFUNC(common,cbaSettings_settingChanged)} ] call CBA_fnc_addSetting; +[ + QGVAR(failureChance), + "SLIDER", + LSTRING(FailureChance), + ["ACE Uncategorized", localize "str_dn_parachute"], + [0, 1, 0, 2, true], + 1 +] call CBA_fnc_addSetting; + ADDON = true; diff --git a/addons/parachute/functions/fnc_handleFailureChance.sqf b/addons/parachute/functions/fnc_handleFailureChance.sqf new file mode 100644 index 0000000000..e5ec0b5cde --- /dev/null +++ b/addons/parachute/functions/fnc_handleFailureChance.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: JoramD + * Handles percentage chance parachute failure. + * + * Arguments: + * 0: Unit + * 1: Vehicle + * + * Return Value: + * None + * + * Example: + * [player, vehicle player] call ace_parachute_fnc_handleFailureChance + * + * Public: No + */ + +params ["_unit", "_vehicle"]; + +if !(_vehicle isKindOf "ParachuteBase") exitWith {}; + +if (random 1 < GVAR(failureChance)) then { + private _failureDelay = getNumber (configOf _vehicle >> QGVAR(failureDelay)); + [FUNC(cutParachute), [_unit, _vehicle], _failureDelay] call CBA_fnc_waitAndExecute; +}; diff --git a/addons/parachute/stringtable.xml b/addons/parachute/stringtable.xml index f5c1015425..ff68c14f0e 100644 --- a/addons/parachute/stringtable.xml +++ b/addons/parachute/stringtable.xml @@ -133,5 +133,8 @@ Oculta la altitud y la velocidad que se muestran en caída libre o en paracaídas. Serbest düşme veya paraşütle atlama sırasında gösterilen yüksekliği ve hızı gizler. + + Parachute Failure Chance + diff --git a/docs/wiki/framework/parachute-framework.md b/docs/wiki/framework/parachute-framework.md index 37e522d055..b92e03b023 100644 --- a/docs/wiki/framework/parachute-framework.md +++ b/docs/wiki/framework/parachute-framework.md @@ -16,9 +16,21 @@ version: ```cpp class CfgVehicles { - class BananaParachute { + class ParachuteBase; + class BananaParachute: ParachuteBase { ace_hasReserveParachute = 1; // Add reserve parachute (1-enabled, 0-disabled) ace_reserveParachute = "ACE_ReserveParachute"; // Classname of the reserve parachute }; }; ``` + +## 2. Adding failure cut delay + +```cpp +class CfgVehicles { + class ParachuteBase; + class BananaParachute: ParachuteBase { + ace_parachute_failureDelay = 2; // Add delay before parachute fails (time in seconds) + }; +}; +```