Jump to content
Sign in to follow this  
nightwisher

Creating explosions at random objects

Recommended Posts

Hi, I've got what might be a simple question, but how exactly do I use the random function to randomly choose an object, so I can then create an explosion.

I've already got the line for triggering the explosion working:

bomb="R_M136_AT" createVehicle position EXP01;

(I've got a list of objects named EXP01 thru 23 as targets)

I just don't know what to put in a script to randomly choose an object out of a list and use that as the target. Is anyone able to help, please? I've tried a few things and I really dont know how to best use the random function to do it.

Share this post


Link to post
Share on other sites

Something like this should do:

rnd = floor (random count EXP01);
choice = EXP01 select rnd;

Share this post


Link to post
Share on other sites

Cheers for the reply, I'm just a bit unsure how to use that. Do I have to define the choices? And I'm not sure exactly how to tie in the explosion part. Sorry to be a pain, this scripting language is more than I'm used to!

Share this post


Link to post
Share on other sites

In my example, the variable "choice" will contain the randomly selected object.

Is EXP01 really an array of multiple units, how did you obtain it ?

rnd = floor (random count EXP01);
choice = EXP01 select rnd;
bomb="R_M136_AT" createVehicle getPos choice;

Share this post


Link to post
Share on other sites

Oh, sorry I should have clarified, I have 23 objects on the map called EXP01, EXP02... etc. Thats the method I've been (trying) to use to place explosions.

Share this post


Link to post
Share on other sites

Ok in this case we'll have to take an slightly different approach.:

rnd = ceil (random 23);
if (rnd < 10) then {
call compile format ['bomb="R_M136_AT" createVehicle getPos EXP0%1;',rnd];
} else {
call compile format ['bomb="R_M136_AT" createVehicle getPos EXP%1;',rnd];
};

And also a bit more cryptic I guess. ^^

Share this post


Link to post
Share on other sites

Ah excellent, that makes sense to me, it seems to work how i want it to. Thank you!

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  

×