RJ Wattenhofer

Tech writing, 3D model building and game design.

April 24, 2024

ArmA 2 | Spawning with For Loops

A script that will spawn and then respawn mission units over and over

arma 2 spawning units

INSTALLATION: Copy and paste the script below into MS Notepad (or equivalent), save it as respawn01.sqf and place it into your mission folder.

ACTIVATION: Place the following code in your init.sqf file:

["marker-spawn01"] execVM "respawn01.sqf";

This will automatically launch the script at mission start. You can also activate the script via trigger during the mission. If you would prefer to do it this way then place this code in a trigger:

null = ["marker-spawn01"] execVM "respawn01.sqf";

'marker-spawn01' refers to a marker that must be placed at the map location where you would like the troops to spawn. This can be named anything you like. The same goes for the script we titled 'respawn01'.

CUSTOMIZATION: The total number of loops can be changed on line five. Currently it is set to loop ten times. The group faction can be modified on line ten. Right now it states 'EAST'. Lines eleven through sixteen designate the individual units to be spawned. Switch out 'RUS_Commander' and 'RU_Soldier2' with the desired units. You can also add additional lines which will create more troops.

Lines eighteen through twenty-seven set the group's skill levels. You can modify these as you wish or remove them altogether. '1' is the highest number that can be used, which sets them at the level of a standard soldier.

On line twenty-nine a loadout script it added for customized weapons & items selection. You can read ArmA 2 | Loadout Codes for Units for assistance in creating your own loadout script.

Lines thirty-two through thirty-six provide and alert to players every time new units spawn. You can replace the sound file with your own or remove the lines. ArmA 2 | Making an Intro with the In-game Camera has a section that explains how to import your own sounds and music.

Lines thirty-eight and forty-three are sleep timers that coordinate the times the units will be deleted and then respawned respectively. The present setup allows for the soldiers to be deleted after fifteen minutes (900 seconds) followed by a delay of fifteen minutes, at which time the script will loop and begin the the process all over again.




//SCRIPT LOOPS TEN TIMES

for "_i" from 0 to 10 do {

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup EAST;
_unit1 = _group1 createUnit ["RUS_Commander", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; 
_unit2 = _group1 createUnit ["RU_Soldier2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"];
_unit3 = _group1 createUnit ["RU_Soldier2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; 
_unit4 = _group1 createUnit ["RU_Soldier2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"];
_unit5 = _group1 createUnit ["RU_Soldier2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; 
_unit6 = _group1 createUnit ["RU_Soldier2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; 

{_x setSkill ["aimingAccuracy",0.03]} foreach units _group1;
{_x setSkill ["aimingShake",0.3]} foreach units _group1;
{_x setSkill ["aimingSpeed",0.3]} foreach units _group1;
{_x setSkill ["endurance",0.3]} foreach units _group1;
{_x setSkill ["spotDistance",0.3]} foreach units _group1;
{_x setSkill ["spotTime",0.3]} foreach units _group1;
{_x setSkill ["courage",0.3]} foreach units _group1;
{_x setSkill ["reloadSpeed",0.3]} foreach units _group1;
{_x setSkill ["commanding",0.3]} foreach units _group1;
{_x setSkill ["general",0.3]} foreach units _group1;

{_x setVehicleInit "0 = [this, 50, true, 600] execvm 'loadouts\loadout-enemy.sqf'";} foreach units _group1;
processInitCommands;

playSound "intruderalert";
sleep 1;
titletext ["COMMAND BASE UNDER ATTACK---RUSSIAN INFANTRY SQUAD", "PLAIN DOWN"];
sleep 2;
playSound "intruderalert";

sleep 900;

{deleteVehicle _x} foreach units _group1;
processInitCommands;

sleep 900;

};



  • xing social button
  • linkedin social button
  • buffer social button
  • reddit social button
  • stumbleupon social button
  • facebook social button
  • google plus button
  • twitter social button
  • renren social button Renren
  • vkontakte social button Share in VK