Jump to content
Sign in to follow this  
Wilson999

Checking if a member of an array is a certain distance away

Recommended Posts

I basically want a trigger to activate when any one of several units gets within a certain distance of a particular unit. For instance:

catcher distance escapee < 10

But when I try to create an array of catchers, and use the same code, it doesn't work (e.g. [catchers_array] distance escapee < 10 doesn't work).

I've been looking all over the web and these forums for the right way to do this, but I can't quite figure it out. I've tried using count and ForEach commands, but they didn't work for me. I only have a fairly basic knowledge of scripting, so I apologize if I'm asking for something really easy or really hard. I think I could use a lot of OR statements in the trigger, but that isn't going to be the best way :)

Share this post


Link to post
Share on other sites

More ways than one to do this...but just started typing and this is the result :)

There's a little demo mission here for you to check out.

http://www.mediafire.com/file/1us3csre3qjycq8/Test_Catch_Enemy.utes.zip

It's a script that runs on the "enemy" and checks the array of "catchers" to see if any are close (<10).

It's only good for one shot...so will exit when the enemy has been found.

The script is run from the Init of the enemy. Better to have one script running for one guy ....than one script running for each catcher!

In the demo mission....the catchers and the enemy are all playable..... so you can Teamswitch to check that the script works no matter if you are the enemy or a catcher.

If you need more help.... I'll be glad to help.

EDITED: AZCoder pointed out I had the wrong link. Thanks. Link fixed.

Edited by twirly
Wrong link included the first time.

Share this post


Link to post
Share on other sites

twirly, I just wanted to double check if that was the right demo mission in your link? It's a nice demo of paradropping from an MV22. I did enjoy it :)

Here is one possible way of handling the distance problem with many units. First create a trigger that covers the area where the chase can occur. Set activation to side of the "catchers" such as OPFOR. Name the trigger, I'll call it "trgPursuit". In the condition put:

{ escapee distance _x < 10} count list trgPursuit > 0

Put whatever you need in the On Act. You may want to use a hint to test it first.

The "list trgPursuit" returns all activation units (like OPFOR) within the trigger area. "count" used in this context is like a forEach, and will compare each OPFOR's distance from the escapee, and if it's less than 10 meters, it will return a 1, thus activating the trigger.

Share this post


Link to post
Share on other sites
twirly, I just wanted to double check if that was the right demo mission in your link? It's a nice demo of paradropping from an MV22. I did enjoy it :)

Ooooops. Thanks mate....the right link is there now!

Share this post


Link to post
Share on other sites

Just what I was looking for! Thank you both for your help. The script in the example mission looks pretty complex to me, I'd never have got it on my own. With that as an example though I'm sure I can figure it out.

I pretty much tried what AZCoder did, but I was using an array instead of 'list trgPursuit' which I'm guessing you can't do? Anyway, thanks again.

Share this post


Link to post
Share on other sites

The list trgPursuit is an array, but it needs count in front of it. I had found that on an old OFP post when I needed to find the closest enemy for a surrendur script I wrote. Twirlys method is good when you can't define one area, or need to have a particular selection of opponents. It all depends on the situation.

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  

×