//Bleeding, poisoning, for loop //test = [] execVM "script.sqf"; for [{_i = 0}, {_i < 6}, {_i = _i + 1}] do { player setDamage (damage player + 0.05); sleep 5; }; //Alternate syntax for "_i" from 0 to 5 step 1 do { player setDamage (damage player + 0.05); sleep 5; }; //For loops are similar to while..., but work on a different principle. I will talk about them some time later. //Poisoning while loop //test = [unitName] execVM "script.sqf"; while {damage _this < 0.9} do { _this setDamage (damage _this + 0.05); }; //Loop without pause can CRASH THE GAME while {true} do { hint "This will crash your game, don't use!"; }; //All loops should have a sleep command, //or repeat a small amount of times. //Loop with a minimal pause is OK. while {true} do { hint "This doesn't crash the game by itself."; sleep 0.1; }; //Wrong sleep placement _target = _this select 0; while {alive _target} do { sleep 60; systemChat str position _target; }; //Much better sleep placement _target = _this select 0; while {alive _target} do { systemChat str position _target; sleep 60; }; //Another alternative, but uses more commands and process time _target = _this select 0; while {alive _target} do { sleep 60; if (alive _target) then {systemChat str position _target}; }; //We are checking for the same condition twice. //Another alternative, but is highly inefficient. _target = _this select 0; _count = 0; while {alive _target} do { sleep 1; if (_count == 60) then { systemChat str position _target; _count = 0; }; _count = _count + 1; }; //The game needs to process a lot more and repeats the calculation //every second instead of being inactive for 60 seconds. //Loop count _target = _this select 0; _count = 0; while {_count < 1000} do { hintSilent str _count; sleep 0.1; }; //The same can be written with For _target = _this select 0; for "_i" from 0 to 999 step 1 do { hintSilent str _count; sleep 0.1; }; //Jump out of a loop while {alive player} do { if (damage player > 0.2) exitWith {}; sleep 1; }; hint "Loop ended."; //Endless loop while {true} do { //code sleep 1; }; //Endless loop v.2 while {1 > 0} do { //code sleep 1; }; //Endless loop v.3 - unnecessarily complicated condition while {(cos direction player < 999) || position player select 1 < 999999999} do { //code sleep 1; }; //Zombie script example /* Calls the script and influences all units that aren't BLUFOR {if (side _x != west) then {null = [_x] execVM "zombie.sqf"}} foreach allunits; */ //script itself, save as zombie.sqf _fex_fn_hint = { while {alive player} do { waitUntil {spotted}; hint "You have been spotted!"; sleep 3; waitUntil {!spotted}; hint "You have evaded the zombies."; }; }; _zombie = _this select 0; _zombie setBehaviour "careless"; spotted = false; _functionCall = [] spawn _fex_fn_hint; while {alive player && alive _zombie} do { _zPos = position _zombie; spotted = false; doStop _zombie; _randomN = random[-10,0,10]; if ((random 5) > 3) then { _zombie DoMove [(_zPos select 0) + _randomN, (_zPos select 1) + _randomN,0]; }; while {player distance zombie < 100} do { spotted = true; _zombie setBehaviour "aware"; _zombie doMove position player; sleep 3; }; sleep 5; }; spotted = false