diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index bf699ab83c..e57dab3521 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -3,9 +3,9 @@ //IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent"); -//Singe PFEH to handle execNextFrame and waitAndExec: +//Singe PFEH to handle execNextFrame, waitAndExec and waitUntilAndExec: [{ - private ["_entry"]; + private ["_entry", "_deleted"]; //Handle the waitAndExec array: while {((count GVAR(waitAndExecArray)) > 0) && {((GVAR(waitAndExecArray) select 0) select 0) <= ACE_Time}} do { @@ -17,6 +17,18 @@ { (_x select 0) call (_x select 1); } forEach GVAR(nextFrameBufferA); + + + _deleted = 0; + { + _x params ["_condition", "_code", "_args"]; + if ((_args call _condition)) then { + GVAR(waitUntilAndExecArray) deleteAt (_forEachIndex + _deleted); + _deleted = _deleted + 1; + _args call _code; + }; + } forEach GVAR(waitUntilAndExecArray); + //Swap double-buffer: GVAR(nextFrameBufferA) = GVAR(nextFrameBufferB); GVAR(nextFrameBufferB) = []; diff --git a/addons/common/functions/fnc_waitUnilAndExecute.sqf b/addons/common/functions/fnc_waitUnilAndExecute.sqf new file mode 100644 index 0000000000..de4623b4ae --- /dev/null +++ b/addons/common/functions/fnc_waitUnilAndExecute.sqf @@ -0,0 +1,22 @@ +/* + * Author: joko // Jonas + * + * Executes a code once with after the Condition is True, using a PFH + * + * Argument: + * 0: Condition + * 1: Code to execute + * 2: Parameters to run the code with + + * + * Return value: + * None + * + * Example: + * [{(_this select 0) == vehicle (_this select 0)}, {(_this select 0) setDamage 1;}, [ACE_player], false] call ace_common_fnc_waitAndExecute + * + * Public: No + */ +#include "script_component.hpp" + +GVAR(waitUntilAndExecArray) pushBack _this;