Jump to content
The Real Bunc

Vehicles command - Aaaaaaaagh!

Recommended Posts

I'm doing some work on a script which shows vehicle icons on the map, it works but I get a problem once vehicles start getting destroyed. The problem is that the array returned by the vehicles command changes its form depending on whether destroyed vehicles are present. 

 

So for example if I have a number of vehicles placed , crewed or uncrewed at the start then I can use

vehicleslist = vehicles

and I get this form of array returned -

[O Alpha 1-3:1,O Alpha 1-4:1,O Alpha 1-5:1,O Alpha 1-6:1,B Alpha 1-6:6,B Alpha 2-1:1]

 

However  when a vehicle gets destroyed the array produced by the same command changes 

[O Alpha 1-3:1,O Alpha 1-4:1,O Alpha 1-5:1,O Alpha 1-6:1,B Alpha 1-6:6,B Alpha 2-1:1,249d56118c0# 1780326: dummyweapon.p3d]

 

Notice that initially I have a nice array with each vehicle as a distinct entry. This means that the array can be looped through and appropriate action taken for each entry - nothing superfluous and the array is predictable.

Now look at the end of the second one with the destroyed vehicle in it, the last entry  B-Alpha 2-1:1    Now, instead of one entry we have two , the first one as before identifying the vehicle but then followed by some numbers and a p3d reference. But note that these are included as an additional array item. My original array contained 11 clearly distinct array items each representing a vehicle, now I have an extra item because the engine decided to chuck in stuff about the damaged vehicle model or something.

 

The problem gets worse, not only does this destroyed vehicle now have two distinct entries in the array but from what I've seen some destroyed vehicles may generate an extra two ( or more?) entries of a similar type.. all comma separated of course so as to f up your array handling.

 

So we are left dealing with an array which varies up and down not only in size but in format depending on the status of the actual things we are trying to get a list of in the first place!. Who the f thought that was a good idea?

 

Anyway, my problem is - how would I handle the array when its changing unpredictably like this when I simply want to cycle through all vehicles applying code to each one?   Im sure there will be some kind of alive test I can do but the problem is I wont know how many array entries always to skip etc . Driving me nuts. Surely a more sensible approach would have been a command that simply returned all vehicles regardless of condition then allow for checks and this other info to be returned by a distinct separate command. Anyway that's the beef but Im really interested in how to cope with unpredictable arrays like this.

 

 

Share this post


Link to post
Share on other sites

In fact, vehicles also returns crates and weapon holders. For example, when you kill a man (armed) , you create a weapon holder which host the primary weapon. So, you have plenty of unwanted "vehicles" which are not drivable vehicle at all. Welcome to ARMA!

So, depending on what the crew becomes, you can have weapon holder(s) or not (the dummyweapon.p3d count = dead crew count outside of the vehicle). Sometimes, crew has enough time to jump out before explosion, sometimes they die on board, sometimes they vanish as the vehicle becomes a wreck (when you blow a Hunter with a single Titan missile) ...

Note 1: the blown vehicle remains a count vehicle, but the designation changed for the p3d wreck model. An empty vehicle returns also the p3d model.

Note 2: an edited (on map) wreck (as is) are not vehicles, but objects.

 

So the vehicles command is weird as hell but you can filter the mess with: (vehicles select {(_x isKindOf "landVehicle" or _x isKindOf "air" or _x iskindOf "ship")}) for example. As there are plenty of weapon Holders, simulated or not, ammo crates... use landVehicle, air, ship.

 

Note3: parachutes and ejected seats and canopies (since Jet DLC) are also vehicles... air . If you are purist you can add in filter:

 && !(_x isKindOf "Ejection_Seat_Base_F") && !(_x isKindOf "ParachuteBase") && !(_x isKindOf "Plane_Canopy_Base_F")

 

Note4: if you don't want anymore destroyed vehicle, just add: && alive _x

So: (vehicles select {alive _x && {(_x isKindOf "landVehicle" or _x isKindOf "air" or _x iskindOf "ship")} && { !(_x isKindOf "ParachuteBase")} && {!(_x isKindOf "Ejection_Seat_Base_F")} &&{ !(_x isKindOf "Plane_Canopy_Base_F")} })

 

To treat all useful vehicles, even spawned ones, in a loop:

 

0 = [] spawn {

  while {true} do {

    _allVehicles = (vehicles select { isNil {_x getVariable "passedVehicle"} && {alive _x} && {(_x isKindOf "landVehicle" or _x isKindOf "air" or _x iskindOf "ship")} && { !(_x isKindOf "ParachuteBase")} && {!(_x isKindOf "Ejection_Seat_Base_F")} &&{ !(_x isKindOf "Plane_Canopy_Base_F")} });

 

    {  // do what you want here for vehicles, for example:

      _x lock 0;
      _x setFuel random 1; // (for spawned vehicles on server)

      _x setVariable ["passedVehicle",true]

    } forEach _allVehicles;
    sleep 2;

  }

};

 

  • Like 3

Share this post


Link to post
Share on other sites

Very helpful Pierre. I of course had some faint hope that there might be an actual command I wasn't aware of and it wasn't an almighty mess. I got round my immediate problem by simply making a list of vehicles at mission start but of course that's a crap solution and I don't have crates placed which from what you say would also mess things up. So a filter it is. I'll try your code, many thanks.

 

One thing on a quick look at your code - im not sure on a first look what work the isNill is doing in that vehicles select expression?     

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

×