Baddo wrote a function, buildingPosCount, to count how many building positions were available in a given building, but it was for OFP. No idea whether it is still valid in ArmA, but it is likely that you can get some joy from it, especially since it is very simple.
It should work in ArmA too. I think I tested some time last year that it works.
Another note from the top of my head is that the nearestBuilding function only returns buildings which have indexed positions in them.
As a sidenote, I've actually just recently been playing with indexed building positions in ArmA... and faced an annoying problem with some guard towers: if you order a unit to go into it, the unit often falls to the ground when on top of the ladders. Argh! I can fall from it too. So a setPos into the guard tower is required if you want to avoid that. Just one of the many stupid annoyances we have when creating missions
Edit: I will post here an unfinished function which creates and inserts units into indexed building positions. I don't have possibility now to finish it, but I will post it here, maybe someone can use it as is or modify it like they wish:
private ["_group", "_buildingType", "_unitType", "_middlePosOfRange"];
private ["_range", "_posIndices", "_houseList", "_houseCount"];
_buildingType = _this select 0;
_range = _this select 1;
_middlePosOfRange = _this select 2;
_posIndices = _this select 3;
_unitType = _this select 4;
_group = _this select 5;
_houseList = nearestObjects [_middlePosOfRange, [_buildingType], _range];
_houseCount = count _houseList;
private ["_retval", "_posIndicesCount"];
_retval = false;
_posIndicesCount = count _posIndices;
if ( ( _houseCount > 0 ) && ( _posIndicesCount > 0 ) ) then {
private ["_k", "_building", "_pos", "_i"];
_k = 0;
while { _k < _houseCount } do {
_building = _houseList select _k;
_i = 0;
while { _i < _posIndicesCount } do {
_pos = _building buildingPos (_posIndices select _i);
_unitType createUnit [_middlePosOfRange, _group, "BDO_guard = this; this setUnitPos ""up""", 0.8];
BDO_guard setPos _pos;
BDO_guard disableAI "move";
sleep 0.2;
_i = _i + 1;
};
sleep 0.2;
_k = _k + 1;
};
BDO_guard = nil;
_retval = true;
};
_retval
I'm calling it like this:
["Land_posed", 200, (getMarkerPos "BDO_UPS01"), [1], "SoldierWB", BDO_watchTowerGrp] execVM "BDO_insertIntoBuildingPositions.sqf";
The "Land_posed" is the building type which is to be used.
The 200 is the range from which searchs the buildings.
(getMarkerPos "BDO_UPS01") is the centre of the range.
[1] is an array of indexed building positions into which to insert the created units. In this case I only insert one unit per building. The index numbers start from zero (0). You can extend this to use the buildingPosCount and randomize the positions fed to this function in your calling script/function. But always remember, the first index is 0 and not 1 like it is shown in-game. In the case of the "Land_posed" watch tower, if I wanted to fill the 0 position too, I'd have [0,1] passed to the function, and a unit would appear at the ground close to the tower, and another unit would be in the tower.
"SoldierWB" is the unit type to be created and inserted into the building positions.
BDO_watchTowerGrp is the group into which the units are created. I'm just having one unit pre-placed into the map which has "BDO_watchTowerGrp = group this" in its initialization field.
In my case I have all the created units in the same group, placed into watch towers. And their movement needs to be disabled, otherwise they run to their leader. This is advantageous: the units share information about enemies when they are in the same group, which fits perfectly for watch tower guards. You can imagine that all watch towers have radios. Fill all watch towers like this in a larger base at North Sahrani and try to invade it with enemy skill set to high... I got quite nice fireworks as a result.
As I said, this is unfinished work but maybe it helps someone.