How to spawn a randomly placed building in Arma 3.

Posted: January 9, 2017. At: 2:27 PM. This was 8 months ago. Post ID: 10159

This simple code for Arma 3 will spawn a randomly placed HQ building within the area of the mkr1 marker. This is a 4000×4000 marker placed on the map. This gets a random safe area and places the building within the area of this marker.

_mrk = "mkr1";
_area = markerSize _mrk;
_nul = _area pushBack markerDir _mrk;
_nul = _area pushBack ( markerShape _mrk isEqualTo "Rectangle" );
_pos = [ _mrk, _area ] call BIS_fnc_randomPosTrigger;

_randPos = [_pos , 0, 1200, 12, 0, 0.3, 0] call BIS_fnc_findSafePos;

_cargo = "Land_Cargo_HQ_V1_F" createVehicle _randPos;

_randPos14 = _cargo getRelPos [9, 12];

_mg13 = createVehicle ["O_GMG_01_high_F", _randPos14, [], 0, "CAN_COLLIDE"];

_mgguy13 = [_randPos14, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;

((units _mgguy13) select 0) moveInGunner _mg13;

This code will add a marker that will show the actual location of the HQ building.

_marker = createMarkerLocal ["opfor_hq.", position player ];
_marker setMarkerPos _randPos;
_marker setMarkerShape "ICON";
_marker setMarkerColor "Default";
_marker setMarkerType "loc_Bunker";
_marker setMarkerText "HQ.";

Use this cool code to spawn a radio tower with a machine gunner guarding it.

// Spawning the radio tower.

_randPos2 = [_pos , 0, 1200, 10, 0, 0.3, 0] call BIS_fnc_findSafePos;

_tower = "Land_TTowerBig_1_F" createVehicle _randPos2;
_tower setVectorUp [0,0,1]; // Make sure the tower is not leaning.

_towerbox = "Land_spp_Transformer_F" createVehicle _randPos2;
_towerbox setVectorUp [0,0,1];

_towerbox2 = "Land_TTowerSmall_1_F" createVehicle _randPos2;
_towerbox2 setVectorUp [0,0,1];

_tower setVehicleVarName "tower1"; tower1 = _tower;

_genny = _tower getRelPos [7, 9];

// Spawn a random minefield around the radio tower.
// *********************************************************************

_initialPos = getPos tower1; // Pos of tower.
for "_count" from 1 to 50 do {
	_minePos = [
		(_initialPos select 0) + ((random 80) - 40),
		(_initialPos select 1) + ((random 80) - 40)
	];
	_minen = createMine [
		"APERSBoundingMine",
		_minePos,
		[],
		0
	];
};

// End mine code.
// *********************************************************************

_minefield = "Land_PowerGenerator_F" createVehicle _genny;

// Spawning a MG guy near tower.

_randPos3 = [_randPos2, 1, 60, 3, 0, 20, 0] call BIS_fnc_findSafePos;

_mg = createVehicle ["O_HMG_01_high_F", _randPos3, [], 0, "CAN_COLLIDE"];

_mgguy = [_randPos3, EAST, ["O_Soldier_F"],[],[],[],[],[],232] call BIS_fnc_spawnGroup;

((units _mgguy) select 0) moveInGunner _mg;

I hope this code is useful to someone who is building a scripted mission and wants randomly placed assets for the players to capture.

One more piece of code. This will spawn enemy supply crates in random positions in random buildings around the Cargo HQ.

_houseList = getPos _cargo nearObjects ["House",600];
{
 _c = 0;
 while { format ["%1", _x buildingPos _c] != "[0,0,0]" } do {_c = _c + 1};
 if (_c > 0) then
    {
       _ranNum = floor(random _c);
       _crate = "Box_East_Support_F" createVehicle [0,0,0];
       _crate setPos (_x buildingPos _ranNum);
    };
 sleep 0.123;
} forEach _houseList;
Czech beer billboard in fallujah.
Czech beer billboard in fallujah.

No comments have been made. Use this form to start the conversation :)

Leave a Reply