Jump to content
Sign in to follow this  
zapat

nearestObjects: all except helis

Recommended Posts

How can I check every object near player, except helis? Is there an easy way to do this, or I have to manually put all classes but helis in [] ?

I use this code for selecting all objects:

{...}foreach (nearestObjects [player,[],50]);

thanks in advance

Share this post


Link to post
Share on other sites

I would do this instead for smaller radius (eg. not 2000):

_all = nearestObjects [player, ["All"], 50];
_helis = nearestObjects [player, ["Helicopter"], 50];
_notHelis = _all - _helis;

_notHelis has what you are looking for.

Share this post


Link to post
Share on other sites

Thanks, this is a good idea.

And what would you do for a 2000 radius? :rolleyes:

(my idea is growing, and it may need some more space. :) )

Share this post


Link to post
Share on other sites
_all = nearestObjects [player, ["All"], [color=red][b]2000[/b][/color]];
_helis = nearestObjects [player, ["Helicopter"], [color=red][b]2000[/b][/color]];
_notHelis = _all - _helis;

Share this post


Link to post
Share on other sites
And what would you do for a 2000 radius? :rolleyes:

Well I would... I guess.... But....

You got me. Guess I would use the above method too, now that I think about it. :D

Like JamesF1 suggests.

Except Evil_Echo now filled in the blanks in m triple dots above :), due to being more efficient.

Share this post


Link to post
Share on other sites

The easiest way would be set arithmatic, just subtract the helos.

 
{...} foreach (nearestObjects [player,[],50]) - (nearestObjects [player,["Helicopter"],50]) ;

But you could just use a statement inside your loop that checks for parent classes and skip helos there. Slightly more complicated, but much more efficient.

 
{
  if ( _x isKindOf "Helicopter" ) then { 
  // skip rest of this loop
  } else {
     ...
  };
} foreach (nearestObjects [player,[],50]);

Share this post


Link to post
Share on other sites

JamesF1: lol, that was a good one, indeed. :D

Evil_Echo: thanks, this is what i am looking for, only couldn't say it this nice.

But now:

{
     if ( !(_x isKindOf "Helicopter") ) then 
     { 
         ...
     };
} foreach (nearestObjects [player,[],2000]);

Edited by zapat

Share this post


Link to post
Share on other sites

Yes, the inverted test is nicer in your case. I actually use a slightly more complex version to knock out several classes as part of a damage routine for nukes.

:smiley-evil:

Use caution when checking for all objects at large radii. It's far faster to do get all objects and filter ( method 2 or varient ) vs multiple calls that each check for different class types.

Edited by Evil_Echo

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  

×