Home   Help Search Login Register  

Author Topic: SOLUTION: How to know if a certain unit is in a certain location  (Read 609 times)

0 Members and 1 Guest are viewing this topic.

Jus

  • Guest
I know this has probably been asked here quite a few times, don't know if someone has presented a solution for it, but here goes.
Somebody just asked me, how to know if player is in a certain location... basic East/West/Resistance is present - triggers won't do, because some friendly soldiers are already in the area. Waypoints are not an option either. BUT this thing can be solved pretty easily.

It isn't the perfect solution though: it isn't accurate. It also has its limitations. But here's the deal:
Using nearestObject, we can get the name of the nearest object of a unit and if that name equals to our target area, *dang* that's it then. Let's show an example:

1.) Create a unit and name it, here we name it OurUnit.
2.) Next create a unit that you want to act as the target area, here we name it Tgt. We'll be using an invisible helipad as our object.
3.) Create a trigger, and change the condition field to:

nearestObject[OurUnit, "HeliHEmpty"] == Tgt

And that should do it. Now you should have a trigger that does whatever you like when OurUnit goes near Tgt. The activation range is 50 meters, a limitation when using nearestObject.
I don't know if there are other solutions to this, but this is a working one and not too complex either, although a bit limited because of the range issue. I guess you could do the checking with getPos too, that you could do as accurately as you would want but the solution presented here might be something to consider if the checking doesn't have to get more accurate than 50 meters.

Enjoy!  :)
« Last Edit: 17 Oct 2003, 02:43:12 by Jus »

Offline Sui

  • Former Staff
  • ****
    • OFPEC
...triggers won't do, because some friendly soldiers are already in the area.

Ah Contraire....

unit in (list trigger)

Will detect if a specific unit is in a trigger set with a present condition.
You can also group the specific unit to the trigger so it will only be set off by that unit ;)

Another alternative is the distance command:

player distance object < x


Your method works, but it's a bit of a cumbersome workaround when there are already much simpler methods in place in the game itself ;)

Jus

  • Guest
Oh, I feel like such an idiot now... :-[
OF COURSE you can do it the old fashioned way, that is by grouping the trigger with the unit...

But I don't stop you if you still want to do it the hard way I just posted here ;) Oh boy, I always do things the hard way, then remember there was a simpler way. Well, at least the topic still stands, the thread now has two solutions ;)

EDIT: Make that three...
« Last Edit: 17 Oct 2003, 02:51:14 by Jus »