diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index db068cf1375..f94835a98f7 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -197,6 +197,7 @@ PREP(swayLoop); PREP(switchAttachmentMode); PREP(switchPersistentLaser); PREP(switchToGroupSide); +PREP(temporaryBlockFire); PREP(throttledPublicVariable); PREP(toBin); PREP(toBitmask); diff --git a/addons/common/functions/fnc_temporaryBlockFire.sqf b/addons/common/functions/fnc_temporaryBlockFire.sqf new file mode 100644 index 00000000000..513f6d4d273 --- /dev/null +++ b/addons/common/functions/fnc_temporaryBlockFire.sqf @@ -0,0 +1,34 @@ +#include "..\script_component.hpp" +/* + * Author: PabstMirror + * Temporarily blocks firing of a weapon for player for a specified duration. + * + * Arguments: + * 0: Duration (seconds) (default: 1) + * + * Return Value: + * None + * + * Example: + * [1] call ace_common_fnc_temporaryBlockFire + * + * Public: Yes + */ + +params [["_duration", 1, [0]]]; + +if (!alive ace_player) exitWith {}; +if (!isNil QGVAR(temporaryBlockFireEH)) exitWith {}; // if in-progress temporary block already exists, don't create another one + +private _firedEH = [ACE_player, "DefaultAction", {true}, {true}] call FUNC(addActionEventHandler); +GVAR(temporaryBlockFireEH) = [ace_player, _firedEH]; +TRACE_2("Blocking fire",ace_player,_firedEH); + +[{ + GVAR(temporaryBlockFireEH) params ["_player", "_firedEH"]; + TRACE_2("Unblocking fire",_player,_firedEH); + if (isNull _player) exitWith {}; + [_player, "DefaultAction", _firedEH] call FUNC(removeActionEventHandler); + GVAR(temporaryBlockFireEH) = nil; +}, [], _duration] call CBA_fnc_waitAndExecute; + diff --git a/addons/medical_gui/functions/fnc_menuPFH.sqf b/addons/medical_gui/functions/fnc_menuPFH.sqf index 0e213eaf5ec..e4594c57a49 100644 --- a/addons/medical_gui/functions/fnc_menuPFH.sqf +++ b/addons/medical_gui/functions/fnc_menuPFH.sqf @@ -27,6 +27,8 @@ if !( [[ELSTRING(medical,DistanceToFar), GVAR(target) call EFUNC(common,getName)], 2] call EFUNC(common,displayTextStructured); }; + + [0.5] call EFUNC(common,temporaryBlockFire); // prevent firing from sudden menu closure }; // Get the Medical Menu display