Jump to content
Sign in to follow this  
tryteyker

Counting all vehicles on map and comparing to one type

Recommended Posts

Alright my head is kinda fried right now regarding this issue, but I'm sure there's an easy way..

I need to count all units on the map and add an action to a specific type (ATV_US_EP1). That's all. This includes ones later spawned in the mission but a loop will fix that, I'm stuck on the counting part, that's all. I tried typeOf, isKindOf, countType and such but I couldn't get it to work, just got Generic Errors everywhere :(

Edit

Talking about empty vehicles here.

Share this post


Link to post
Share on other sites

or this.

{if ((count crew _x) == 0) then {_x addaction ["whatever","dothis.sqf"]};} foreach entities "ATV_US_EP1"

Share this post


Link to post
Share on other sites

thats a big old search to be conducting - cant you just keep count of those in map using an array? then count the peps inside each of those vehicles in the array to get empty vehicles

Share this post


Link to post
Share on other sites

Alright got the first part working, thanks Sel.

Now to the second part, exiting the script if another ATV is in close proximity. I got everything set up and just need to link the scripts together, BUT:

if ((count vehicles ATV) > 0) exitWith {
hint "exit";
};

won't work. D:

ATV = nearestObject [_unit,"Car"];

Only counts one object. The error it gives me above is a missing ).

Share this post


Link to post
Share on other sites

ATV = _unit nearestObjects [_unit,["Car"],50]

the last number is a radius, ATV will contain a list of vehicles in that area

if _unit is a car then you may want to exclude that from the list

ATV = _unit nearestObjects [_unit,["Car"],50] - nearestObjects [_unit,["Car"],0];

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Sadly didn't resolve the missing ) error in my if () exitWith statement. :( I officially have a fried brain. Fixed it by removing "vehicles".. /E Yeah okay, so I need it to ignore the rest of the script, which it doesn't exactly do with exitWith. Terminate has caused CTDs for me in the past and I don't have a proper scripthandle for it to work.

Edited by tryteyker

Share this post


Link to post
Share on other sites

Could you explain a bit more what you're trying to do?

exitWith exits the current scope. If you're inside for example a loop or an if-clause, it would only exit the loop and not the entire script. I don't know about terminating a script from inside itself (I've never had to use terminate in any of my scripts).

Do you want to completely exit the script if any of the ATV's are currently close to another ATV, or do you simply want to skip that ATV?

Share this post


Link to post
Share on other sites

I would imagine terminate script would work fine in a simple script but if that script runs multiple scripts they could get left running.

The only time I've used it was when running a BIS_fnc_dirIndicator and I couldn't find any other way of turning it off.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I managed to fix the issue (altho not entirely sure how, I'm at school). I'll update how I fixed it.

//Edit

I don't even know how I fixed it, I simply adjusted the if exitWith statement. I guess I prevented the script from executing by creating certain variables that won't match up when condition of exitWith is true (example: I use nearestObjects to find the two ATVs, and create different arrays selecting from the main array. Obv that's not gonna work if only one of them is present so the ATV(s) won't get attached)

Edited by tryteyker

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  

×