private
["_pos","_dist","_type","_buf","_breakflag","_obj","_j","_c","_xmin","_xmax","_ymin","_ymax","_zmin","_zmax","_mpos","_mx","_my","_mz","_wz"
,"_return"];
_pos = _this select 0;
_type = _this select 1;
_dist = _this select 2;
_buf = [0,0,0];
if (count _this > 3) then {_buf = _this select 3;};
_breakflag = TRUE;
_obj = nearestObjects [_pos, _type, _dist];
_wz = -99999;
for [{_j = 0},{_j < count _obj && _breakflag},{_j = _j + 1}] do
{
_c = boundingBox (_obj select _j);
_xmin = ((_c select 0) select 0) - (_buf select 0);
_xmax = ((_c select 1) select 0) + (_buf select 0);
_ymin = ((_c select 0) select 1) - (_buf select 1);
_ymax = ((_c select 1) select 1) + (_buf select 1);
_zmin = ((_c select 0) select 2) - (_buf select 2);
_zmax = ((_c select 1) select 2) + (_buf select 2);
_mpos = (_obj select _j) worldToModel _pos;
_mx = _mpos select 0;
_my = _mpos select 1;
_mz = _mpos select 2;
if (_mx > _xmin && _mx < _xmax && _my > _ymin && _my < _ymax) then
{
_breakflag = FALSE;
_wz = ((_obj select _j) modelToWorld [0,0,_zmax]) select 2;
};
};
[not _breakflag,_wz]