//for...do examples //example 1 - example of simple countdown mechanism for "_i" from 10 to 0 step -1 do { hint str _i; sleep 1; }; //example 2 - same principle, only now the counting is reversed, and the values increase for "_i" from 0 to 10 step 1 do { hint str _i; sleep 1; }; //example 2 - alternative syntax (not really recommended due to slightly slower execution, but completely OK in small loops) for [{_i=0},{_i<=10},{_i = _i + 1}] do { hint str _i; sleep 1; }; //example 3 - display ten words, one after another. _words = [ "First", "Second", "Third", "Fourth", //our array of words (strings) "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth" ]; for "_i" from 0 to 9 step 1 do { hint (_words select _i); //don't forget that array index starts at 0, not at 1 sleep 0.7; }; //alternatively, change the numbers a bit - this way the 'for' itself seems more intuitive, but we need to pick an element i - 1 /* for "_i" from 1 to 10 step 1 do { hint (_words select (_i - 1)); sleep 0.7; }; */ //example 4 - pick a random sentence from array of strings, display it in a custom format, where //each word starts on a new line _sentences = [ "Can the male hangover patronize the terrible directive?", "Throughout the constant leaps an eccentric choice.", "The procedure multiplies behind the thrust!", "The expected average pulps its inverse sink.", //our array of sentences "The optical creator listens.", "The contour seeds the helmet.", "An inaccurate jungle swallows in each deep captain.", "A crossroad chews beneath the supernatural.", "The birth pinches an owned resolve." ]; _randomNumber = floor random ((count _sentences) - 1); //pick a random number from 0 to the total count of sentences _randomSentence = _sentences select _randomNumber; //select an element of the array with that number _split = _randomSentence splitString " "; //split the sentence into an array of individual words _resultingText = ""; //pre-prepare the final string //_resultingText = _split joinString "\n"; //an alternative to using 'for' for "_i" from 0 to (count _split - 1) step 1 do { _resultingText = _resultingText + (_split select _i) + "\n"; //keep adding individual words, and the sign for new line }; hint _resultingText; //example 5 _finalString = ""; //pre-prepare the final string for "_i" from 0 to ((count units group player) - 1) step 1 do { //display the unit's number and damage in % _finalString = _finalString + str (_i + 1) + ": " + str (damage ((units group player) select _i) * 100) + "%\n"; }; hint _finalString; //the same script, only beautified, and updating regularly while {alive player} do { _finalString = ""; for "_i" from 0 to ((count units group player) - 1) step 1 do { if (damage ((units group player) select _i) < 0.25) then { _finalString = //this is structured text. It can use certain tags for font, color, size... _finalString + "
" //make the text green - the unit is OK. + str (_i + 1) //unit's number in the group + ": " + str (damage ((units group player) select _i) * 100) //unit's damage in % + "%"; //the % sign itself }; if (damage ((units group player) select _i) > 0.25 && damage ((units group player) select _i) < 0.7 ) then { //make the color yellow, the unit is hurt. _finalString = _finalString + "
" + str (_i + 1) + ": " + str (damage ((units group player) select _i) * 100) + "%"; }; if (damage ((units group player) select _i) > 0.7) then { //make the color red, the unit is badly wounded. _finalString = _finalString + "
" + str (_i + 1) + ": " + str (damage ((units group player) select _i) * 100) + "%"; }; }; hintSilent parseText _finalString; //because we used structured text, we need parseText for the game to display it properly sleep 1; //update the info every 1 second. } //example 6 //searching for anyone named "John" or "Johnny" in the vicinity //possible to add more names if necessary to the array _arrNames = ["John","Johnny"]; //array of names to search _maxNames = count _arrNames; //total number of names _foundUnits = []; //here we will store people who match the desired name(s) _units = (position player) nearEntities ["MAN", 100]; //nearby people _maxUnits = count _units; //count all nearby people for "_i" from 0 to _maxUnits - 1 step 1 do { for "_j" from 0 to _maxNames - 1 step 1 do { //condition checks if unit's name matches one of our desired names if (toLower(name (_units select _i)) == (toLower(_arrNames select _j))) then { _foundUnits append [_units select _i]; //add the unit to our array of people who match the search }; }; }; if (count _foundUnits < 1) then { TitleText ["Sorry, we haven't found anyone.","plain down"]; //if the array is empty, we haven't found anyone } else { TitleText ["We have some results.","plain down"]; //we have found at least one unit that matches for "_i" from 0 to (count _foundUnits) - 1 step 1 do { //for each such unit, create a marker on its location _marker = createMarker ["JohnMarker_" + str _i, position (_foundUnits select _i)]; _marker setMarkerShape "ICON"; _marker setMarkerType "hd_unknown"; _marker setMarkerSize [1,1]; }; }; //example 6 - edited version. The John/Johnny can be a PART of the unit's name, not its full, entire name. _arrNames = ["John","Johnny"]; _maxNames = count _arrNames; _foundUnits = []; _units = (position player) nearEntities ["MAN", 100]; _maxUnits = count _units; for "_i" from 0 to _maxUnits - 1 step 1 do { for "_j" from 0 to _maxNames - 1 step 1 do { //the condition is changed from "does it totally match" to "try to find the required word within the full name" if ( (toLower(name (_units select _i))) find toLower(_arrNames select _j) != -1) then { //an additional condition to check if we aren't adding the same unit twice //(for example, with John 'Johnny' Cash, we'd have two positive finds, although it's still only one person) if (count _foundUnits > 0) then { if ((_foundUnits select (count _foundUnits - 1)) != (_units select _i)) then { _foundUnits append [_units select _i]; }; } else { _foundUnits append [_units select _i]; }; }; }; }; if (count _foundUnits < 1) then { TitleText ["Sorry, we haven't found anyone.","plain down"]; } else { //hintSilent "People found: " + str count _foundUnits; TitleText ["We have some results.","plain down"]; for "_i" from 0 to (count _foundUnits) - 1 step 1 do { _marker = createMarker ["JohnMarker_" + str _i, position (_foundUnits select _i)]; _marker setMarkerShape "ICON"; _marker setMarkerType "hd_unknown"; _marker setMarkerSize [1,1]; }; };