From 263286f95453697bfb296937cb1a896c7885e682 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:44:59 +0200 Subject: [PATCH] Common - Added CBA_fnc_execAfterNFrames from ZEN (#1584) * Added n frame delay * Revert "Added n frame delay" This reverts commit 50df691493ff87b89d5971ff74619d71f68ccd83. * Added function from ZEN * Update addons/common/fnc_execAfterNFrames.sqf Co-authored-by: PabstMirror * Update fnc_execNextFrame.sqf --------- Co-authored-by: PabstMirror --- addons/common/CfgFunctions.hpp | 1 + addons/common/fnc_execAfterNFrames.sqf | 35 ++++++++++++++++++++++++++ addons/common/fnc_execNextFrame.sqf | 4 +-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 addons/common/fnc_execAfterNFrames.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 17478a7557..9366f9803d 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -131,6 +131,7 @@ class CfgFunctions { PATHTO_FNC(directCall); PATHTO_FNC(objectRandom); PATHTO_FNC(execNextFrame); + PATHTO_FNC(execAfterNFrames); PATHTO_FNC(waitAndExecute); PATHTO_FNC(waitUntilAndExecute); PATHTO_FNC(compileFinal); diff --git a/addons/common/fnc_execAfterNFrames.sqf b/addons/common/fnc_execAfterNFrames.sqf new file mode 100644 index 0000000000..3c141e72ca --- /dev/null +++ b/addons/common/fnc_execAfterNFrames.sqf @@ -0,0 +1,35 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_execAfterNFrames + +Description: + Executes the given code after the specified number of frames. + +Parameters: + _function - The function to run. + _args - Parameters passed to the function executing. This will be the same array every execution. (optional, default: []) + _frames - The amount of frames the execution of the function should be delayed by. (optional, default: 0) + +Returns: + Nothing Useful + +Examples: + (begin example) + [{hint "Done!"}, [], 5] call cba_fnc_execAfterNFrames; + (end) + +Author: + mharis001, donated from ZEN +---------------------------------------------------------------------------- */ + +if (canSuspend) exitWith { + [CBA_fnc_execAfterNFrames, _this] call CBA_fnc_directCall; +}; + +params [["_function", {}, [{}]], ["_args", []], ["_frames", 0, [0]]]; + +if (_frames > 0) exitWith { + [CBA_fnc_execAfterNFrames, [_function, _args, _frames - 1]] call CBA_fnc_execNextFrame; +}; + +_args call _function; diff --git a/addons/common/fnc_execNextFrame.sqf b/addons/common/fnc_execNextFrame.sqf index c81cc92b9f..e0b2b00eef 100644 --- a/addons/common/fnc_execNextFrame.sqf +++ b/addons/common/fnc_execNextFrame.sqf @@ -7,10 +7,10 @@ Description: Parameters: _function - The function to run. - _args - Parameters passed to the function executing. This will be the same array every execution. [optional] + _args - Parameters passed to the function executing. This will be the same array every execution. (optional, default: []) Returns: - Nothing + Nothing Useful Examples: (begin example)