Jump to content
Sign in to follow this  
clydefrog

detecting when 2 units are out of an area

Recommended Posts

What's the best way of detecting when something has left an area via a trigger? At the moment I have 2 AI men and I have a trigger with this in the onAct: powpilot1 distance center >300 or powpilot2 distance center >300

I have an object called "center" and the trigger is supposed to detect when 1 of the 2 units are more than 300 metres from it then show a hint. The problem with this is sometimes (and I have no idea how it can happen) it triggers when they are not even that far from it e.g. 100 metres. I need something that works better and is more reliable that will only trigger when they are out of a trigger zone or something, I've tried quite a few other things like not present triggers with unit in thislist and stuff like that and none of it has worked. Any ideas?

Thanks.

Share this post


Link to post
Share on other sites

BIS_fnc_inTrigger

Author: Karel Moricky

Description:

Detects whether is position within trigger area.

Parameter(s):

_this select 0: Trigger

_this select 1: Position

_this select 2: OPTIONAL - scalar result (distance from border)

Returns:

Boolean (true when position is in area, false if not).

Share this post


Link to post
Share on other sites
BIS_fnc_inTrigger

Thanks but could you give me an example of how I'd use that? It doesn't really make much sense to me as it is.

Share this post


Link to post
Share on other sites
_test = [_name_of_trigger , _pos_of_obj_to_test] call BIS_fnc_inTrigger;

if (_test) then 
    {
        // Yes the object was in the trigger area. So you can do stuff here.
    }
  else
    {
         // The object was [u]not[/u] in the trigger area. So you can do other stuff here.
     };

Edited by Riouken

Share this post


Link to post
Share on other sites
_test = [_name_of_trigger , _pos_of_obj_to_test] call BIS_fnc_inTrigger;

if (_test) then 
    {
        // Yes the object was in the trigger area. So you can do stuff here.
    }
  else
    {
         // The object was [u]not[/u] in the trigger area. So you can do other stuff here.
     };

Sorry I still don't understand, where do I put this code? What do I put as the position of the unit ( would it be e.g. [MyTrigger, getPos MyUnit] call BIS_fnc_inTrigger; ? ) and also I have two units not only one, but it really only needs to know if either one of them are out of the area. I also have no idea what you'd put in the "you can do stuff here" bit, I am not a scripter. I'd want it to do nothing if they are in the trigger area, and if they are out of it I would want it to give a hint saying "the POWs are out of the base".

Edited by clydefrog

Share this post


Link to post
Share on other sites

If you only need to check if one of the two units has left the trigger thislist should easily do that.

trigger anyone present

cond

!(man1 in thislist) or !(man2 in thislist)

on act

hint "Unit has left"

Share this post


Link to post
Share on other sites

You can put the code where you need to. Probably the best way would be to put it in a .sqf and then run that when you need to check this. It all depends on what your trying to do.

As for two people you just have to run it twice.

[color=#3E3E3E]_test1 = [MyTrigger, getPos MyUnit] call BIS_fnc_inTrigger;
[/color]_test2 = [color=#3E3E3E][MyTrigger, getPos MyUnit2] call BIS_fnc_inTrigger;[/color]

---------- Post added at 08:50 AM ---------- Previous post was at 08:35 AM ----------

After rereading your first post, Im not even sure if you need any of this, if you just want to know(or do something) when one or both of the pilots are more than 300m from the point you can just do this.

while {true} do
{

   center_pos = getMarkerPos "center";
   plr1_pos = getPosAsl powpilot1;
   plr2_pos = getPosAsl powpilot2;
   exitloop = false;

   if ((plr1_pos distance center_pos) > 300) then
   {
       hint "powpilot1 is more than 300m from center";
       exitloop = true;
   };

       if ((plr2_pos distance center_pos) > 300) then
   {
       hint "powpilot2 is more than 300m from center";
       exitloop = true;
   };

   if (exitloop) exitWith {};

sleep 1;
};

Share this post


Link to post
Share on other sites
If you only need to check if one of the two units has left the trigger thislist should easily do that.

trigger anyone present

cond

!(man1 in thislist) or !(man2 in thislist)

on act

hint "Unit has left"

I'm having a problem with this, the trigger is also set up to complete a task so when one of them dies it triggers the code saying they're away from the base and completes the task, because one of them isn't in the list anymore. I'm going to try and work out how to do it but if you think of a solution please let me know, thanks.

Edited by clydefrog

Share this post


Link to post
Share on other sites

!([powCamp, position man1] call BIS_fnc_inTrigger) || !([powCamp, position man2] call BIS_fnc_inTrigger)

Demo.

Share this post


Link to post
Share on other sites

(alive man1 and  !(man1 in thislist)) or (alive man2 and  !(man2 in thislist))

it shouldn't trigger now if they die.

Share this post


Link to post
Share on other sites

Thanks for that kylania, works nicely. I take it it's fine for multiplayer? Also do I need to have the functions module loaded or anything in my init or is it fine as it is? Thank you F2k Sel and Riouken too, I'll try that one out as well then decide which to use, cheers.

Edited by clydefrog

Share this post


Link to post
Share on other sites

Yes you need the functions module down in your mission, or if you use the mod CBA it starts the funtions module for you, so you don't have to worry about it.

When you place it down in your mission, when your mission loads it starts its own init that precompiles and loads all of those functions into memory.

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  

×