Jump to content
Sign in to follow this  
Kingsley1997

Multiple helicopters being spawned with BIS_fnc_spawnVehicle

Recommended Posts

I have no idea how this code is not working... It's supposed to check a "zone" every 5 seconds, checks if there aren't any enemies in it. If there aren't any enemies within the given radius of the zone (marker) then it will mark that zone as complete in the DB. It then checks the rest of the other zones, and if they are ALL complete, then it will proceed to the end process which is to spawn a helicopter (Huron) and waypoint it to the chosen LZ position.

The problem is, no matter how I end the "while" loop with either a variable switch or a "breakOut" it will still continue and spawn more helicopters causing them to hilariously crash into each other...

Any suggestions? Code below.

EDIT - The code below is being executed on the server!

private ["_zonName", "_radiusToCheck", "_fobName"];

_zonName = _this select 0;
_radiusToCheck = _this select 1;
_fobName = _this select 2;
_endProcess = false;

while { true } do {
scopeName "zoneCheckLoop";

_nearMen = (getMarkerPos _zonName) nearEntities ["Man", _radiusToCheck];
_zoneClear = true;

{
	if (side _x == east) then {
		_zoneClear = false;
	};
} forEach _nearMen;

if (_zoneClear) then {
	["Zone End", false] call fn_devLog;
	_zonName setMarkerColor "ColorWEST";
	["zones", _zonName, "status", "2"] call iniDB_write; // 1 = EAST CONTROL	2 = WEST CONTROL

	// Check other zones
	_allZonesComplete = true;

	["Starting Zone Loop", false] call fn_devLog;
	for "_z" from 0 to 10 do {
		scopeName "zEndLoop";
		_mrkName = format["%1_aiZone_%2", _fobName, _z];

		if (getMarkerColor _mrkName == "") then {
			// Marker doesn't exist, gone too far
			breakOut "zEndLoop";
		} else {
			if (getMarkerColor _mrkName != "ColorWEST") then {
				_allZonesComplete = false;
			};
		};
	};

	if (_allZonesComplete && !_endProcess) then {
		["All Zones Complete", false] call fn_devLog;
		// Tour completed
		{
			if (isPlayer _x) then {
				// Start end tour process for this player (_x)
				if (local _x) then {
					hint "Tour Complete. Well done!";
				};
			};
		} forEach playableUnits;

		// Start end tour process for this FOB (_fobName)
		_randLZ = (getMarkerPos _fobName) findEmptyPosition [0, 2000, "B_Heli_Transport_03_F"];

		if (count _randLZ > 0) then {
			["Found LZ position", false] call fn_devLog;
			// [position,direction,type,side or group] call BIS_fnc_spawnVehicle
			_hPad = "Land_HelipadEmpty_F" createVehicle _randLZ;
			_heli = [(getMarkerPos "heli_spawn"), 45, "B_Heli_Transport_03_F", west] call BIS_fnc_spawnVehicle;

			_endProcess = true;

			// Debug
			player moveInCargo _heli select 0;

			_heli select 0 call { _heli select 0 allowDamage false; };
			_heliGrp = _heli select 2;
			_wp = _heliGrp addWaypoint [_randLZ, 0];
			_wp setWaypointBehaviour "CARELESS";
			_wp setWaypointCombatMode "RED";
			_wp setWaypointCompletionRadius 0;
			_wp setWaypointFormation "NO CHANGE";
			_wp setWaypointSpeed "FULL";
			_wp setwaypointType "LOAD";

			_wpMrkName = format ["%1_LZ", _fobName];
			_marker = createMarker [_wpMrkName, _randLZ];
			_marker setMarkerShape "ICON";
			_marker setMarkerSize [1, 1];
			_marker setMarkerColor "ColorWEST";
			_marker setMarkerType "hd_pickup";

			breakOut "zoneCheckLoop";
		} else {
			// Can't find LZ position?
			["Can't find LZ position", false] call fn_devLog;
		};
	};
};

sleep 5;
};

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  

×