thx mandoble, but something is still messy...to the point where it waits for the nearestobject it works, but as soon it detects the vehicle with nearestobject, the script runs straight to the end.
private ["_horiz_dist", "_chopper", "_pilot", "_id", "_inrange", "_inheight", "_vehicle", "_xdist", "_ydist", "_zdist", "_x", "_pos", "_dist"];
_chopper = _this select 0;
_pilot = _this select 1;
_vehicle = objnull;
if (driver _chopper != _pilot) exitwith {hint "You're not the Pilot."};
hint format ["Hook program activated for %1", typeof _chopper];
_id = _this select 2;
_chopper removeaction _id;
waituntil {(getpos _chopper select 2) > 1};
while {(isnull _vehicle)} do
{
_vehicle = nearestobject [_chopper, "LandVehicle"];
sleep 1;
};
_inrange = false;
_inheight = false;
while {(! _inrange) and (! _inheight)} do
{
_xdist = ((getpos _chopper select 0) - (getpos _vehicle select 0));
_ydist = ((getpos _chopper select 1) - (getpos _vehicle select 1));
_horiz_dist = sqrt(_xdist^2 + _ydist^2);
if (_horiz_dist < 3) then
{
_inrange = true;
}
else
{
_inrange = false;
};
_zdist = getpos _chopper select 2;
if ((_zdist > 5) and (_zdist < 25)) then
{
_inheight = true;
}
else
{
_inheight = false;
};
hint format ["X-offset: %1\nY-offset: %2\nHeight: %3\nDist:%4", _xdist, _ydist, _zdist, _horiz_dist];
Sleep 0.1;
};
_x = (getpos _vehicle select 2);
_dist = _chopper distance _vehicle;
hint format ["%1 attached.\nMax allowed speed: 100km/h", typeof _vehicle];
while {_x > -0.3} do
{
_pos = [getpos _chopper select 0, getpos _chopper select 1, (getpos _chopper select 2) - _dist];
_vehicle setpos _pos;
_vehicle setdir getdir _chopper;
_x = (getpos _vehicle select 2);
sleep 0.01;
if (speed _chopper > 100) exitwith {hint format ["Speed: %1km/h\nAllowed: 100km/h\n%2 dropped.", speed _chopper, typeof _vehicle]};
};
hint format ["%1 released.", typeof _vehicle];
_chopper addaction ["Hook", "liftup.sqf"];
This is how the whole script looks like right now, including your last corrections, mandoble. It seems as it doesn't wait for _inrange and _inheight becoming true.
:EDIT:
Mandoble, if you have time to, would you mind to contact me on msn? Cause this thing is causing me headache. But i bet you got enough other things to do.