Jump to content
RoryRothon

Check if crew left vehicle or vehicle destroyed?

Recommended Posts

Hey there.

 

I am working on a custom coded mission called "Operation Missdrop" where players have jumped out of a struck airframe and are scattered across the map.
All the while, players have East and Guer hunting them down which includes vehicles...
Although i have everything working great, i have hit an issue regarding vehicles and crews..

_eastPatrolVehicle = [ _spawnPos, 180, (selectRandom (RAZ_fnc_groundPatrolVehiclesEast)), East ] call bis_fnc_spawnvehicle;

_veh = _eastPatrolVehicle select 0;

_crew = _eastPatrolVehicle select 2;

Currently i have a waituntil holding the script until the _veh is destroyed.
I want to create a check that checks if the vehicle is destroyed or all crew members are dead...
You can see my attempted commented below haha       

 waitUntil { !alive _veh };

        //waitUntil { ({!alive _x;} forEach crew _veh;) or (!alive _veh) };

        if ( debugScript ) then { format ["East vehicle has been destroyed, or all crew members are dead!"] remoteExec ["systemChat"]; };

        deleteWaypoint [_crew, 0];

        { deleteVehicle _x } forEach units _crew;

        deleteGroup _crew;

        sleep 300;

 

So to clarify:

 

  1. Check to see if either the vehicle is destroyed or all crew are dead
  2. if all crew are dead, do nothing to the vehicle and leave it on the map
  3. If vehicle empty but crew are alive, do nothing and wait until the crew or vehicle are dead

 

I hope this makes sense lol
Kind regards
Rory

Share this post


Link to post
Share on other sites

Just to point out, my commented code was used without the waitUntil above it.....

Share this post


Link to post
Share on other sites

This provides a few cases that can/will happen:

  • Vehicle has been abandoned
  • Vehicle can no longer move (at least 2 tires popped)
  • Vehicle has been destroyed
  • Vehicle crew has been killed

Can easily expand from there and handle each case separately if that's what you want:


GOM_fnc_vehicleDeleteCheck = {

	params ["_veh"];

	//check if vehicle is destroyed
	_veh addEventHandler ["Killed",{
		systemchat "Vehicle has been destroyed.";//add a respawn script here, or whatever you seem fit
	}];


	//check when no more crewmembers are alive
	{
		_x addEventHandler ["Killed",{
			params ["_killed"];
			if ({alive _x} count units _killed isEqualTo 0) then {
				systemchat "Crew has no more alive members";
			};
		}];
	} forEach crew _veh;

	//check if vehicle is still mobile
	_veh addEventHandler ["Engine",{
		params ["_veh", "_engineState"];
		if (!_engineState and alive _veh) then {
			systemchat "Engine turned off, checking if vehicle can still move.";
			if (!canMove _veh) then {
				systemchat "Vehicle can no longer move!";
			};
		};
	}];

	//check if vehicle has been abandoned
	_veh addEventHandler ["GetOut",{
		params ["_veh", "_role", "_unit", "_turret"];
		if (alive _veh AND count crew _veh isEqualTo 0) then {
			systemchat "Vehicle has been abandoned!";
		};

	}]
};
[MyVehicle] call GOM_fnc_vehicleDeleteCheck;

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

lol Grumpy i swear your stalking me!
The BIS forums should knight you!
Thanks again buddy, i shall give it a whirl!

  • Like 1

Share this post


Link to post
Share on other sites

Sorry for being a pain, but how would one call the function within my vehicle spawn / hunt script?

 

_spawnEastGroundVehicle = [] spawn {

	waitUntil { time > 10 };

	while { spawnVehiclePatrols } do {

		_spawnPos = mapCenter getPos [ random worldSize / 2, random 360 ];

		_spawnPos = [ _spawnPos, 1, random worldSize / 2, 10, 0, 35, 0 ] call BIS_fnc_findSafePos;

		_eastPatrolVehicle = [ _spawnPos, 180, (selectRandom (RAZ_fnc_groundPatrolVehiclesEast)), East ] call bis_fnc_spawnvehicle;

		_veh = _eastPatrolVehicle select 0;

		_crew = _eastPatrolVehicle select 2;

		_veh setPilotLight true;

		{ gm addCuratorEditableObjects [ [_x], true ]; } forEach units _crew;

		gm addCuratorEditableObjects [ [ _veh ], true ];

		while { alive  _veh } do {

			sleep 2;

			waitUntil { (count (allplayers - switchableUnits) > 0) };

			_unit = selectRandom ( allPlayers select { alive _x } );

			if ( alive _unit ) then {

				_unit = _unit;

				sleep 2;

			};

			if ( !alive _unit ) then {

				sleep 2;

				waitUntil { (count (allplayers - switchableUnits) > 0) };

				_unit = selectRandom ( allPlayers select { alive _x } );

			};

			deleteWaypoint [ _crew, 0 ];

			_wp = _crew addWaypoint [ position _unit, 0 ];

			if ( debugScript ) then { format ["East vehicle has switched target to %1", name _unit] remoteExec ["systemChat"]; };

			[_crew, 0] setWaypointType "SAD";
	 
	        [_crew, 0] setWaypointSpeed "NORMAL";

            sleep 10;

		};

		waitUntil { !alive _veh };

		if ( debugScript ) then { format ["East vehicle has been destroyed, or all crew members are dead!"] remoteExec ["systemChat"]; };

		deleteWaypoint [_crew, 0];

		{ deleteVehicle _x } forEach units _crew;

		deleteGroup _crew;

		sleep 300;

	};

};

And one would assume i can use the function on various instances of the above script?
Kind regards
Rory

Share this post


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

So to clarify:

 

  1. Check to see if either the vehicle is destroyed or all crew are dead
  2. if all crew are dead, do nothing to the vehicle and leave it on the map
  3. If vehicle empty but crew are alive, do nothing and wait until the crew or vehicle are dead

 

I hope this makes sense lol
Kind regards
Rory

 

No, that doesn't! "Do nothing" is simple to code. Truly, I can't understand what you're trying to do.

Share this post


Link to post
Share on other sites
26 minutes ago, pierremgi said:

 

No, that doesn't! "Do nothing" is simple to code. Truly, I can't understand what you're trying to do.

 

Let me explain it simply.
I would like to pause my code until either:

_veh is destroyed or immobilised

OR

the crew of _veh have left the vehicle

OR

crew of _veh are dead.

 

Using waitUntil

Does that explain it a bit better?

Kind regards
Rory
 

Share this post


Link to post
Share on other sites
3 minutes ago, RoryRothon said:

 

Let me explain it simply.
I would like to pause my code until either:

_veh is destroyed or immobilised

OR

the crew of _veh have left the vehicle

OR

crew of _veh are dead.

 

Using waitUntil

Does that explain it a bit better?

Kind regards
Rory
 

Don't pause anything, make 2 functions.

One function to handle vehicle spawning and crew spawning.

Another function to control when the spawning function should be called, as in the example above.

 

This way there's even no need to loop anything.

 

Cheers

Share this post


Link to post
Share on other sites

Well, GOM is right, imho.

 

Anyway, if you need to wait before spawning a next vehicle, I guess you're able to write something like:

waitUntil {sleep 2; !canMove _veh or !alive _veh or {alive _x} count crew _veh == 0};

So?

 

btw, I don't understand:

waitUntil { (count (allplayers - switchableUnits) > 0) }; in your code. I missed something.

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

×