diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index 17478a755..9366f9803 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 000000000..3c141e72c --- /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 c81cc92b9..e0b2b00ee 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)