Comrades in Arms Discussion Board

Full Version: Detected-By Type of trigger that works as you expect
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I found a post by Killzone Kid that detailed a way to work around the problem of AI detection triggers, and I extended this to be able to work with multiplayer.

Here's the theory:

You have a Detected-By-Trigger with a countdown. You EXPECT that if the players kill all the detecting units before the timeout hits, it would not trigger, but we all know how this turns out.

Now, here's a way to achieve this (most; it has a few caveats). What this does is, it creates a trigger that triggers if and only if any unit that has spotted the players is alive at the end of the timeout.

Here's how it works (this assumes player faction is independent or blufor):

Place a trigger and make it repeatable, but instead of making it "BLUFOR Detected By OPFOR" make it "OPFOR" and "present". Delete the "this" condition and replace it with:

[playableUnits, thisList] call FHQ_fnc_detectedBy

Set the trigger activation field to whatever you need, and set the trigger to TIMEOUT with whatever timeout you want.

That's it. The magic comes with the FHQ_fnc_detectedBy.

If you use a function module, you can put the following code in a function. Otherwise, add it to a variable in the mission's init.sqf:
Code:
FHQ_fnc_detectedBy = { // remove this line if you put it into a function module
   private _detectList = _this select 0;
   private _triggerList = _this select 1;

   private _knowledge = 0;

   {
       private _unit = _x;
       if (alive _unit) then {
           _knowledge = _knowledge + ({(_unit knowsAbout _x) > 0} count _detectList);
       };
   } forEach _triggerList;

   _knowledge > 0
}; // remove this line if you put this into a function module
What does this do? Since the trigger is "OPFOR" and "present", thisList will contain all OPFOR units in the trigger area. playableUnits is the units that can be detected; if you want to restrict this to a subset of units, you can pass a normal array here as well.
The detectedBy function just goes through all the OPFOR units in the trigger and counts their knowledge about the player, if they are alive (dead units do not reset their knowsAbout so this is important). If the result is not 0, then there is at least one unit alive that has detected the players. Since this condition needs to be satisfied over the entire time of the timeout, if the players manage to kill all units with knowsAbout > 0, the trigger will not fire.
Caveats:
  1. Nearby units might be alerted even if they haven't detected you, but usually, they need a line of sight in order for their knowledge to go up.
  2. If there are many OPFOR units in the trigger, this has the potential of being expensive, so I wouldn't recommend to place too many of these triggers.
  3. side (EAST in this case) will retain knowledge of you even if all detecting units are dead, however, it doesn't affect the trigger; the trigger script counts first hand knowledge only
I made a small sample mission attached to this post.

Enjoy!