Jump to content
Heavensrevenger

Run a code for each crew member of a vehicle

Recommended Posts

Hello i want to run a code on every member of a vehicle (Turrets, cars, tanks, planes, helos, boats and basically everything that can be entered). I have the following code for this:
 

   _vehicle = nearestObjects [player, ["AllVehicles"], 200];
   {
    if (damage _x < 0.5 ) then {
     _x setdammage (damage _x + 0.1);
    };
   } forEach crew _vehicle;

But the code always tells me that in the forEach crew _vehicle; it expects an object not an array. I'm unsure how to do this. Do I have to do this:

   _vehicle = nearestObjects [player, ["AllVehicles"], 200];
   {
	{
     if (damage _x < 0.5 ) then {
      _x setdammage (damage _x + 0.1);
     };
	} forEach crew _x;
   } forEach _vehicle;

or is there a better way?

Also is the "AllVehicles" class the correct one or should I use a different one?

Share this post


Link to post
Share on other sites

_vehicle = nearestObjects [player, ["AllVehicles"], 200]; is confusing because it's an array of vehicles. Say _vehicles is more appropriate but you can do what you want.

 

Anyway, you can also use a single : {... } forEach flatten crew _vehicles

That's for answering your question.

Now, for the aim I guess, you should probably use the EH "handleDamage". (to be confirmed by your goal).

  • Thanks 2

Share this post


Link to post
Share on other sites

I've run into a problem I'm not sure how to fix 

_vehicles = nearestObjects [player, ["Ship", "LandVehicle", "Helicopter", "Plane"], 200];

This returns the "crew" AI of drones, so running the code will kill the drones "crew" so they are basically useless. Is there a way to exclude classes? i tried !"B_UAV_AI" but that doesnt work

Share this post


Link to post
Share on other sites
private _vehicles = nearestObjects [player, ["Ship", "LandVehicle", "Helicopter", "Plane"], 200];
_vehicles = _vehicles select {getText (configOf _x / "vehicleClass") !=  "Autonomous"};

 

  • Like 1

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

×