Jump to content
Sign in to follow this  
louderthanu

AI Piloted Helicopter And MoveTo Command

Recommended Posts

I have an airlift script that spawns a Ch-47 that flies to the players vehicle, picks the vehicle and player up, carries it to the point the player had previously marked on the map, drops the player and vehicle on the mark and flies back to its spawn point despawning after getting out of sight of the player.

Amazingly, it works! Um, most of the time that is. The problem is often the helicopter stops 100 meters from the dropoff ip and goes no further.

I'd started using waypoints, swiched to doMove and have the problem with both. Here's the idea:

1. Player starts the script from an add action while in a vehicle, map opens and a dropoff point is selected by a left click on the map.

2. Helicopter and crew spawn, fly to an IP point (500 meters from the pickup... eg. (vehPos is the player and is set and updated in the script) ipPos = [ (vehPos select 0)+500, (vehPos select 1)+500, 75])

3. Just short of the IP (125m) the loop exits and the code issues a doMove with the coordinates of the vehicle/player (pickup location)

4. Helicopter gets within 50m of the vehicle/player, the 2nd loop exits and an attachto is called to "pick" up the vehicle

5. Helicopter flys to 2nd IP (eg. (dropPos is the corridnates of the mapclick) ip2Pos = [(dropPos select 0)+500, (dropPos select 1)+500, 50])

6. Just short of the 2nd IP that loop exits and the code issues a doMove with the corridnates of the drop point

7. Helicopter gets within 50m of the drop point, that loop exits and script "deattaches" the vehicle placing it at the "drop zone" cooridnates.

8. Helicopter is issued a doMove to its spawn point, flies away from the dropoff and despawns when 1500m from the player

99% of the time, 1-5 work as exactally as expected, but hangs at Step #6 . When it doesn't hang, steps 6-8 function as expected.

I've hinted the position values and they exist and they're correct but the (_heli distance _ip2 <= xxx) never seems to trigger to exit that loop- and the helicopter will stop 100m (consistantly) from whatever value I'm checking. For instance, If I've set it to exit the loop at 500m, it will stop at 600 and never trigger the loop exit. If I set it to 100m, it will stop at 200m. If I set it to 0m it will stop at 100m and so forth.... Never more or less that 100m... weird huh?

The pilot is being issued the doMove command, the pilot is set to combat status green and is made captive (and that really does prevent him from flying off on his own!). Again, I've tried waypoints and doMovecommands, the behaviour is the same with both methods.

I've noticed that the problem is most acute in MP. In other words the script completes 80% of the time in single player but only 20% in MP. I've also noticed that in both SP and MP, if the script runs succesfully once- the second attempt will stall at #6.

Any suggestions? Thanks in advance!

TAW_louderthanu

Edited by louderthanu
change moveto to domove

Share this post


Link to post
Share on other sites

Do you mind providing the full script you've written so far? I think it'd be easier to help you with the script present.

Share this post


Link to post
Share on other sites

Sure! There is "dead" code in there, but you'll get the idea:

_pos = [0,0,0];
_lzPos = [0,0,0];
_lzIP = [0,0,0];
_playerPos = [0,0,0];
_vehPos = [0,0,0];
_heliSpawn = [0,0,0];
_crewSpawn = [0,0,0];
_grp = objNull;
_puTrig = 0;
_distance1 = 0;
_distance2 = 0;
_destroyed = 0;
_dead = 0;
_canceled = 0;


fnc_airLift = 
{
   _canceled = 0;
_destroyed = 0;
_dead = 0;
_player = _this select 0;
_lzPos = _this select 1;
_playerPos = getPos vehicle player;
_heliSpawn = getMarkerPos "airdrop_spawn";
_crewSpawn = [(_heliSpawn select 0)+5, (_heliSpawn select 1)+5, 0];
_heliType = "CH_47F_EP1";
_crewType = "USMC_Soldier_Pilot";

//map marker
_lzmarker = createMarker ["lzmarker", _lzPos];
_lzmarker setMarkerShape "ICON";
"lzmarker" setMarkerType "hd_destroy";
"lzmarker" setMarkerText "Airlift LZ";
"lzmarker" setMarkerColor "ColorOrange";

//spawn lift chopper crew
_grp = creategroup WEST;
_pilot1 = _grp createUnit [_crewType, _crewSpawn, [], 0, "FORM"];
_pilot1 setRank "LIEUTENANT";

_gunner1 = _grp createUnit [_crewType, _crewSpawn, [], 0, "FORM"];
_gunner2 = _grp createUnit [_crewType, _crewSpawn, [], 0, "FORM"];
_gunner3 = _grp createUnit [_crewType, _crewSpawn, [], 0, "FORM"];
{

	_x addEventHandler ["killed", {handle = [_this select 0] execVM "data\scripts\bury.sqf"}];
} foreach units _grp;

//spawn lift chopper
_heli = createVehicle [_heliType, _heliSpawn, [], 0, "FLY"];
_heli allowDamage false;


_pilot1 moveindriver _heli;
_pilot1 setCaptive true;
_pilot1 allowDamage false;
_pilot1 setRank "LIEUTENANT";

_gunner1 MoveInTurret [_heli,[0]];
_gunner2 MoveInTurret [_heli,[1]];
_gunner3 MoveInTurret [_heli,[2]];

_gunner1 allowDamage false;
_gunner2 allowDamage false;
_gunner3 allowDamage false;

//lift chopper map marker
_sumark = [_heli] execVM "scripts\loud\loudAirlift\loudAirlift_HeliMarker.sqf";

_grp setBehaviour "CARELESS";
_grp setCombatMode "GREEN";  //hold fire, defend only;

_heli engineOn true;
_heli flyInHeight 75;	

_veh = vehicle player;
_vehPos = getPos vehicle player;	

_ip = [(_vehPos select 0)-500, (_vehPos select 1)-500, 0];
_pilot1 doMove _ip;

//disable vehicle
//_veh setFuel 0;
//_veh lock true;

//**** from spawn to ip
for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
{
	_distance1 = (position _heli) distance (getPos vehicle player);
	if (_distance1 >= 600) then {
		hintSilent parseText format["<t color='#e5b348'>Airlift:</t> Lift Chopper is %1m from pickup lz!<br/><br/><t color='#ff0000'>DO NOT LEAVE YOUR VEHICLE!!!</t>", round((position _heli) distance (getPos vehicle player))];
	};
	if (_distance1 <= 600) then {_rloop=1;};
	if (vehicle player == player) then {_canceled = 1;_rloop=1;};
	if (!alive _heli || !alive _pilot1) then {_destroyed = 1;_rloop=1;};
	if (!alive player) then {_dead = 1;_rloop=1;};
};
if (_canceled == 1) then {[] call fnc_cancelAirlift};
if (_destroyed == 1) then {[] call fnc_heliDead};
if (_dead == 1) then {[] call fnc_playerDead};

//update position
_vehPos = getPos vehicle player;

if (_canceled == 0) then
{
	//pop smoke
	_k = "SmokeShellGreen" createVehicle _vehPos;
	_k setPos (getPos _veh);
	_k attachTo [_veh,[0,0,0.2]];
};

// go to pickup
_heli limitSpeed 40;
_pickup = [(_vehPos select 0), (_vehPos select 1), 0];
_heli flyInHeight 40;
_pilot1 doMove _pickup;	

//**** from ip to pickup	
for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
{
	_distance1 = (position _heli) distance (getPos vehicle player);
	if (_distance1 >= 125 && speed _heli > 1) then {
		hintSilent parseText format["<t color='#e5b348'>Airlift:</t> Lift Chopper is %1m from pickup lz!<br/><br/><t color='#ff0000'>DO NOT LEAVE YOUR VEHICLE!!!</t>", round((position _heli) distance (getPos vehicle player))];
	};
	if (_distance1 <= 125) then {_rloop=1;};
	if (vehicle player == player) then {_canceled = 1;_rloop=1;};
	if (!alive _heli || !alive _pilot1) then {_destroyed = 1;_rloop=1;};
	if (!alive player) then {_dead = 1;_rloop=1;};
};
if (_canceled == 1) then {[] call fnc_cancelAirlift};
if (_destroyed == 1) then {[] call fnc_heliDead};
if (_dead == 1) then {[] call fnc_playerDead};

if (_canceled == 0) then
{
	//pick up vehicle
	_veh allowdamage false;
	_veh attachTo [_heli,[0,0,-10]];
	_veh setDir 360;
	_veh setPos getPos _veh;
	if (alive _k) then {deleteVehicle _k};
};

//go to lz_ip
_lzIP = [(_lzPos select 0)-500,(_lzPos select 1)-500,0];
_heli flyInHeight 75;
_pilot1 doMove _lzIP;


//**** from pickup to lz
for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
{
	_distance1 = (position _heli) distance (_lzPos);
	if (_distance1 >= 600) then {
		hintSilent parseText format["<t color='#e5b348'>Airlift:</t> Lift Chopper is %1m from dropoff lz", round((position _heli) distance _lzPos)]; 
	};
	if (_distance1 <= 600) then {_rloop=1;};
	if (vehicle player == player) then {_canceled = 1;_rloop=1;};
	if (!alive _heli || !alive _pilot1) then {_destroyed = 1;_rloop=1;};
	if (!alive player) then {_dead = 1;_rloop=1;};
};
if (_canceled == 1) then {[] call fnc_cancelAirlift};
if (_destroyed == 1) then {[] call fnc_heliDead};
if (_dead == 1) then {[] call fnc_playerDead};

if (_canceled == 0) then
{
	//pop smoke at lz
	_k2 = "SmokeShellRed" createVehicle _lzPos;
	_k2 setPos (_lzPos);
};

//go to lz
_heli limitSpeed 40;
_heli flyInHeight 40;
_pilot1 doMove _lzPos;


//**** from lz_ip to dropoff
for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
{
	_distance1 = (position _heli) distance (_lzPos);
	if (_distance1 >= 125) then {
		hintSilent parseText format["<t color='#e5b348'>Airlift:</t> Lift Chopper is %1m from release", round((position _heli) distance _lzPos)];
	};
	if (_distance1 <= 125 && speed _heli > 1) then {_rloop=1;};
	if (vehicle player == player) then {_canceled = 1;_rloop=1;};
	if (!alive _heli || !alive _pilot1) then {_destroyed = 1;_rloop=1;};
	if (!alive player) then {_dead = 1;_rloop=1;};
};
if (_canceled == 1) then {[] call fnc_cancelAirlift};
if (_destroyed == 1) then {[] call fnc_heliDead};
if (_dead == 1) then {[] call fnc_playerDead};

if (_canceled == 0) then
{
	//release vehicle
	detach _veh;
	_veh setPos [_lzPos select 0, _lzPos select 1, 0];
	_veh setVelocity [0,0,0];
	sleep 1;
	_veh allowDamage true;
	_veh setFuel 1;
	_veh engineOn true;
	_veh lock false;
	sleep 1;
};

//go to end mark
_heli flyInHeight 150;
_pilot1 doMove _heliSpawn;

//**** from dropoff to ending
for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
{
	_distance1 = (position _heli) distance (_heliSpawn);
	_distance2 = (position _heli) distance (vehicle player);
	if (_distance1 >= 500) then {
		hintSilent parseText format["<t color='#e5b348'>Airlift:</t> Lift Chopper is %1m from base", round((position _heli) distance _heliSpawn)];
	};
	if (_distance1 <= 500 || _distance2 >= 1500) then {_rloop=1;};
	if (!alive _heli || !alive _pilot1) then {_destroyed = 1;_rloop=1;};
};
if (_destroyed == 1) then {[] call fnc_heliDead};

[] call fnc_removeAirlift;

deleteMarker "lzmarker";

hintSilent parseText "<t color='#e5b348'>Airlift:</t> Lift Chopper Out Of Area.";

}; 

//REMOVE HELICOPTER FUNCTION
fnc_removeAirlift = {
if (alive _heli) then {deleteVehicle _heli};
if (alive _pilot1) then {deleteVehicle _pilot1};
if (alive _gunner1) then {deleteVehicle _gunner1};
if (alive _gunner2) then {deleteVehicle _gunner2};
if (alive _gunner3) then {deleteVehicle _gunner3};
deleteGroup _grp;
};



//PLAYER OUT OF VEHICLE FUNCTION
// fnc_outOfVeh = {
// _i = 15;
// for [{_rloop=0}, {_rloop<1}, {_rloop=_rloop}] do
// {
	// if (vehicle player == player) then {
		// if (_i > 0) then {
			// hintSilent parseText format["<t color='#e5b348'>Airlift:</t> You have %1 seconds to return to your vehicle before the airlift is canceled!", _i];
			// _heli setVelocity [0,0,0];
			// _i = _i - 1	
		// } else {
			// hintSilent parseText "<t color='#e5b348'>Airlift:</t> The airlift request has been canceled!";
			// _canceled = 1;
			// _rloop=1;
		// };
	// } else {
		// _heli setVelocity [100,0,0];
		// _canceled = 0;
		// _rloop=1;
	// };
	// sleep 1.0;
// };
// };

// HELICOPTER DESTROYED / PILOT DEAD FUNCTION 
fnc_heliDead = {
hint parseText "<t color='#ff0000'>Lift Chopper Has Been Destroyed!</t>";
deleteMarker "lzmarker";
[] call fnc_removeAirlift;
if(_destroyed == 1) exitwith {};
};

//PLAYER DEAD FUNCTION
fnc_playerDead = {
hint parseText "<t color='#ff0000'>Player Died!</t>";
deleteMarker "lzmarker";
[] call fnc_removeAirlift;
if (_dead == 1) exitwith {};
};

//CANCEL AIRLIFT FUNCTION
fnc_cancelAirlift = {
hint parseText "<t color='#ff0000'>Airlift Canceled By Player!</t>";
deleteMarker "lzmarker";
_veh allowDamage true;
_veh setFuel 1;
_veh engineOn true;
_veh lock false;
_veh setPos [_playerPos select 0, _playerPos select 1, 0];
[] call fnc_removeAirlift;	
if (_canceled == 1) exitwith {};
};


//************************************************************** START *******************************************************
if (vehicle player != player) then {
if ((vehicle player isKindOf "Tank") || (vehicle player isKindOf "Car") || (vehicle player isKindOf "Ship")) then {
	//open map, get position from single click and run fnc_airLift
	airlift = true;
	hint "Click on the map where you'd like to to be dropped off.  BE SURE THE LZ IS CLEAR FOR AT LEAST 1.0k IN ALL DIRECTIONS AND THAT ANY AAA THREAT IN THE VICINTITY HAS BEEN ELIMIATED!!";
	openMap true;
	onMapSingleClick "onMapSingleClick """";[player, _pos] spawn fnc_airlift;airlift = false;openMap false;";	
} else {
	hint "You Must Be In A Ground Vehicle To Use This!";
};
} else {
hint "You Must Be In A Vehicle To Use This!";
};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×