Code:
/*
will spawn a group and make them guard the immediate area until all dead,
then spawn a new copy of same group if the building start object was set near is not destroyed.
place functions module on map in editor.
place this in a objects initline:
_null = this execVM "buildingspawn.sqf";
note object will be deleted after mission start, it can be any kind of object, for example the invicible H in empty objects.
optional, place this in init for using ID number of house in editor, find ID when pressing ID button and zooming in.
this setVariable ["house", 123456, true]; _null = this execVM "buildingspawn.sqf";
123456 is the idNumber found in editor.
*/
// set this below to true to show a marker on map on the building, and end hint. true/false = on/off.
_debug = true;
// here we wait until the function module is ready, its needed for BIS_fnc_spawnGroup.
waitUntil { !isNil "BIS_fnc_init" };
// position of the building wich you can walk inside nearest to the object placed in editor.
_building = nearestBuilding _this; // the building.
_pos = getPos _building; // the position of the building.
// here is the optional ID way of locating a house, useful for those houses wich you cannot walk inside.
_var = _this getVariable ["house", -666];
if (_var != -666) then {
_building = getPos _this nearestObject _var; // the building.
_pos = getPos _building; // the position of the building.
};
// creating the marker if debug is true.
_mName = format["%1",(vehicleVarName _this)];
_marker = createMarker[_mName,_pos];
_marker setMarkerShape "ICON";
_marker setMarkerType "DOT";
// here we delete the object used to start the script.
deleteVehicle _this;
// a loop running while the building i still up.
while {alive _building OR (getDammage _building) < 1} do {
// here we create a group with 2 units in on the building position, note they will spawn randomly at available positions near and in the building.
_group = [_pos, EAST, ["TK_INS_Bonesetter_EP1", "TK_INS_Soldier_2_EP1"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;
// here we create a random patrol around the house.
_patrol = [_group, _pos, 100] call bis_fnc_taskPatrol;
// here we wait until all are dead in the group.
waitUntil {({alive _x} count units _group) == 0};
// at this point after the waitUntil check, all units in group is dead, what happens now is that if the building is still alive or have not been
// completely destroyed, we go to the top, and repeat the creation of the group, otherwise we exit the loop here to show the hint below.
};
if (_debug) then {hint "building destroyed, exiting script"};