ACE3/addons/common/functions/fnc_waitAndExecute.sqf

37 lines
968 B
Plaintext
Raw Normal View History

2015-01-17 05:58:24 +00:00
/*
2015-03-24 04:18:00 +00:00
* Author: esteldunedain
2015-01-17 05:58:24 +00:00
*
* Executes a code once with a given game time delay, using a PFH
*
* Argument:
* 0: Code to execute (Code)
2015-01-17 05:58:24 +00:00
* 1: Parameters to run the code with (Array)
* 2: Delay in seconds before executing the code (Number)
* 3: Interval of time in which the execution is evaluated, 0 means every frame (Number)
*
* Return value:
* PFH handler ID
*/
#include "script_component.hpp"
EXPLODE_4_PVT(_this,_func,_params,_delay,_interval);
[
{
2015-01-17 16:45:56 +00:00
EXPLODE_2_PVT(_this,_params,_pfhId);
2015-01-17 05:58:24 +00:00
EXPLODE_2_PVT(_params,_delayedExecParams,_startTime);
EXPLODE_3_PVT(_delayedExecParams,_func,_funcParams,_delay);
// Exit if the time was not reached yet
if (time < _startTime + _delay) exitWith {};
// Remove the PFH
[_pfhId] call cba_fnc_removePerFrameHandler;
// Execute the function
_funcParams call _func;
},
_interval,
[_this, time]
2015-01-17 16:56:24 +00:00
] call CBA_fnc_addPerFrameHandler