Jump to content
Maff

[SOLVED] Filter specific nearestObjects results

Recommended Posts


I lost all my scripts due to HDD failure and have been away from Arma for a month or two.

 

I had a nice little script that would filter results from nearestObjects.

I cannot for the life of me recreate it and I'm starting to lose patience, so any help appreciated.


The gist of it went like;

_pos = screenToWorld [0.5, 0.5];
_rad = screenToWorld [0.5, 0.5] distance2D screenToWorld [1, 1];

_filter = ["wall","sign","house","stone","pipe","pole"];

{
	if ( > ANY word from _filter is in _x < ) then
	{
		_v = create3DENEntity ["object", "Sign_arrow_down_large_EP1", getPosATL _x];
	};
} forEach nearestObjects [_pos, [], _rad];

//	Object "69391: powerpolewooden_f.p3d" now has an arrow on it because "pole" is in _filter.

 

This was helpful when returning many objects in an area where I didn't have to know the entire class name or model class.

 


Cheers.

Share this post


Link to post
Share on other sites

90% sure it was nearestObjects.

I know nearestTerrainObjects well.

The nearestTerrainObjects filters aren't what I'm looking for.

 

My old script searched the results from nearestObjects.

It would probably work with nearestTerrainObjects also but there may have been a reason for using nearestObjects.

 

 

I have found an old backup.

I should rephrase and ask how to shorten this script:

Spoiler

_posArr = [];
{
    if (str _x find "cart" > -1) then { _posArr pushBackUnique (getPosATL _x); };
	if (str _x find "corner" > -1) then { _posArr pushBackUnique (getPosATL _x); };
    if (str _x find "house" > -1) then { _posArr pushBackUnique (getPosATL _x); };
    if (str _x find "kiosk" > -1) then { _posArr pushBackUnique (getPosATL _x); };
    if (str _x find "market" > -1) then { _posArr pushBackUnique (getPosATL _x); };
	if (str _x find "minaret" > -1) then { _posArr pushBackUnique (getPosATL _x); };	
	if (str _x find "mosque" > -1) then { _posArr pushBackUnique (getPosATL _x); };
	if (str _x find "stand" > -1) then { _posArr pushBackUnique (getPosATL _x); };
    if (str _x find "well" > -1) then { _posArr pushBackUnique (getPosATL _x); };	
} forEach nearestObjects [player, [], 500];

 

 

Share this post


Link to post
Share on other sites

Shorter version:

 

_posArr = [];
_filters = ["cart","corner","house"]; // Add rest of the filters here!

{
 private _nobj = _x;

 if(({((toLower str _nobj) find _x) > -1} count _filters) > 0) then
 {
  _posArr pushBackUnique (getPosATL _nobj);
 }

} forEach nearestObjects [player, [], 500];

 

add rest of the filter strings to _filters

 

I added toLower to the code to get more matches

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
if( _filters findIf{ toLowerANSI _x in str _nObj } > -1 ) then {

Then a soon as one filter is found you don't have to check the rest.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Larrow said:

Then a soon as one filter is found you don't have to check the rest.

 

Nice. Very nice!

 

Thanks, @Larrow.

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

×