Jump to content
Aviox93

AI vehicles spawned don't move.

Recommended Posts

Hi !

My goal is to make a domination mission, with 10 differentes sectors (Alpha,Beta,.....,India,Juliet).

So I made a script that spawn regularly enemy APCs (every 15s in the following script). 

Warning : Big script but nothing complicated !

_ingame = true;

while {_ingame} do {
	r = random 10;
	switch (true) do {
		case (r<=3): { //BMP2
			_BMP2 = "CUP_O_BMP2_RU" createVehicle getmarkerpos "spawn_apc_r";
			_squad = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_crew","min_rf_engineer","min_rf_soldier_repair","min_rf_crew","min_rf_crew"]] call BIS_fnc_SpawnGroup;
			_squad2 = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_soldier_SL","min_rf_soldier","min_rf_support_Mort","min_rf_soldier"]] call BIS_fnc_SpawnGroup;
			{
				_x MoveInAny _BMP2;
			} forEach units _squad;
			{
				_x MoveInCargo _BMP2;
			} forEach units _squad2;
			null = [_squad] execVM "patrol.sqf";
		};
		case (r<=5): { //BMP3
			_BMP3 = "CUP_O_BMP3_RU" createVehicle getmarkerpos "spawn_apc_r";
			_squad = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_crew","min_rf_engineer","min_rf_soldier_repair"]] call BIS_fnc_SpawnGroup;
			_squad2 = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_soldier_SL","min_rf_soldier","min_rf_support_Mort","min_rf_soldier","min_rf_soldier"]] call BIS_fnc_SpawnGroup;
			{
				_x MoveInAny _BMP3;
			} forEach units _squad;
			{
				_x MoveInCargo _BMP3;
			} forEach units _squad2;
			null = [_squad] execVM "patrol.sqf";
		};
		case (r<=7): { //T15
			_T15 = "min_rf_t_15" createVehicle getmarkerpos "spawn_apc_r";
			_squad = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_crew","min_rf_engineer","min_rf_soldier_repair"]] call BIS_fnc_SpawnGroup;
			_squad2 = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_soldier_SL","min_rf_soldier","min_rf_support_Mort","min_rf_soldier","min_rf_soldier"]] call BIS_fnc_SpawnGroup;
			{
				_x MoveInAny _T15;
			} forEach units _squad;
			{
				_x MoveInCargo _T15;
			} forEach units _squad2;
			null = [_squad] execVM "patrol.sqf";
		};
		case (r<=10): { //MTLB
			_MTLB = "CUP_O_MTLB_pk_Green_RU" createVehicle getmarkerpos "spawn_apc_r";
			_squad = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_crew","min_rf_soldier_repair"]] call BIS_fnc_SpawnGroup;
			_squad2 = [getmarkerpos "spawn_infantry_r", east,
						["min_rf_soldier_SL","min_rf_soldier","min_rf_support_Mort","min_rf_soldier","min_rf_soldier"]] call BIS_fnc_SpawnGroup;
			{
				_x MoveInAny _MTLB;
			} forEach units _squad;
			{
				_x MoveInCargo _MTLB;
			} forEach units _squad2;
			null = [_squad] execVM "patrol.sqf";
		};
	};
	sleep 15;
}

And my patrol.sqf file juste gives a "move" waypoint and the patrol task to the group after the group gets to the "move" waypoint :

 

_squad = (_this select 0);
r = random 20;
switch (true) do {
	case (r<=4): { //Alpha
		hint "Alpha";
		_wp = _squad addWaypoint [ getMarkerPos "m_alpha", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_alpha", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=7): { //Beta
		hint "Beta";
		_wp = _squad addWaypoint [ getMarkerPos "m_beta", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_beta", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=9): { //Charlie
		hint "Charlie";
		_wp = _squad addWaypoint [ getMarkerPos "m_charlie", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_charlie", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=11): { //Delta
		hint "Delta";
		_wp = _squad addWaypoint [ getMarkerPos "m_delta", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_delta", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=13): { //Echo
		hint "Echo";
		_wp = _squad addWaypoint [ getMarkerPos "m_echo", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_echo", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=15): { //Foxtrot
		hint "Foxtrot";
		_wp = _squad addWaypoint [ getMarkerPos "m_foxtrot", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_foxtrot", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=16): { //Golf
		hint "Golf";
		_wp = _squad addWaypoint [ getMarkerPos "m_golf", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_golf", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=17): { //Hotel
		hint "Hotel";
		_wp = _squad addWaypoint [ getMarkerPos "m_hotel", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_hotel", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=19): { //India
		hint "India";
		_wp = _squad addWaypoint [ getMarkerPos "m_india", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_india", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};
	case (r<=20): { //Juliet
		hint "Juliet";
		_wp = _squad addWaypoint [ getMarkerPos "m_juliet", 5];
		_wp setWaypointType "MOVE";
		[_squad, getMarkerPos "m_juliet", 700] call BIS_fnc_TaskPatrol;
		_squad setBehaviour "AWARE";
		_squad setSpeedMode "NORMAL";
	};

};

Anyways, the script works but 40% of the vehicles just appear and don't move. And when there are these kinds of errors, the vehicle appeared and the sector chosen is never the same.
(this can happen for a T14 on Golf, or a BMP2 on Alpha even if other BMP2s have gone to Alpha without problems before...).

I also tried to spawn only vehicle when I launch the scenario and it seems to work every time.

I then made a script to spawn multiple BMP2s to golf (since golf had 70% errors), and it seems like the first and second BMP2s go to Golf but every time the third don't move and after it, it's random.

Thanks for helping, I have no idea what it could be!

Share this post


Link to post
Share on other sites

Convert your global variable  r to a local variable like  _r. They are conflicting with each other. Update all references under it of course.

Share this post


Link to post
Share on other sites
6 hours ago, RCA3 said:

Convert your global variable  r to a local variable like  _r. They are conflicting with each other. Update all references under it of course.

Hey thx for your answer ! You're right indeed, however, it doesn't solve the issue since the issue seems to come from the fact that a sector is chosen but the apc is just not following the waypoint. 😕

Share this post


Link to post
Share on other sites

Alr guys I did some test and it seems to work better when I'm moving only 3 soldiers into it. When its more than 3 soldiers, 50% of the times the APC won't move. Any ideas? (There is still the issue tho)

And some stuck APCs seem to move after 1/2 minutes spawning

Share this post


Link to post
Share on other sites

And with only one soldier inside the vehicle it seems that no apcs are stuck. (Some of them still don't move when they spawn but start moving 20/30s after).

It's really weird... If any of you wants a video so I can show you the issue, no problem.

Share this post


Link to post
Share on other sites

Try applying private to all local variables, like so:

private _ingame = true;

Do it to all local (_thisIsLocal) variables.

If you're just using CUP you can share your mission and i'll take a look. DM if you want.

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

×