-
Notifications
You must be signed in to change notification settings - Fork 149
/
fnc_waitUntilAndExecute.sqf
64 lines (54 loc) · 2.29 KB
/
fnc_waitUntilAndExecute.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_waitUntilAndExecute
Description:
Executes a code once in unscheduled environment after a condition is true.
It's also possible to add a timeout >= 0, in which case a different code is executed.
Then it will be waited until _timeout time has elapsed or _condition evaluates to true.
Parameters:
_condition - The function to evaluate as condition. <CODE>
_statement - The function to run once the condition is true. <CODE>
_args - Parameters passed to the functions (statement and condition) executing. (optional) <ANY>
_timeout - If >= 0, timeout for the condition in seconds. If < 0, no timeout.
Exactly 0 means timeout immediately on the next iteration.(optional, default -1) <NUMBER>
_timeoutCode - Will execute instead of _statement if the condition times out. (optional) <CODE>
Passed Arguments:
_this - Parameters passed by this function. Same as '_args' above. <ANY>
Returns:
Nothing
Examples:
(begin example)
[{(_this select 0) == vehicle (_this select 0)}, {(_this select 0) setDamage 1;}, [player]] call CBA_fnc_waitUntilAndExecute;
(end)
(begin example)
[{backpackCargo _this isEqualTo []}, {
deleteVehicle _this;
}, _holder, 5, {hint backpackCargo _this;}] call CBA_fnc_waitUntilAndExecute;
(end)
Author:
joko // Jonas, donated from ACE3
---------------------------------------------------------------------------- */
params [
["_condition", {}, [{}]],
["_statement", {}, [{}]],
["_args", []],
["_timeout", -1, [0]],
["_timeoutCode", {}, [{}]]
];
if (_timeout < 0) then {
GVAR(waitUntilAndExecArray) pushBack [_condition, _statement, _args];
} else {
GVAR(waitUntilAndExecArray) pushBack [{
params ["_condition", "_statement", "_args", "_timeout", "_timeoutCode", "_startTime"];
if (CBA_missionTime - _startTime > _timeout) exitWith {
_args call _timeoutCode;
true
};
if (_args call _condition) exitWith {
_args call _statement;
true
};
false
}, {}, [_condition, _statement, _args, _timeout, _timeoutCode, CBA_missionTime]];
};
nil