OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: laggy on 23 Jan 2010, 01:50:21

Title: Finding the closest actually existing buildingPos X
Post by: laggy on 23 Jan 2010, 01:50:21
Hello dear friends,

I want myObject to be setPos'd at a random buildingPos, in the building nearest to myObject.
Since myObject can start pretty much anywhere in a city I have to search/find a close buildingPos that exists.

script:
Code: [Select]
_houseArray = nearestObjects [myObject, ["House"], 500];
_house = _houseArray select 0;
_x = 0;

while { format ["%1", _house buildingPos _x] != "[0,0,0]" } do {_x = _x + 1};
_x = _x - 1;
myObject setPos (_house buildingpos (ceil random _x));

This works great as long as the nearest enterable "House" with an actual "buildingPos" is close enough (very close, 10m). However, if there is no such "House" close by, myObject is setPos'd into the sea (I guess pos [0,0,0]) even though myObject was less than 50 meters away from a building that actually should work, and my building search still had a radius of 500m. STRANGE!!! OR???

Grateful for any input.

Laggy
Title: Re: Finding the closest actually existing buildingPos X
Post by: Fincuan on 23 Jan 2010, 10:16:35
Try putting a sleep of a few seconds after you've gone through all the buildingPos's but before setPosing the object. As strange as it may sound this helped me in a similar situation: For some reason the amount of buildingPositions kept topping out at three no matter what, but after putting in the sleep it would deliver all of them. Go figure?!

edit: Also I used this to get the actual building, seems to work every time and is good if you only need the nearest building:
Code: [Select]
_building = nearestBuilding _object;