Jump to content
Sign in to follow this  
karl1206

Unit in trigger via .sqf

Recommended Posts

Hey i was wondering what the easiest way to check if a unit isn't within a trigger placed in editor via a script. i want it as a condition for a "if" command. thx in advance. :)

Share this post


Link to post
Share on other sites

Hey i was wondering what the easiest way to check if a unit isn't within a trigger placed in editor via a script. i want it as a condition for a "if" command. thx in advance. :)

 

You want to know if a unit is not in a trigger area? The easiest way is to use the special variable "thisList", which is an array accessible in the trigger code fields (condition, activation, deactivation) that contains every unit presently meeting the trigger detection criteria. If you want this information accessible in an external script, you can either call the script from your trigger, passing thisList as an argument, or you can set thisList to a global variable. For example, you could make a repeatable trigger with the criteria "Any -- Present" and the following code in both the activation and deactivation fields: 

var_myTriggerList = thisList

Now the global variable "var_myTriggerList" will contain a list of everyone in your trigger's area, updated each time a unit enters or leaves. In your script, you could check against this with the following code to determine that a unit is not in the area:

if (isNil "var_myTriggerList") then {var_myTriggerList = []};
if (!myUnit in var_myTriggerList) then {code}

(The first line accounts for a situation where no unit has yet entered or left the trigger area, in which case the variable would not yet be defined).

  • Like 3

Share this post


Link to post
Share on other sites
if ([trigger, unit] call BIS_fnc_inTrigger) then {
};

or

if (["marker", unit] call BIS_fnc_inTrigger) then {
};

negative

if !([trigger, unit] call BIS_fnc_inTrigger) then {
};

or

if !(["marker", unit] call BIS_fnc_inTrigger) then {
};
  • Like 1

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  

×