Results 1 to 6 of 6

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

  1. #1

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

    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

  2. #2
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    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/1us3cs...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.
    Last edited by twirly; Oct 19 2010 at 03:53. Reason: Wrong link included the first time.

  3. #3
    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:
    Code:
    { 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.

  4. #4
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    Quote Originally Posted by AZCoder View Post
    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!

  5. #5
    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.

  6. #6
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •