Jump to content

Recommended Posts

So here's a weird one:

I have a custom function setup in my scenario which:

  1. Spawns in an IFV
  2. Spawns a group to crew it
  3. Spawns a group to ride in the back
  4. Tells both groups to drive to a marker and eject the infantry
  5. Tells both groups to attack an area with BIS_fnc_taskAttack


It works as expected, in fact, quite well.

There's just 1 problem - every 2nd time I spawn this function, the infantry in the back dismount as soon as they spawn in and hoof it all the way to the marker. I've tested multiple times and it's consistent. For example, if I spawn this function 8 times, the 1st, 3rd, 5th, and 7th time will work perfectly and the 2nd, 4th, 6th, and 8th will dismount the infantry as soon as they spawn. This occurs in both a singleplayer and multiplayer (LAN) environment. It's too consistent to be a random error - it's clearly something I've missed in how my function is set up but I've had no luck finding a lead for about 5 days now.

Here's the function (it is defined within cfgfunctions.hpp and works without spitting out errors when I spawn it):

if !(isServer) exitWith {};
_unitClass = "Unknown";



//DEFINE GROUPS
_bIfvGroup = ["B_crew_F","B_crew_F"];
_bIfvInfGroup = ["B_soldier_F","B_soldier_F","B_Patrol_Soldier_MG_F","B_engineer_F","B_soldier_F","B_recon_F"];



//SPAWN IFV
_bNewVehicleIfv = createVehicle ["B_APC_Wheeled_01_cannon_F", [27635,23853,0], [], 0, "NONE"];
_bNewVehicleIfv setDir 227;
_bNewVehicleIfv lockturret [[0,0],true];
clearWeaponCargoGlobal _bNewVehicleIfv;
clearMagazineCargoGlobal _bNewVehicleIfv;
clearBackpackCargoGlobal _bNewVehicleIfv;
clearItemCargoGlobal _bNewVehicleIfv;



//SPAWN IFV CREW
newBluforIfvCrew = createGroup [west,true];

{
	_newBluforCrewUnit = _x createUnit [getMarkerPos "bAiSpawn02",newBluforIfvCrew,"newBluforCrewUnit=this"];
	{
		[newBluforCrewUnit] call LIZ_fnc_bCrewLoadout;
		if alive driver _bNewVehicleIfv then {newBluforCrewUnit moveInGunner _bNewVehicleIfv;} else {newBluforCrewUnit moveInDriver _bNewVehicleIfv;};
		newBluforCrewUnit disableAI "FSM";
		newBluforCrewUnit allowFleeing 0;
		newBluforIfvCrew setSpeedMode "FULL";
	} foreach units (newBluforIfvCrew);
} foreach _bIfvGroup;

_bNewVehicleIfv lockDriver true;

sleep 2;

//SPAWN IFV INFANTRY
newBluforIfvInfGroup = createGroup [west,true];

{
	_newBluforMechUnit = _x createUnit [getMarkerPos "bAiSpawn02",newBluforIfvInfGroup,"newBluforMechUnit=this"];
	{
		if (typeOf newBluforMechUnit == "B_soldier_F") then {_unitClass = "Rifleman";};
		if (typeOf newBluforMechUnit == "B_Patrol_Soldier_MG_F") then {_unitClass = "MG";};
		if (typeOf newBluforMechUnit == "B_engineer_F") then {_unitClass = "AT";};
		if (typeOf newBluforMechUnit == "B_recon_F") then {_unitClass = "Recon";};
		switch (_unitClass) do {
			case "Rifleman":
			{
				[newBluforMechUnit] spawn LIZ_fnc_bRifleLoadout;
			};
			case "MG":
			{
				[newBluforMechUnit] spawn LIZ_fnc_bMgLoadout;
			};
			case "AT":
			{
				[newBluforMechUnit] spawn LIZ_fnc_bAtLoadout;
			};
			case "Recon":
			{
				[newBluforMechUnit] spawn LIZ_fnc_bReconLoadout;
			};
		};
		newBluforMechUnit moveInCargo _bNewVehicleIfv;
		newBluforIfvInfGroup setSpeedMode "FULL";
	} foreach units (newBluforIfvInfGroup);
} foreach _bIfvInfGroup;

sleep 1;

//RANDOM OBJECTIVE MARKER
_randomDismountMarker = ["dismountMarker01","dismountMarker02","dismountMarker03","dismountMarker04"] call BIS_fnc_selectRandom;
_randomObjMarker = ["combatMarker01","combatMarker02","combatMarker03"] call BIS_fnc_selectRandom;



//SEND ORDERS FOR IFV CREW
_wp1 = newBluforIfvCrew addWaypoint [getMarkerPos _randomDismountMarker, 0];
_wp1 setWaypointType "TR UNLOAD";
_wp1 setWaypointSpeed "FULL";



//SEND ORDERS FOR INFANTRY GROUP
_wp2 = newBluforIfvInfGroup addWaypoint [getMarkerPos _randomDismountMarker, 0];
_wp2 setWaypointType "GETOUT";
newBluforIfvInfGroup setBehaviourStrong "AWARE";
newBluforIfvInfGroup setSpeedMode "FULL";



[newBluforIfvCrew, 0] synchronizeWaypoint [ [newBluforIfvInfGroup, 0] ];



//IFV LEAVES INFANTRY ATTACKS
waitUntil {({_x in _bNewVehicleIfv} count (units newBluforIfvInfGroup)) < 6};

[newBluforIfvInfGroup] spawn LIZ_fnc_eject;

waitUntil {({_x in _bNewVehicleIfv} count (units newBluforIfvInfGroup)) < 1};

sleep 2;

[newBluforIfvInfGroup, getMarkerPos _randomObjMarker] call BIS_fnc_taskAttack;
[newBluforIfvCrew, getMarkerPos _randomObjMarker] call BIS_fnc_taskAttack;

Currently this function is triggered by me using a Radio Trigger for testing - 0 = [] spawn LIZ_fnc_bIfvSpawn. I also considered that my other function LIZ_fnc_eject (which ejects the infantry from the IFV) might have something to do with it, so here it is:

_infantry = _this select 0;

{
	unassignVehicle (_x);
	(_x) action ["EJECT", vehicle _x];
	sleep 0.2;
} foreach units (_infantry);

sleep 3;

If you can see my error, or if I've unwittingly left out some key piece of information, please let me know.

Help me BI forums, you're my only hope.

  • Like 1

Share this post


Link to post
Share on other sites
Spoiler

if !(isServer) exitWith {};

//DEFINE GROUPS UNIT TYPES
_ifvCrewTypes = [ "B_crew_F", "B_crew_F" ];
_ifvInfTypes = [ "B_soldier_F", "B_soldier_F", "B_Patrol_Soldier_MG_F", "B_engineer_F", "B_soldier_F", "B_recon_F" ];

//SPAWN IFV VEHICLE
_ifvVehicle = createVehicle[ "B_APC_Wheeled_01_cannon_F", [27635,23853,0], [], 0, "NONE" ];
_ifvVehicle setDir 227;
_ifvVehicle lockTurret[ [0,0], true ];

clearWeaponCargoGlobal _ifvVehicle;
clearMagazineCargoGlobal _ifvVehicle;
clearBackpackCargoGlobal _ifvVehicle;
clearItemCargoGlobal _ifvVehicle;

//SPAWN IFV CREW
_ifvCrewGroup = createGroup[ west, true ];
_ifvCrewGroup setSpeedMode "FULL";

{
	//Changed createUnit to main syntax that DOES return the unit created
	//Rather than the newBluforCrewUnit=this init nonsense
	_ifvCrewUnit = _ifvCrewGroup createUnit[ _x, getMarkerPos "bAiSpawn02", [], 0, "FORM" ];
	
	//Removed inner foreach loop, no need to looop every unit in the group every time a unit is added to the group
	//of which because of the newBluforCrewUnit stuff would set that particular unit up multiplied by number of units in the group
	
	[ _ifvCrewUnit ] call LIZ_fnc_bCrewLoadout;
	
	//Driver will be NULL if there isnt one
	if ( isNull driver _ifvVehicle ) then {
		_ifvCrewUnit moveInDriver _ifvVehicle;
		_ifvVehicle lockDriver true; //Moved here, added driver so lock
	} else {
		_ifvCrewUnit moveInGunner _ifvVehicle;
	};
	
	_ifvCrewUnit disableAI "FSM";
	_ifvCrewUnit allowFleeing 0;	
}forEach _ifvCrewTypes;

sleep 2;

//SPAWN IFV INFANTRY
_ifvInfGroup = createGroup[ west, true ];
_ifvInfGroup setSpeedMode "FULL";
_ifvInfGroup addVehicle _ifvVehicle;

{
	//Changed createUnit to main syntax that DOES return the unit created
	//Rather than the newBluforMechUnit=this init nonsense
	_ifvInfUnit = _ifvInfGroup createUnit[ _x, getMarkerPos "bAiSpawn02", [], 0, "FORM" ];
	
	//Removed inner foreach loop, no need to loop every unit in the group every time a unit is added to the group
	//of which because of the newBluforMechUnit stuff would set that particular unit up multiplied by number of units in the group
	
	//No need to convert unit types here, just do a switch straight on their type
	switch ( toLower typeOf _ifvInfUnit ) do {
		// Rifleman
		case "b_soldier_f":
		{
			[ _ifvInfUnit ] spawn LIZ_fnc_bRifleLoadout;
		};
		// MG
		case "b_patrol_soldier_mg_f":
		{
			[ _ifvInfUnit ] spawn LIZ_fnc_bMgLoadout;
		};
		// AT
		case "b_engineer_f":
		{
			[ _ifvInfUnit ] spawn LIZ_fnc_bAtLoadout;
		};
		// Recon
		case "b_recon_f":
		{
			[ _ifvInfUnit ] spawn LIZ_fnc_bReconLoadout;
		};
	};
	
	_ifvInfUnit moveInCargo _ifvVehicle;
}forEach _ifvInfTypes;

sleep 1;

//RANDOM OBJECTIVE MARKER
_randomDismountMarker = selectRandom[ "dismountMarker01", "dismountMarker02", "dismountMarker03", "dismountMarker04" ];
_randomObjMarker = selectRandom[ "combatMarker01", "combatMarker02", "combatMarker03" ];

//SEND ORDERS FOR IFV CREW
_wp1 = _ifvCrewGroup addWaypoint[ getMarkerPos _randomDismountMarker, 0 ];
_wp1 setWaypointType "TR UNLOAD";
_wp1 setWaypointSpeed "FULL";

//SEND ORDERS FOR INFANTRY GROUP
_wp2 = _ifvInfGroup addWaypoint[ getMarkerPos _randomDismountMarker, 0 ];
_wp2 setWaypointType "GETOUT";
//When inf gets out setBehaviour and unassign vehicle for EH, see //IFV LEAVES INFANTRY ATTACKS
_wp2 setWaypointStatements[ "true", format[ "
	_infGroup = group this;
	_infGroup setBehaviourStrong 'AWARE';
	_infGroup leaveVehicle ( '%1' call BIS_fnc_objectFromNetId );
", _ifvVehicle call BIS_fnc_netId ] ];

// [ group, 0 ] is NOT what you think it is,
//waypoint 0 of a group is the position they were spawned in at
//NOT the first waypoint added to the group
//We know the waypoints as they were added above so just use them
_wp1 synchronizeWaypoint [ _wp2 ];

//place objective marker on vehicle so we can retrieve it in the EH
_ifvVehicle setVariable[ "randomObjMarker", _randomObjMarker ];

//IFV LEAVES INFANTRY ATTACKS
//Why LIZ_fnc_eject? you have already given them a GETOUT wp
//I have given the group a leaveVehicle in the waypoint statement above instead

//When the group activates their GETOUT wp we remove the vehicle from the group so this EH will fire
_ifvInfGroup addEventHandler[ "VehicleRemoved", {
	params[ "_group", "_oldVehicle" ];
	
	_randomObjMarker = _oldVehicle getVariable "randomObjMarker";
	
	[ _group, getMarkerPos _randomObjMarker ] call BIS_fnc_taskAttack;
	[ group driver _oldVehicle, getMarkerPos _randomObjMarker ] call BIS_fnc_taskAttack;
}];

 

Added some comments, untested, not sure if it will fix your particular problem.

  • Like 2

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

×