Jump to content
Onno

How to select all vehicles in a player group?

Recommended Posts

I was trying to figure out if the statement "vehicles units group player" would get me all the vehicles in a group, but not the soldiers inside them.

To test this, I opened up the editor and set up 3 hunters with my player as the group lead in the driver position.

I then tried to put this piece of code in the init of my vehicle:

_vehicles = vehicles units group player;
{
   hintC format["unit: %1",  _x];
} foreach _vehicles;

somehow this throws up an error about a missing semicolon (;).

2 quick questions for those who know more about this than I do:

1. Does vehicles accept modifiers in the same way as units does?

2. why is the editor complaining about a missing semicolon? as far as I can see, I've ended every statement with one.

Edited by Onno

Share this post


Link to post
Share on other sites

I think you have an s that should not be there. Try 'vehicle units' not 'vehicles Units'

Edit.

No it's more than that I think you need a a loop to iterate all the vehicles in the group

Will look into it for you

Edit 2:misunderstood original question slightly and found that vehicles is a command to return all vehicles in the mission.

Edited by KevsnoTrev
Updated wrong info
  • Like 1

Share this post


Link to post
Share on other sites

If you are totting up all the vehicles, then filter them so you don't add the same vehicle twice (if more than one unit is in a vehicle).

Something like:

_vehs = [];

{
_veh = vehicle _x;
_inArray = _veh in _vehs;
if (not _inArray and {_veh != _x}) then
{
	_vehs set [count _vehs, _veh];
};
} forEach units group player;

hint format ["%1", _vehs];
{player sideChat format ["%1", typeOf _x]} forEach _vehs;

Share this post


Link to post
Share on other sites

Thnx for your replies so far :)

I think you have an s that should not be there. Try 'vehicle units' not 'vehicles Units'

Edit.

No it's more than that I think you need a a loop to iterate all the vehicles in the group

Will look into it for you

I was hoping to use biki:vehicles but I guess a loop over all the units will work.

If you are totting up all the vehicles, then filter them so you don't add the same vehicle twice (if more than one unit is in a vehicle).

Something like:

I thought that vehicles would do that for me as well.

Anyways, even though you have given me some useful tips, the two original questions remain unanswered. Can someone tell me in detail how the 'vehicles' keyword works?

Edited by Onno

Share this post


Link to post
Share on other sites

Vehicles will return all vehicles in the mission, so you would have a massive array to sort through if there is lots of vehicles on the map.

It's just an array so you need to do stuff with it.

Much better in this case to just check the vehicles your men are in.

  • Like 1

Share this post


Link to post
Share on other sites

I guess the answer to question number 1 would be "no" according to you then?

Share this post


Link to post
Share on other sites

Right, I thought it was a keyword that would create an array. Apparently it is an array in global that's present by default then. At times I wish the comref was more verbose on this. It's really hard to understand the workings of the keywords with such minimal descriptions.

Share this post


Link to post
Share on other sites

Correct :) It's one of the "magic" commands that BIS put into the scripting library so you can have easy access to information without having to run a nearestObjects or nearEntities check over the whole map (which would eat up CPU cycles).

Others include:

allDead

allUnits

allUnitsUAV

playableUnits

switchableUnits

and so on.

Hope that helps.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks! This clarifies a lot :) Kudo's to you my friend!

(The comref unfortunately did not do that)

Share this post


Link to post
Share on other sites

Thanks for pointing one thing out Omno - I had no idea HintC existed - I thought it was a typo until I just checked....Always Learning I guess

  • Like 1

Share this post


Link to post
Share on other sites
On 9/9/2020 at 12:31 PM, kingofnuthin1980 said:

 

[group player, true] call BIS_fnc_groupVehicles;

 

That's fucking golden, ty!!!

Share this post


Link to post
Share on other sites
On 4/17/2014 at 5:23 PM, das attorney said:

If you are totting up all the vehicles, then filter them so you don't add the same vehicle twice (if more than one unit is in a vehicle).

Something like:

 


_vehs = [];

{
_veh = vehicle _x;
_inArray = _veh in _vehs;
if (not _inArray and {_veh != _x}) then
{
	_vehs set [count _vehs, _veh];
};
} forEach units group player;

hint format ["%1", _vehs];
{player sideChat format ["%1", typeOf _x]} forEach _vehs;
 

 

I believe this is a nice (most hopefully working) solution. I believe you could also use pushBackUnique in order to avoid some checks as to whether this vehicle is in the array or not. The adapted solution could look like the following (adapting das attorney's solution)

// Declare and initialise empty vehicles array
_vehs = [];

// Go through the units in the group of the player
{
	// Add the vehicle to the array if not already in there
	_vehs pushBackUnique (vehicle _x);
} forEach units group player;

// Present some results
hint format ["%1", _vehs];
{player sideChat format ["%1", typeOf _x]} forEach _vehs;

Please note that this code snippet is not tested and should be treated with caution. Nevertheless I hope it does help somehow one way or another.

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

×