So I was teaching myself particles when a couple of params in particle array caught my attention, mainly the onTimerScript and beforeDestroyScript. After a few hours and a dozen of experiments let me amaze you too! If you remember I have already used an unorthodox solution to absent dedicated timer functionality in Arma by using triggers. Well this new method actually beats triggers in both efficiency and flexibility. You can run both, a timeout and an interval process at the same time.

The major disadvantage of this method lies in inability to call a function or run script directly from particle array param. It only accepts script file name, which gets execVMed. I do not like scheduled environment because it could be lagging and unpredictable in general, however if you delegate non critical tasks to execVMed functions, this should be ok. Besides, it is probably better to forcefully make some scripts to run in scheduled environment to ensure smooth engine functionality. It is like bricks and mortar, bricks are being the non-scheduled tasks and mortar is being scheduled in a sense.

But enough with metaphors already, let’s look at the function:

KK_fnc_setTimeoutIntervalFile = { drop [ ["\A3\data_f\ParticleEffects\Universal\Universal",16,0,0,0],"", "Billboard",_this select 3,_this select 1,[0,0,0],[0,0,0],0,0,0,0,[0,0], [[0,0,0,0],[0,0,0,0]],[0,0],0,0,_this select 2,_this select 0,player ]; };

Passed param array:

  • [timeoutScript, timeout, intervalScript, interval]
  • timeoutScript – file name relative to mission directory
  • timeout – time in seconds after which timeoutScript is executed and timer is deleted
  • intervalScript – file name relative to mission directory
  • interval – frequency with which intervalScript is executed. When timer is deleted upon finished timeout, interval exec will also stop.

Return: Nothing

Examples:

Call “myScript.sqf” every 2.5 seconds for 10 seconds (including the last call @10 seconds):

["myScript.sqf", 10, "myScript.sqf", 2.5] call KK_fnc_setTimeoutIntervalFile;

Call “myScript.sqf” after 25 seconds delay:

["myScript.sqf", 25, "", 0] call KK_fnc_setTimeoutIntervalFile;

Call “myScript.sqf” every second for a very, very long time:

["", 1e39, "myScript.sqf", 1] call KK_fnc_setTimeoutIntervalFile;

Call “myScript.sqf” every second, then after 60 seconds call different script “myScriptEnd.sqf”:

["myScriptEnd.sqf", 60, "myScript.sqf", 1] call KK_fnc_setTimeoutIntervalFile;

Neat, right? But as you have already noticed once a function is called it cannot be cancelled and it also has limited duration no matter how long. Let’s rectify this with an improved function for interval using slightly different approach:

KK_fnc_setIntervalFile = { private "_timer"; _timer = "#particlesource" createVehicleLocal position player; _timer setParticleParams [ ["\A3\data_f\ParticleEffects\Universal\Universal",16,0,0,0], "","Billboard",0,0,[0,0,0],[0,0,0],0,0,0,0,[0,0], [[0,0,0,0],[0,0,0,0]],[0,0],0,0,"",_this select 0,player ]; _timer setDropInterval (_this select 1); _timer };

The advantage of this function is that it returns reference to the timer, meaning it can be deleted. It also executes file straight from the start unlike with previous function.

Passed param array:

  • [intervalScript, interval]
  • intervalScript – file name relative to mission directory
  • interval – frequency with which intervalScript is executed.

Return: Timer object

Example:

Run “myScript.sqf” every second forever:

timer = ["myScript.sqf", 1] call KK_fnc_setIntervalFile;

Making setTimeoutFile function in similar way is a bit different and the resulting function will need some additional managing:

KK_fnc_setTimeoutFile = { private "_timer"; _timer = "#particlesource" createVehicleLocal position player; _timer setParticleParams [ ["\A3\data_f\ParticleEffects\Universal\Universal",16,0,0,0], "","Billboard",0,_this select 1,[0,0,0],[0,0,0],0,0,0,0,[0,0], [[0,0,0,0],[0,0,0,0]],[0,0],0,0,"",_this select 0,player ]; _timer setDropInterval 1e39; _timer setVariable ["#Expires", (_this select 1) + time]; _timer };

The clear advantage is returned timer object and ability to cancel timeout before it expires. I’ve also assigned the timer object a variable with approximate end time “#Expires” so that one can get an idea how long before assigned script is executed. Important thing is that timer object will continue to exist for a very long time after timeout is over. This will require the timeout script to take care of the timer object and delete it after the script is done.

Passed param array:

  • [timeoutScript, timeout]
  • timeoutScript – file name relative to mission director
  • timeout – time in seconds after which timeoutScript is executed

Return: Timer object

Example:

Run “myScript.sqf” after 30 seconds:

timer = ["myScript.sqf", 30] call KK_fnc_setTimeoutFile;

Enjoy,
KK