Jump to content
JR Nova

Spawned AI not following waypoints sometimes

Recommended Posts

I'm trying to spawn AI units in groups that spawn more and more units each wave and the units start wearing more armor over time.

 

I got the loadouts and spawns working properly but after about wave 5, units sometimes stop following their waypoints. I can hear them on the radio ordering guys to move but they just move into formation where they spawn then never move. Its very bad on vehicles, they have about a 50% chance of moving after they spawn.

 

Any idea what I'm doing wrong?

 

init.sqf

Spoiler

call compile preprocessfile "SHK_pos\shk_pos_init.sqf";

waitUntil {player == player && time > 1};



waveLvl=1;
publicVariable "waveLvl";

playerNum = playersNumber west;
publicVariable "playerNum";

incomingEnemy = false;



null=[] execVM "Spawn.sqf";

 


spawn.sqf

Spoiler

//WAVES 1-2 - 1 group
if ((waveLvl <= 2) && !incomingEnemy) then {
    private ["_pos", "_group", "_wp"];
    incomingEnemy = true;
    hint format ["Enemies incoming. Wave %1", waveLvl];
    
    //GROUP 1 - 2 or 4 units + player count
    _pos = [attackPos, [150,200]] call SHK_pos;
    _group = [_pos, resistance, playerNum + waveLvl * 2] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Basic","0arm_Rifle"]] execVM "loadouts.sqf";} forEach units _group;
    _group deleteGroupWhenEmpty true;
    _stalking = [_group, group player,nil,10,{player distance _group < 600}] spawn BIS_fnc_stalk;
    
    waitUntil {({(side _x) == resistance} count allUnits) == 0};
    hint "Wave complete.";
    sleep 5;
    { deleteVehicle _x } forEach allDead;
    incomingEnemy = false;
    waveLvl = waveLvl+1;
    sleep 25;
    null=[] execVM "Spawn.sqf";
};

//WAVES 3-4 - 2 groups
if ((waveLvl > 2) && (waveLvl <= 4) && !incomingEnemy) then {
    private ["_pos", "_group", "_wp"];
    incomingEnemy = true;
    hint format ["Enemies incoming. Wave %1", waveLvl];
    
    //GROUP 1 - 3 or 4 units + player count
    _pos = [attackPos, [150,200]] call SHK_pos;
    _group = [_pos, resistance, playerNum + waveLvl] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Basic","0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group;
    _group deleteGroupWhenEmpty true;
    _stalking = [_group, group player,nil,10,{player distance _group < 600}] spawn BIS_fnc_stalk;
    
    //GROUP 2 - player count
    _pos2 = [attackPos, [150,200]] call SHK_pos;
    _group2 = [_pos2, resistance, playerNum] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group2;
    _group2 deleteGroupWhenEmpty true;
    _stalking2 = [_group2, group player,nil,10,{player distance _group2 < 600}] spawn BIS_fnc_stalk;
    
    waitUntil {({(side _x) == resistance} count allUnits) == 0};
    hint "Wave complete.";
    sleep 5;
    { deleteVehicle _x } forEach allDead;
    incomingEnemy = false;
    waveLvl = waveLvl+1;
    sleep 25;
    null=[] execVM "Spawn.sqf";
};

//WAVES 5-6 1 group, 1 offroad
if ((waveLvl > 4) && (waveLvl <= 6) && !incomingEnemy) then {
    private ["_pos", "_group", "_wp"];
    incomingEnemy = true;
    hint format ["Enemies incoming. Wave %1", waveLvl];
    
    //GROUP 1 - 5 or 6 units + player count
    _pos = [attackPos, [150,200]] call SHK_pos;
    _group = [_pos, resistance, waveLvl + playerNum] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group;
    _group deleteGroupWhenEmpty true;
    _stalking = [_group, group player,nil,10] spawn BIS_fnc_stalk;
    
    //Offroad
    _posVEH = [attackPos, [250,300]] call SHK_pos;
    _VEHgrp = createGroup resistance;
    _VEH = [_posVEH, 180, "I_G_Offroad_01_armed_F", _VEHgrp] call bis_fnc_spawnvehicle;
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _VEHgrp;
    _VEHgrp deleteGroupWhenEmpty true;
    _stalkingVEH = [_VEHgrp, group player,nil,10] spawn BIS_fnc_stalk;
    
    waitUntil {({(side _x) == resistance} count allUnits) == 0};
    hint "Wave complete.";
    sleep 5;
    { deleteVehicle _x } forEach allDead;
    incomingEnemy = false;
    waveLvl = waveLvl+1;
    sleep 25;
    null=[] execVM "Spawn.sqf";
};

//WAVES 7-8 - 2 groups, 1 offroad
if ((waveLvl > 6) && (waveLvl <= 😎 && !incomingEnemy) then {
    private ["_pos", "_group", "_wp"];
    incomingEnemy = true;
    hint format ["Enemies incoming. Wave %1", waveLvl];
    
    //GROUP 1 - 7 - 9 units
    _pos = [attackPos, [150,200]] call SHK_pos;
    _group = [_pos, resistance, waveLvl] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG","1arm_Rifle","1arm_GL","1arm_MG"]] execVM "loadouts.sqf";} forEach units _group;
    _group deleteGroupWhenEmpty true;
    _stalking = [_group, group player,nil,10] spawn BIS_fnc_stalk;
    
    //GROUP 2 - player count + 1
    _pos2 = [attackPos, [150,200]] call SHK_pos;
    _group2 = [_pos2, resistance, playerNum + 1] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group2;
    _group2 deleteGroupWhenEmpty true;
    _stalking2 = [_group2, group player,nil,10] spawn BIS_fnc_stalk;
    
    //Offroad
    _posVEH = [attackPos, [250,300]] call SHK_pos;
    _VEHgrp = createGroup resistance;
    _VEH = [_posVEH, 180, "I_G_Offroad_01_armed_F", _VEHgrp] call bis_fnc_spawnvehicle;
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _VEHgrp;
    _VEHgrp deleteGroupWhenEmpty true;
    _stalkingVEH = [_VEHgrp, group player,nil,10] spawn BIS_fnc_stalk;
    
    waitUntil {({(side _x) == resistance} count allUnits) == 0};
    hint "Wave complete.";
    sleep 5;
    { deleteVehicle _x } forEach allDead;
    incomingEnemy = false;
    waveLvl = waveLvl+1;
    sleep 25;
    null=[] execVM "Spawn.sqf";
};

//WAVES 9-10 - 2 groups, 2 offroads
if ((waveLvl > 😎 && (waveLvl <= 10) && !incomingEnemy) then {
    private ["_pos", "_group", "_wp"];
    incomingEnemy = true;
    hint format ["Enemies incoming. Wave %1", waveLvl];
    
    //GROUP 1 - 4 - 5 units + player count 
    _pos = [attackPos, [150,200]] call SHK_pos;
    _group = [_pos, resistance, waveLvl / 2 + playerNum] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG","1arm_Rifle","1arm_GL","1arm_MG"]] execVM "loadouts.sqf";} forEach units _group;
    _group deleteGroupWhenEmpty true;
    _stalking = [_group, group player,nil,10] spawn BIS_fnc_stalk;
    
    //GROUP 2 - 4 - 5 units + player count 
    _pos2 = [attackPos, [150,200]] call SHK_pos;
    _group2 = [_pos2, resistance, waveLvl / 2 + playerNum] call bis_fnc_spawngroup; 
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group2;
    _group2 deleteGroupWhenEmpty true;
    _stalking2 = [_group2, group player,nil,10] spawn BIS_fnc_stalk;
    
    //Offroad
    _posVEH = [attackPos, [250,300]] call SHK_pos;
    _VEHgrp = createGroup resistance;
    _VEH = [_posVEH, 180, "I_G_Offroad_01_armed_F", _VEHgrp] call bis_fnc_spawnvehicle;
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _VEHgrp;
    _VEHgrp deleteGroupWhenEmpty true;
    _stalkingVEH = [_VEHgrp, group player,nil,10] spawn BIS_fnc_stalk;
    
    //Offroad
    _posVEH2 = [attackPos, [250,300]] call SHK_pos;
    _VEHgrp2 = createGroup resistance;
    _VEH2 = [_posVEH2, 180, "I_G_Offroad_01_armed_F", _VEHgrp2] call bis_fnc_spawnvehicle;
    {[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _VEHgrp2;
    _VEHgrp2 deleteGroupWhenEmpty true;
    _stalkingVEH2 = [_VEHgrp2, group player,nil,10] spawn BIS_fnc_stalk;
    
    waitUntil {({(side _x) == resistance} count allUnits) == 0};
    hint "Wave complete.";
    sleep 5;
    { deleteVehicle _x } forEach allDead;
    incomingEnemy = false;
    waveLvl = waveLvl+1;
    sleep 25;
    null=[] execVM "Spawn.sqf";
};

 

 

 

Edited by JR Nova
fixed emojis in code
  • Like 1

Share this post


Link to post
Share on other sites

@JR Nova,

Quote

Not sure how to remove the emojis lol they are 8 ) without the space

Put a "Code" in your "Spoiler".

As for the way-points. The AI are probably doing whatever they're supposed to do based on their behavior mode, ect. They may need more specific directions.

  • Thanks 1

Share this post


Link to post
Share on other sites

Ah, thanks for the help!

 

I finally got it working by running a code on the spawned groups that give them a doMove command to an invisible heli pad named "attackPos", waits a minute, then runs the stalker code.

 

I renamed spawn.sqf from original post to waves.sqf

 

init.sqf

Spoiler

call compile preprocessfile "SHK_pos\shk_pos_init.sqf";

waitUntil {player == player && time > 1};



waveLvl=1;
publicVariable "waveLvl";

playerNum = playersNumber west;
publicVariable "playerNum";

incomingEnemy = false;



null=[] execVM "waves.sqf";

 

 

waves.sqf

Spoiler

//WAVES 1-2 - 1 group
if ((waveLvl <= 2) && !incomingEnemy) then {
	private ["_pos", "_group", "_wp"];
	incomingEnemy = true;
	hint format ["Enemies incoming. Wave %1", waveLvl];
	
	//GROUP 1 - 2 or 4 units + player count
	_pos = [attackPos, [150,200]] call SHK_pos;
	_group = [_pos, resistance, playerNum + waveLvl * 2] call bis_fnc_spawngroup; 
	{[_x, selectRandom ["0arm_Basic","0arm_Rifle"]] execVM "loadouts.sqf";} forEach units _group;
	_group deleteGroupWhenEmpty true;
	[_group,getPos attackPos] execVM 'spawn.sqf';
	
	waitUntil {({(side _x) == resistance} count allUnits) == 0};
	hint "Wave complete.";
	sleep 5;
	{ deleteVehicle _x } forEach allDead;
	incomingEnemy = false;
	waveLvl = waveLvl+1;
	sleep 6;
	null=[] execVM "waves.sqf";
};

//WAVES 3-4 - 2 groups
if ((waveLvl > 2) && (waveLvl <= 4) && !incomingEnemy) then {
	private ["_pos", "_group", "_wp"];
	incomingEnemy = true;
	hint format ["Enemies incoming. Wave %1", waveLvl];
	
	//GROUP 1 - 3 or 4 units + player count
	_pos = [attackPos, [150,200]] call SHK_pos;
	_group = [_pos, resistance, playerNum + waveLvl] call bis_fnc_spawngroup; 
	{[_x, selectRandom ["0arm_Basic","0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group;
	_group deleteGroupWhenEmpty true;
	[_group,getPos attackPos] execVM 'spawn.sqf';
	
	//GROUP 2 - player count + 1
	_pos2 = [attackPos, [150,200]] call SHK_pos;
	_group2 = [_pos2, resistance, playerNum + 1] call bis_fnc_spawngroup; 
	{[_x, selectRandom ["0arm_Rifle","0arm_GL","0arm_MG"]] execVM "loadouts.sqf";} forEach units _group2;
	_group2 deleteGroupWhenEmpty true;
	[_group2,getPos attackPos] execVM 'spawn.sqf';
	
	waitUntil {({(side _x) == resistance} count allUnits) == 0};
	hint "Wave complete.";
	sleep 5;
	{ deleteVehicle _x } forEach allDead;
	incomingEnemy = false;
	waveLvl = waveLvl+1;
	sleep 6;
	null=[] execVM "waves.sqf";
};

 

 

spawn.sqf

Spoiler

_group = _this select 0;
_attackPos = _this select 1;

_group move _attackPos;

sleep 60;
_stalking = [_group, group player,nil,10,{player distance _group < 600}] spawn BIS_fnc_stalk;

 

 

  • Like 1

Share this post


Link to post
Share on other sites

I had a similar problem a while ago. I had it happen when I spawned vehicles out in the terrain, but it worked when spawning them on a road.

 

My solution was to monitor their movement after spawn, and if they did not get moving in a minute I deleted their waypoint and created a new. That usually had them start moving.

 

I’m not sure if I gave them different behavior for different waypoints, but I had some kind of randomizaton about that.

Share this post


Link to post
Share on other sites
19 minutes ago, engima said:

I had a similar problem a while ago. I had it happen when I spawned vehicles out in the terrain, but it worked when spawning them on a road.

 

My solution was to monitor their movement after spawn, and if they did not get moving in a minute I deleted their waypoint and created a new. That usually had them start moving.

 

I’m not sure if I gave them different behavior for different waypoints, but I had some kind of randomizaton about that.

@engima
I have had issues ever since the recent DLC update with spawned groups that refuse to move again after reaching the first waypoint.
Any chance you could share an example of your workaround?

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

×