This is a simple script that allows you to place an object/unit anywhere in a city/town/village in a random building at a random buildingPos. Perfect for "hide and seek" missions where you look for an object or a unit and when you want some replay value through randomness. The script literally enables the object/unit to appear in thousands of different places and the location varies every time you run the script.
someBuildingPos.sqf
private ["_obj","_radius","_minBuildingPos","_randomPos","_houseArray","_houseNumber","_x","_house","_y"];
_obj = _this select 0;
_radius = _this select 1;
_minBuildingPos = _this select 2;
_randomPos = [(getpos _obj select 0) + _radius*0.5 - (random _radius), (getpos _obj select 1) + _radius*0.5 - (random _radius), 0];
_houseArray = nearestObjects [_randomPos, ["House"], _radius];
sleep 1;
_houseNumber = count _houseArray;
_x = 0;
while {_x <= _houseNumber} do
{
_house = _houseArray select _x;
waitUntil {! isNil "_house"};
if (format ["%1", _house buildingPos _minBuildingPos] != "[0,0,0]") exitWith {_y = 0; while { format ["%1", _house buildingPos _y] != "[0,0,0]" } do {_y = _y + 1}; _y = _y - 1; _obj setPos (_house buildingpos (ceil random _y));};
_x = _x +1;
sleep 0.1;
};
Implementation:
- Place the object/unit in an area with buildings that are enterable.
- call {[unit,radius,minPositions] execVM "someBuildingPos.sqf"};
Example: call {[mySoldier,500,5] execVM "someBuildingPos.sqf"};
- This will place mySoldier in a random building within a 500m radius and the building will have at least 5 positions in it.
Third parameter is obviously the minimum required number of buildingPos's for a building to be chosen by the script. The reason for a minimum is that some buildings only have one and you sometimes can't get there as a player, which may cause problems. In my example mission I chose 5 as minimum, which really makes sure that the building chosen by the script is enterable. Please note that there might be a couple of seconds delay before the script has chosen a house/position.
I might develop this further, so there is an option to repeat the script, making it random patrolling in a city.
Grateful for feedback or any spotting of flaws,
Laggy
contact: tolaggy@hotmail.com