Jump to content
Sign in to follow this  
gotipe

How to make AI vehicle follow/chase players

Recommended Posts

Hello,

I have tried the latest days to create in a sqf script something that will prompt spawned AI enemy helicopters in an already existing addon script (Parareinf) to attack/follow/chase spotted enemies. My scripting skills are limited but so far I haven't been able to make them actually follow the player. :/ Tried to follow similar threads but not been able to reproduce a script that actually gets them moving. :/ With "doMove (getPos player)" it still doesn't take long before they become rather stationary. While they occassionally do fire on me they don't move. Could somebody perhaps offer some input to how to get them to follow/attack player(s)?

Share this post


Link to post
Share on other sites

Hey Gotipe

Try this

Groupheli = CreateGroup West;

heli1 = createVehicle ["AH1Z", [(getpos player) select 0,(getpos player) select 1,0], [], 1500, "FLY"];
heli1c1 = Groupbheli createUnit ["USMC_Soldier_Pilot", [0,0,1], [], 0, "CAN_COLLIDE"];
heli1c1 moveInDriver heki1;
heli1c2 = GroupTank createUnit ["USMC_Soldier_Pilot", [0,0,2], [], 0, "CAN_COLLIDE"];
heli1c2 moveInGunner heli1;

heli1c1 sideChat "HQ: What ever you want to say";

sleep 1;

wp1 = Groupbheli addwaypoint [position Player, 200];
wp1 setwaypointtype "MOVE"; 
wp1 setWaypointCombatMode "RED"; 
wp1 setWaypointFormation "WEDGE"; 
wp1 setWaypointSpeed "FULL"; 
wp1 setWaypointBehaviour "COMBAT"; 
wp1 setWaypointCompletionRadius 10; 
wp1 setWaypointStatements ["true", ""];  


wp2 = Groupbheli addwaypoint [position Player,200]; 
wp2 waypointAttachVehicle vehicle player;  
wp2 setwaypointtype "SAD"; 
wp2 setWaypointCombatMode "RED"; 
wp2 setWaypointFormation "WEDGE"; 
wp2 setWaypointSpeed "FULL"; 
wp2 setWaypointBehaviour "COMBAT"; 
wp2 setWaypointCompletionRadius 25;
wp2 setWaypointStatements ["true", ""];  


wp3 = Groupbheli addwaypoint [position Player, 200]; 
wp3 waypointAttachVehicle vehicle player;  
wp3 setwaypointtype "SAD"; 
wp3 setWaypointCombatMode "RED"; 
wp3 setWaypointFormation "WEDGE"; 
wp3 setWaypointSpeed "FULL"; 
wp3 setWaypointBehaviour "COMBAT"; 
wp3 setWaypointCompletionRadius 25;
wp3 setWaypointStatements ["true", ""];  


wp4 = Groupbheli addwaypoint [position Player, 200]; 
wp4 setwaypointtype "Cycle"; 
wp4 setWaypointCombatMode "RED"; 
wp4 setWaypointFormation "WEDGE"; 
wp4 setWaypointSpeed "FULL"; 
wp4 setWaypointBehaviour "COMBAT"; 
wp4 setWaypointCompletionRadius 10;

This should make a heli 1500 meters away in the air it will fly to your location 200 feet away and do a SAD then follow you and do a new SAD then the whole thing will repeat. This should work hope this is wht you needed. Avibird

PS. This is for the same side!!

Share this post


Link to post
Share on other sites
Did you try the reveal command ?

Not yet, but I will test it. Will it prompt the hostile AI helicopter to go after the revealed threat? (With careless behaviour, red combat mode f.e)

@AVIBIRD 1: We only play Insurgency Blufor so sides should be no problem, but I wonder if there might be a way to make the AI update position automatically when needed instead of writing a series of waypoints.

Because I want the helicopter(s) to go after the players until they are shot down no matter how much the players move around on the map.

Share this post


Link to post
Share on other sites

This scripting command waypointAttachVehicle vehicle player; Will put the waypoint on the player and the cycle will update the current position. The units will follow you like a dog lol all over the map. Hope you get it to work.

Share this post


Link to post
Share on other sites

I think a chopper following you would be to easy for them as they can just fly above you to around your position, infantry would be

more interesting i think as they will have to traverse the terrain in order to see you to be able to shoot at you, is there a script i could sue to implement

into a mission that would have enemy AI search and or chase you and engage you, I like the idea of the enemy hunting you, makes you rather scared ingame

and gives you ideas where you can set traps for them, like mines, or ambush them ect,.

But not just Ai on foot, but in vehicles,a dn maybe armored, how can i set that up?

Share this post


Link to post
Share on other sites

Hehe indeed.

This scripting command waypointAttachVehicle vehicle player; Will put the waypoint on the player and the cycle will update the current position. The units will follow you like a dog lol all over the map. Hope you get it to work.

It seems like it worked to begin with, then the second chopper (I spawned two by calling the script twice in a trigger) just became stationary at start again. I think the other helicopter ran out of ammo but began flying where I clearly was not, but at least it followed me away from the starting point, :S

EDIT: Hmm strange, now it finally came along. Took some time though, but sure enough both helicopters are with me. But I wonder, are they meant to go back to the initial area after a waypoint cycle? It seems like they do that, or take very wide overpass circles.

Edited by Gotipe

Share this post


Link to post
Share on other sites
Hehe indeed.

It seems like it worked to begin with, then the second chopper (I spawned two by calling the script twice in a trigger) just became stationary at start again. I think the other helicopter ran out of ammo but began flying where I clearly was not, but at least it followed me away from the starting point, :S

EDIT: Hmm strange, now it finally came along. Took some time though, but sure enough both helicopters are with me. But I wonder, are they meant to go back to the initial area after a waypoint cycle? It seems like they do that, or take very wide overpass circles.

Yes in that setup they will fallback to a setup zone it was for a comabt support script and mission I am working on. You can have them just follow you by taking out the Cycle or something esle ?. Check to see if you can get it to follow you all the time. if you can't I will look at some of the test trails to find out the setup for you(:

Share this post


Link to post
Share on other sites

I put in a _wp1 setWPPos getPos Player; at the second SAD waypoint, not sure how it actually worked, but one of the helicopters still seemed to be very slow to react at all.

Share this post


Link to post
Share on other sites

This script turns hinds and apaches into nasty beasties.

-reveals nearby targets

-agressive flight profile

-operates from low to medium altitude

-area patrol

-auto flares

-close range rocket spam reduced

-rockets fired from longer range

-remove rocket magazine (optional)

//eg hind init field
//nul = [this,(getPosATL player),1000,300] execVM "heliCtrl.sqf";
//parameters[aircraft,position,number,number]

private ["_cntrPos","_hgtArr","_tgtArray","_target","_vcl","_wPArray","_wp1","_aimingQuality","_fnc_flares","_fnc_rkts"];
_vcl = _this select 0;
_centerPatrolArea = _this select 1;
_areaSize = _this select 2;
_revealAreaSize = _this select 3;

var_Patrol=1;
_vcl setPosATL [getPosATL _vcl select 0, getPosATL _vcl select 1, 500];
_vcl setVelocity [(sin (getDir _vcl)) * 50, (cos (getDir _vcl)) * 50, 0];

////////////removes rockets from attack helicopters, optional, commented out/////////////////
////if uncommented - you need to remove _fnc_rkts////////////////
/*
if (_vcl isKindOf "Helicopter") then {
_magsArr = getArray (configFile >> "CfgVehicles" >> (typeOf _vcl) >> "Turrets" >> "MainTurret" >> "magazines");
{_vcl removeMagazines _x} forEach _magsArr;

_blklist = ["6Rnd_CRV7_HEPD","6Rnd_CRV7_FAT","38Rnd_FFAR","192Rnd_57mm","128Rnd_57mm","64Rnd_57mm","40Rnd_80mm","80Rnd_80mm"];

for "_i" from 0 to (count _blklist -1) do {
if (_magsArr find (_blklist select _i) > -1) then {_magsArr = _magsArr - [_blklist select _i];}
};

{_vcl addMagazine _x; _vcl addMagazine _x;} forEach _magsArr;
};
*/
//////////////remove all previous waypoints//////////////////
_wPArray = waypoints (group _vcl);
for "_i" from 0 to (count _wPArray -1) do {
deleteWaypoint [(group _vcl), _i]
};

/////////////add 1 WP it's all you need///////////////////
_wp1 = (group _vcl) addWaypoint [getPosATL _vcl, 100];
   _wp1 setWaypointType "SAD";

//////////////////////////////////////////////////////////////
//Auto flares

_fnc_flares = {
private ["_list","_airVec","_prm","_cls","_plt","_msl"];
_airVec = _this select 0;
_airVec removeMagazinesTurret ["CMFlareLauncher",[0]];
_airVec addMagazineTurret ["120Rnd_CMFlare_Chaff_Magazine",[0]];

 _prm = 750;
   _plt = driver _airVec;

while {alive _airVec} do {
 	  _list = (position _airVec) nearObjects ["MissileBase",_prm];

if (count _list >=1) then {
  _msl = _list select 0;
	    _cls = typeOf _msl;

if (_cls == "M_Strela_AA"|| _cls == "M_Stinger_AA" || _cls == "M_Igla_AA") then{
 _airVec action ["useWeapon", _airVec, _plt, 2];

 	if ((_airVec ammo "CMFlareLauncher") == 0) then {
_airVec addMagazineTurret ["120Rnd_CMFlare_Chaff_Magazine",[-1]];
       reload _airVec;

   sleep 0.3;
	};
     };
   };
 };
};

[_vcl] spawn _fnc_flares;

/////////////////////////remove this section if not using rockets////////////////////////////////////////////////////
_fnc_rkts = {
private ["_gshp","_target","_aimingQuality"];

_gshp = _this select 0;
_weapArr = getArray (configFile >> "CfgVehicles" >> (typeOf _vcl) >> "Turrets" >> "MainTurret" >> "Weapons");
while {alive _gshp} do {
  _target = assignedTarget _gshp;
_aimingQuality = _gshp AimedAtTarget [_target];

if (_aimingQuality >= 0.7 && _gshp distance _target > 500) then {_gshp action ["useWeapon", _gshp, (gunner _gshp), 7];};
if (_gshp distance _target < 500) then {_gshp selectWeapon (_weapArr select 0);};
   sleep 2;
 };
};
[_vcl] spawn _fnc_rkts;

/////////////loop to control flight and attacking//////////////
while {alive _vcl} do {
_cntrPos = _centerPatrolArea//can be anything or any postition
_hgtArr = [50,100,150,200,250,300];
	   _vcl flyInHeight (_hgtArr select (floor (random 6)));

if (format ["%1", _cntrPos] != "[0,0,0]" && var_Patrol==1) then {
     _wp1 setWaypointPosition [_cntrPos, floor(random _areaSize)];
       (group _vcl) setCurrentWaypoint _wp1;};

//////////////////////for a quick response attack://///////////
_tgtArray = _vcl nearTargets _revealAreaSize;
   if (count _tgtArray >0) then {{(group _vcl) reveal (_x select 4);} forEach _tgtArray;};

_target = assignedTarget _vcl;
_aimingQuality = _vcl AimedAtTarget [_target];
if (_aimingQuality >= 0.7) then {_vcl action ["useWeapon", _vcl, (gunner _vcl), 7];};

if (!(isNull _target)) then {var_Patrol=0; _wp1 setWaypointPosition [getPosATL _target, floor(random 50)];
   (group _vcl) setCurrentWaypoint _wp1;
} else {
var_Patrol=1;
};

sleep 20;
};

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Sweet! But I wonder if it can be changed, no need for fancy weapons use, for Mi-8 helicopters? Those are spawned by the parajump script I am trying to amend, where instead of the helicopters being deleted I want them to chase the player(s)/hostiles. Instead of area patrol, =P

I am still unsure why the second helicopter would take time to move or move back to the first waypoint that should be updated, the script is executed twice from trigger without error except for that.

Share this post


Link to post
Share on other sites

Hey Gotipe if you want the units to follow you and not go back to the setup zone/1st WP then this is the WP setup to follow

//staging sector
wp1 = GroupTank addwaypoint [position Player, 50];
//wp1 waypointAttachVehicle vehicle player; 
wp1 setwaypointtype "MOVE"; 
wp1 setWaypointCombatMode "YELLOW"; 
wp1 setWaypointFormation "DIAMOND"; 
wp1 setWaypointSpeed "FULL"; 
wp1 setWaypointBehaviour "AWARE"; 
wp1 setWaypointCompletionRadius 10; 
wp1 setWaypointStatements ["true", "hint '';"];


//hint "";
waituntil {moveToCompleted leader GroupTank};
//hint ""; 


//Alpha waypoint
wp2 = GroupTank addwaypoint [position Player, 50]; 
wp2 waypointAttachVehicle vehicle player;  
wp2 setwaypointtype "MOVE"; 
wp2 setWaypointCombatMode "Yellow"; 
wp2 setWaypointFormation "WEDGE"; 
wp2 setWaypointSpeed "FULL"; 
wp2 setWaypointBehaviour "AWARE"; 
wp2 setWaypointCompletionRadius 10;
wp2 setWaypointStatements ["true", "hint '';"];

//hint "";
waituntil {moveToCompleted leader GroupTank};
//hint ""; 


//Bravo waypoint
wp3 = GroupTank addwaypoint [position Player, 50]; 
wp3 waypointAttachVehicle vehicle player;  
wp3 setwaypointtype "MOVE"; 
wp3 setWaypointCombatMode "YELLOW"; 
wp3 setWaypointFormation "VEE"; 
wp3 setWaypointSpeed "FULL"; 
wp3 setWaypointBehaviour "AWARE"; 
wp3 setWaypointCompletionRadius 10;
wp3 setWaypointStatements ["true", "hint '';"];


//Charlie waypoint
wp4 = GroupTank addwaypoint [position Player, 50]; 
wp4 waypointAttachVehicle vehicle player; 
wp4 setwaypointtype "Cycle"; 

You can change the [position Player, 50] to a big distance and you could change the combatmode to "RED"

I am using this setup for a group of JETS to move to may location to give me CAS for a few minutes. May issue without this SETUP the jets would fly off all over the map to chase other opfor units. Still not 100% staying in the area of support for me because the planes have a better and larger LOS and if set to RED/YELLOW they will target what they can see. Hope this helps. AVIBIRD.

Edited by AVIBIRD 1

Share this post


Link to post
Share on other sites
Sweet! But I wonder if it can be changed, no need for fancy weapons use, for Mi-8 helicopters? Those are spawned by the parajump script I am trying to amend, where instead of the helicopters being deleted I want them to chase the player(s)/hostiles. Instead of area patrol, =P

I am still unsure why the second helicopter would take time to move or move back to the first waypoint that should be updated, the script is executed twice from trigger without error except for that.

When vehicles spawn they get an initial waypoint at that position - if you want precise movement you need to delete it - try this, checks for nearby enemy and follows them @ random 50m, if Null follows player @ random 300m:

//nul = [vecNameor_ref] execVM "follow.sqf";

private ["_cntrPos","_vcl","_wPArray","_wp1","_tgtArray","_nrstETgts"];

_vcl = _this select 0;

//remove all previous waypoints
_wPArray = waypoints (group _vcl);
      for "_i" from 0 to (count _wPArray -1) do
     {
      deleteWaypoint [(group _vcl), _i]
     };

//add 1 WP it's all you need
_wp1 = (group _vcl) addWaypoint [(getPosATL _vcl), 0];
   _wp1 setWaypointType "SAD"; //change to "MOVE" if you want it hovering over

//movement loop
while {alive _vcl} do 
{
_tgtArray = nearestObjects [_vcl, ["Car","Man"], 1000];//change to value you need
   _nrstETgts = []; 
   {
       if (side _x == EAST) then
       { //change to WEST if need to follow WEST
           _nrstETgts set [(count _nrstETgts),_x];
       };
   } foreach _tgtArray;

   _cntrPos =  getPosATL (_nrstETgts select 0);

               if (count _nrstETgts !=0 && format ["%1", _cntrPos] != "[0,0,0]") then 
               {        
                  //chase enemy if exist and have valid position
                 _wp1 setWaypointPosition [_cntrPos, floor(random 50)];
                 (group _vcl) setCurrentWaypoint _wp1;
                 _vcl reveal (_nrstETgts select 0);
               }
               else 
               {
                 //chase player
                 _wp1 setWaypointPosition [(getPosATL player), floor(random 300)];
                 (group _vcl) setCurrentWaypoint _wp1;
               };
sleep 30; //behaviour changes every n seconds
};

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites
Hey Gotipe if you want the units to follow you and not go back to the setup zone/1st WP then this is the WP setup to follow

//staging sector
wp1 = GroupTank addwaypoint [position Player, 50];
//wp1 waypointAttachVehicle vehicle player; 
wp1 setwaypointtype "MOVE"; 
wp1 setWaypointCombatMode "YELLOW"; 
wp1 setWaypointFormation "DIAMOND"; 
wp1 setWaypointSpeed "FULL"; 
wp1 setWaypointBehaviour "AWARE"; 
wp1 setWaypointCompletionRadius 10; 
wp1 setWaypointStatements ["true", "hint '';"];


//hint "";
waituntil {moveToCompleted leader GroupTank};
//hint ""; 


//Alpha waypoint
wp2 = GroupTank addwaypoint [position Player, 50]; 
wp2 waypointAttachVehicle vehicle player;  
wp2 setwaypointtype "MOVE"; 
wp2 setWaypointCombatMode "Yellow"; 
wp2 setWaypointFormation "WEDGE"; 
wp2 setWaypointSpeed "FULL"; 
wp2 setWaypointBehaviour "AWARE"; 
wp2 setWaypointCompletionRadius 10;
wp2 setWaypointStatements ["true", "hint '';"];

//hint "";
waituntil {moveToCompleted leader GroupTank};
//hint ""; 


//Bravo waypoint
wp3 = GroupTank addwaypoint [position Player, 50]; 
wp3 waypointAttachVehicle vehicle player;  
wp3 setwaypointtype "MOVE"; 
wp3 setWaypointCombatMode "YELLOW"; 
wp3 setWaypointFormation "VEE"; 
wp3 setWaypointSpeed "FULL"; 
wp3 setWaypointBehaviour "AWARE"; 
wp3 setWaypointCompletionRadius 10;
wp3 setWaypointStatements ["true", "hint '';"];


//Charlie waypoint
wp4 = GroupTank addwaypoint [position Player, 50]; 
wp4 waypointAttachVehicle vehicle player; 
wp4 setwaypointtype "Cycle"; 

You can change the [position Player, 50] to a big distance and you could change the combatmode to "RED"

I am using this setup for a group of JETS to move to may location to give me CAS for a few minutes. May issue without this SETUP the jets would fly off all over the map to chase other opfor units. Still not 100% staying in the area of support for me because the planes have a better and larger LOS and if set to RED/YELLOW they will target what they can see. Hope this helps. AVIBIRD.

This seems to work in that they don't return to the original waypoint as I can see. But after I die once, they seem to circle constantly around the player HQ/respawn point. :S

I'll see if I can get use for Mattar's script for a patrolling attack heli later hehe. :)

Edited by Gotipe

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  

×