Jump to content
Sign in to follow this  
Kydoimos

Random Array

Recommended Posts

Hi all - just need a little help with picking a single part from an array - but randomly! I've played around with the random functions, but it seems everything I try sets off all parts of the array simultaneously.

_Array = ["_Grenade_Random_A", "_Grenade_Random_B", "_Grenade_Random_C", "_Grenade_Random_D", "_Grenade_Random_E", "_Grenade_Random_F", "_Grenade_Random_G", "_Grenade_Random_H", "_Grenade_Random_I"]

I just want to pick one of these to execute! Thanks - I'm sure the answer's quite obvious - I had a little search through the forums - forgive me if I've missed a thread that covers this in detail! :p

Share this post


Link to post
Share on other sites
_Array = ["_Grenade_Random_A", "_Grenade_Random_B", "_Grenade_Random_C", "_Grenade_Random_D", "_Grenade_Random_E", "_Grenade_Random_F", "_Grenade_Random_G", "_Grenade_Random_H", "_Grenade_Random_I"];
_randomElement = _Array call BIS_fnc_selectRandom;

Share this post


Link to post
Share on other sites

Thank cuel - I'll try that! :p

---------- Post added at 12:48 ---------- Previous post was at 12:42 ----------

---------- Post added at 13:29 ---------- Previous post was at 12:48 ----------

Still having problems! But I don't think it's your code, cuel - here's my full script:

private ["_Grenade_Random_A"];
_Grenade_Random_A = "Grenade" createVehicle getMarkerPos "Grenade_A";
private ["_Grenade_Random_B"];
_Grenade_Random_B = "Grenade" createVehicle getMarkerPos "Grenade_B";
private ["_Grenade_Random_C"];
_Grenade_Random_C = "Grenade" createVehicle getMarkerPos "Grenade_C";
private ["_Grenade_Random_D"];
_Grenade_Random_D = "Grenade" createVehicle getMarkerPos "Grenade_D";
private ["_Grenade_Random_E"];
_Grenade_Random_E = "Grenade" createVehicle getMarkerPos "Grenade_E";
private ["_Grenade_Random_F"];
_Grenade_Random_F = "Grenade" createVehicle getMarkerPos "Grenade_F";
private ["_Grenade_Random_G"];
_Grenade_Random_G = "Grenade" createVehicle getMarkerPos "Grenade_G";
private ["_Grenade_Random_H"];
_Grenade_Random_H = "Grenade" createVehicle getMarkerPos "Grenade_H";
private ["_Grenade_Random_I"];
_Grenade_Random_I = "Grenade" createVehicle getMarkerPos "Grenade_I";
_Array = ["_Grenade_Random_A", "_Grenade_Random_B", "_Grenade_Random_C", "_Grenade_Random_D", "_Grenade_Random_E", "_Grenade_Random_F", "_Grenade_Random_G", "_Grenade_Random_H", "_Grenade_Random_I"]; 
_Random = _Array select floor random count _Array;
Sleep 10;
Sleep Random 10;
if (alive Ambient_Firing_FailSafe_D) then {[] spawn Ambient_Firing_Grenades};

Basically, this is making all the grenades explode at the same time...

---------- Post added at 13:29 ---------- Previous post was at 13:29 ----------

I've also tried _randomElement = _Array call BIS_fnc_selectRandom;

Edited by Kydoimos

Share this post


Link to post
Share on other sites

You are trying to explode a grenade on a random position picked from an array, isn't it?

Share this post


Link to post
Share on other sites
You are trying to explode a grenade on a random position picked from an array, isn't it?
Yeah! You got it!

Share this post


Link to post
Share on other sites

Do you want something like this?

_posArr = ["marker1", "marker2", ..., "markerN"];
_pos = getMarkerPos (_posArr call BIS_fnc_selectRandom);
_grenade =  "Grenade" createVehicle _pos;

If you want to determine random positions in a certain area you might want to look into SHKPos. It's perfectly suited for a task like this and the author gave me his explicit permission to use it on MANW, so you could simply ask him to grant you the same rights.

Share this post


Link to post
Share on other sites

Hey, man! Thanks! That looks like it would do the job! :cool:

---------- Post added at 14:50 ---------- Previous post was at 14:27 ----------

@IndeedPete - you are a legend! :yay: That's the first and only dancing banana I've ever awarded. :)

Share this post


Link to post
Share on other sites

Your old script was creating every grenade, putting them in an array and then just selecting a reference to one of the (already) created grenades (and then doing nothing) :)

Share this post


Link to post
Share on other sites

Yes. Instead of a random grenade script was a carpet bombing one... efective too :)

Share this post


Link to post
Share on other sites

Always happy to help, no bananas needed. :D

Looking forward to the third part of your script rework, the second one was awesome so far, thanks again!

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  

×