Jump to content
Sign in to follow this  
jw custom

Spawned vehicle names into array

Recommended Posts

I'm spawning a random number of random selected vehicles with this, no problems:

_NumOfVeh = ceil(random 5);

for [{ _loop1 = 0 },{ _loop1 < _NumOfVeh},{ _loop1 = _loop1 + 1}] do
{
_vehicle_types = ["BMP3","BTR90", "GAZ_Vodnik","GAZ_Vodnik_HMG", "2S6M_Tunguska", "BTR90_HQ"];

_vec_type = floor (random count _vehicle_types);

OpVeh = _vehicle_types select random _vec_type createVehicle (getMarkerPos "spwn1");
};

My question is how do i keep track of the spawned vehicles names so i can check if they are alive. The first vehicle is named OpVeh, but what about the next vehicle....is that named OpVeh_1??

My real question is how can i put the names into an array and check that array if all vehicle names in it are destroyed?

Help is really appreciated :D

Share this post


Link to post
Share on other sites

private ["_vehs","_a"];
_vehs = [];
_a = ["BMP3","BTR90", "GAZ_Vodnik","GAZ_Vodnik_HMG", "2S6M_Tunguska", "BTR90_HQ"];
for "_i" from 0 to (ceil(random 5)) do {
 _vehs set [_i, ((_a select floor(random(count _a))) createVehicle (getMarkerPos "spwn1"))];
};

Waiting for all to be dead:

waituntil {{alive _x} count _vehs < 1};
hint "all dead";

You can make _vehs a global var as well, if you want to check it outside the script.

Share this post


Link to post
Share on other sites

You can also use simple math with arrays:

OpVehArray = OpVehArray + [OpVeh];

Share this post


Link to post
Share on other sites

Thanks alot guys, really appreciated :cool:

I used Murklor suggestion with shk "waituntil {{alive _x} count _vehs < 1};" snippet and it works great :dancered:

Gotta love this community :thumb:

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  

×