Jump to content

Recommended Posts

Hello ARMAtes. I need help with the next problem:

 _selectm = selectRandom ["rm01","rm02","rm03","rm04"];
_posm = getMarkerPos _selectm; sleep 1; 

This way I randomly pick what existing marker on the map will be used but I need the full circle to be completed without repeating already used ones. For example, if trigger tgrm_03 will be activated - the area of marker rm03 will be used to spawn some units and due to tgrm_03 being set to "enableSimulation false" after use, it will not be activated if the random system chooses it again accidentally but the script will stop seeking next one so units will not be deployed... What I want is to tell the script to choose only between triggers that are left untouched until I manually set them all to "enableSimulation true" again.

Thanks in advance

Share this post


Link to post
Share on other sites

Not sure I understood the goal, but I reckon you're looking for something like this ?

 

all_markers = ["rm01","rm02","rm03","rm04"];
unused_markers = all_markers;

_selectm = selectRandom unused_markers;
unused_markers = unused_markers - [_selectm];//remove it from our list so it gets picked once only
if(unused_markers isEqualTo [])then{
	unused_markers = all_markers//if list is empty, repopulate it for next time
};
_posm = getMarkerPos _selectm; sleep 1;

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@haleks beat me to it, but questions still remain. 

 

Every time the above code is run, the all_markers array is reset, due to it being defined at the top. 

 

So, how are you ultimately planning to run this code? Should it be something that is initiated at mission start and runs autonomously from there, or is it to be called when certain conditions are met, or when the array is empty, etc.? Is it part of a larger script? The answers define the approach to be taken.

Share this post


Link to post
Share on other sites

Oops, yep I should've mentioned that the first 2 lines should run only once... ^^'

Put them somewhere in a gamelogic or init.sqf; and use the rest wherever you run your loop from.

Share this post


Link to post
Share on other sites

Not at hoem right now will answer soon. It is not on mission start it is run with setting random position of object using between trigger areas and every of that trigger have cond: specific object-present that's how I start loop - [when object is presented in trigger area] after that trigger do the rest. I think I understand both of you just can't try it right now..

Share this post


Link to post
Share on other sites
5 hours ago, haleks said:

Not sure I understood the goal, but I reckon you're looking for something like this ?

 


all_markers = ["rm01","rm02","rm03","rm04"];
unused_markers = all_markers;

_selectm = selectRandom unused_markers;
unused_markers = unused_markers - [_selectm];//remove it from our list so it gets picked once only
if(unused_markers isEqualTo [])then{
	unused_markers = all_markers//if list is empty, repopulate it for next time
};
_posm = getMarkerPos _selectm; sleep 1;

 

 

Due to Array Reference you would not want to simply cross-reference the array with "=" alone, since any changes to unused_markers would then also change all_Markers.

You would instead want to copy the array with "= +" so that all_Markers and unused_Markers become separate arrays of their own:

 

all_markers = ["rm01","rm02","rm03","rm04"];
unused_markers = +all_markers;
if(unused_markers isEqualTo [])then{
	unused_markers = +all_markers//if list is empty, repopulate it for next time
};

 

  • Like 3

Share this post


Link to post
Share on other sites

A quicker and neater way to remove a random item from an array: 

_marker = _array deleteAt floor random count _array;

  • Like 4

Share this post


Link to post
Share on other sites

all_markers = ["rm01","rm02","rm03","rm04"]; 
unused_markers = +all_markers; //executed from anywhere but from randomSelector.sqf

 

randomSelector.sqf

_selectm = selectRandom unused_markers;
unused_markers = unused_markers - [_selectm];//remove it from our list so it gets picked once only
if(unused_markers isEqualTo [])then{
    unused_markers = +all_markers//if list is empty, repopulate it for next time
};
_posm = getMarkerPos _selectm; sleep 1;

sel setPos _posm;

 

Works fantastic! Finally! A combination of @haleks 's and @opusfmspol 's is a perfect result. I also tried @mrcurry 's but can't understand for some reason. If you can show me the example in combination with the rest of the script, please?

And one more thing please guys: due to this random array of markers referring to tasks on the field, not always a full cycle is necessary to be completed due to some recruits failing during the process and needing to start over because exercise require to be done in one go. So my last goal is to make a command to reset the array and make it like at the beginning (used markers to be counted again). I tried a few combinations I thought will work but can't figure it out:

all_markers = ["rm01","rm02","rm03","rm04"];

if(unused_markers isEqualTo [4])then{ unused_markers = +all_markers };  etc...

THANK you all mates for your help and your time!

edited: unused_markers = +all_markers do the job.I feel like 😶

  • Like 1

Share this post


Link to post
Share on other sites
On 3/30/2023 at 9:22 PM, opusfmspol said:

_selectm = selectRandom unused_markers; unused_markers = unused_markers - [_selectm];

Replace the above with:

_selectm = unused_markers deleteAt floor random count unused_markers;

They both do essentially the same thing. The main difference is that deleteAt works insitu while subtraction "-" recreates the entire array.

Not a big resource hog for small arrays like yours but if you ever need to go big it's nice to know more techniques.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
13 hours ago, mrcurry said:

it's nice to know more techniques

Exactly! Thank's mate!

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

×