Jump to content
Sign in to follow this  
sabot10.5mm

help randomly selecting hills 2000m apart eachother

Recommended Posts

i would like to create a function that gets all hill locations and randomly selects a range of locations that are 2000 meters apart. could someone help me with this? really appreciate it.

 

_nearbyLocations = nearestLocations [position player, ["hills"], 25000];

select a random range of 1 to 4 locations that are at least > 2000 meters apart

return the value

 

Share this post


Link to post
Share on other sites

You may be better using selectBestPlaces command for this instead.

https://community.bistudio.com/wiki/selectBestPlaces

No need to create your own function. When you say all locations? Do you mean selects one of them? This command offers an expression parameter (argument) in which you can use for whatever you need.

Share this post


Link to post
Share on other sites

i want a way of randomly selecting 4 hills that are 2000 meters apart. the way I'm doing it now is, manually putting down objects on the map and randomly selecting a hill in a 2000 meter radius. 

Spoiler

            {if( player distance _x < _threshold) exitWith {_nearestpos = getpos _x; _nearest append _nearestpos;};} forEach [radio1,radio2,radio3,radio4]; _nearest;
            hint "1";    
            if !(count (_nearest)==0) then {_fndLoc = (selectrandom (nearestLocations [_nearest, ["hill"], 1999]));

instead of having to place objects down as a reference, i would rather have a function find random hill at least 2000 meters apart

Share this post


Link to post
Share on other sites
34 minutes ago, sabot10.5mm said:

i want a way of randomly selecting 4 hills that are 2000 meters apart. the way I'm doing it now is, manually putting down objects on the map and randomly selecting a hill in a 2000 meter radius. 

  Hide contents

            {if( player distance _x < _threshold) exitWith {_nearestpos = getpos _x; _nearest append _nearestpos;};} forEach [radio1,radio2,radio3,radio4]; _nearest;
            hint "1";    
            if !(count (_nearest)==0) then {_fndLoc = (selectrandom (nearestLocations [_nearest, ["hill"], 1999]));

instead of having to place objects down as a reference, i would rather have a function find random hill at least 2000 meters apart

Don't use nearestLocations for that, since it requires the map to have defined "hill" locations, which has to be manually done by the map author, even BI doesn't seem to care too much about this, since most official maps lack those kind of locations, same for strategic locations etc.

 

This snippet tries to grab 100 hills from the map, filters the output into a positions array only holding hills that are at least 2000m from each other.

This is very cpu intensive and would be best to use the final output in your mission instead of the function itself:

{deletemarker _x} foreach allMapMarkers;

_hills = [];
_allHills = selectBestPlaces [getposatl player,25000,"(1 + hills) * (1 - sea)",50,100] apply {_x select 0};//gives all hills as 2d positions

while {count _allHills > 0} do {

	_rndHill = selectRandom _allHills;
	_allHills = _allHills select {_x distance2d _rndHill >= 2000};
	_hills pushback _rndHill;

	_marker = createmarker [str _rndHill,_rndHill];
	_marker setmarkertype "hd_dot";
	_marker setmarkercolor "ColorYellow";
	_marker setmarkertext format ["hill",""];


};
systemchat format ["Valid hills found: %1",count _hills];
copyToClipboard str _hills;//put the final array of valid hills to clipboard for use in mission

Play with selectBestPlaces parameters to get the result you want, also read the linked thread made by @rübe for further knowledge.

9XHGz8A.jpg

 

Also try to be a bit more descriptive with your threat titles, since most folks tend to help if they know the answer to a problem, but a generic "please help" title does the opposite, usually.

 

 

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Brilliant work GOM, as usual. Sometimes you scare me.

  • Haha 2

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  

×