createTrigger: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
(58 intermediate revisions by 4 users not shown)
Line 21: Line 21:
|gr1= Triggers
|gr1= Triggers


|descr= Creates a sensor ([[trigger]]) of the given type and at the given position. The type must be a class name in CfgNonAIVehicles or CfgVehicles with simulation <nowiki>=</nowiki> detector. An array containing all units that have activated the trigger is available via [[list]] ''triggerobj''. Since triggers are [[object|'''objects''']], they can be deleted using [[deleteVehicle]].<br><br>
|descr= Creates a [[Trigger|trigger]] of the given type and at the given position. The type must be a class name in ''CfgNonAIVehicles'' or ''CfgVehicles'' with <syntaxhighlight lang="cpp" inline>simulation = detector</syntaxhighlight>. An array containing all units that have activated the trigger is available via <sqf inline>list triggerobj</sqf>. Since triggers are '''[[Object]]s''', commands such as [[getPosASL]], [[setPosASL]], [[deleteVehicle]] etc. work on them.
{{Feature | Informative | Note that triggers are objects, and commands such as [[getPosASL]], [[setPosASL]], [[deleteVehicle]], etc. work on them the same as other objects.}}
{{Feature|important|Triggers are always created on the road surface (AGL) at provided x, y coordinates. The z param is ignored. In order to place the trigger with a custom z, use a 'setPosXXX' command after trigger creation.}}
{{Feature | Informative | Since Arma 3 v1.44 triggers can be created locally on clients setting optional param ''makeGlobal'' to [[false]]}}
{{Feature|informative|Since {{arma3}} v1.54 triggers can be disabled/enabled using [[enableSimulation]] command.}}
{{Feature | Informative | Since Arma 3 v1.54 triggers can be disabled/enabled using [[enableSimulation]] command}}<br>


Triggers are created with default params, which are:
Triggers are created with default parameters:
* <tt>a</tt>: 50.0
{{Columns|4|
* <tt>b</tt>: 50.0
* {{hl|a}}: 50
* <tt>c</tt>: -1
* {{hl|b}}: 50
* <tt>angle</tt>: 0
* {{hl|c}}: -1
* <tt>rectangular</tt>: false
* {{hl|angle}}: 0
* <tt>activationBy</tt>: None
* {{hl|rectangular}}: false
* <tt>activationType</tt>: Present
* {{hl|activationBy}}: None
* <tt>repeating</tt>: false
* {{hl|activationType}}: Present
* <tt>timeoutMin</tt>: 0
* {{hl|repeating}}: false
* <tt>timeoutMid</tt>: 0
* {{hl|timeoutMin}}: 0
* <tt>timeoutMax</tt>: 0
* {{hl|timeoutMid}}: 0
* <tt>interruptable</tt>: true
* {{hl|timeoutMax}}: 0
* <tt>type</tt>: None
* {{hl|interruptable}}: true
* <tt>text</tt>: ""
* {{hl|type}}: None
* <tt>name</tt>: ""
* {{hl|text}}: ""
* <tt>expCond</tt>: "this"
* {{hl|name}}: ""
* <tt>expActiv</tt>: ""
* {{hl|expCond}}: "this"
* <tt>expDesactiv</tt>: ""
* {{hl|expActiv}}: ""
* <tt>interval</tt>: 0.5 (Cannot be accessed via editor, [[setTriggerInterval | scripted only]] since Arma 3 v1.98)
* {{hl|expDesactiv}}: ""
* {{GVI|arma3|1.98|size= 0.75}} {{hl|interval}}: 0.5
}}


|s1= [[createTrigger]] [type, position, makeGlobal]
|s1= [[createTrigger]] [type, position, makeGlobal]


|p1= [type, position, makeGlobal]: [[Array]]
|p1= type: [[String]] - usually "EmptyDetector"
|p2= type: [[String]] - usually "EmptyDetector"
 
|p3= position: [[Position2D]], [[Position3D]] or [[Object]]
|p2= position: [[Position#Introduction|Position2D]], [[Position#Introduction|Position3D]] or [[Object]] (see the note in description)
|p4= makeGlobal (Optional): [[Boolean]] - locality flag ''(available since Arma 3 v1.44)''
 
* [[true]] (Default) - trigger is global {{Icon|globalEffect|32}}
|p3= makeGlobal: [[Boolean]] - (Optional - default [[true]]) locality flag
* [[false]] - trigger is local {{Icon|localEffect|32}}
* [[true]] - trigger is global {{Icon|globalEffect|24}}
* [[false]] - trigger is local {{Icon|localEffect|24}}
|p3since= arma3 1.44


|r1= [[Object]] - created trigger
|r1= [[Object]] - created trigger


|x1= <code>_trg = [[createTrigger]] ["EmptyDetector", [[getPos]] [[player]]];
|x1= <sqf>
_trg [[setTriggerArea]] [5, 5, 0, [[false]]];
_trg = createTrigger ["EmptyDetector", getPos player];
_trg [[setTriggerActivation]] ["CIV", "PRESENT", [[true]]];
_trg setTriggerArea [5, 5, 0, false];
_trg [[setTriggerStatements]] ["this", "hint 'Civilian near player'", "hint 'no civilian near'"];</code>
_trg setTriggerActivation ["CIV", "PRESENT", true];
_trg setTriggerStatements ["this", "hint 'Civilian near player'", "hint 'no civilian near'"];
</sqf>


|x2= Open/close Bar Gate automatically: <code>//--- init of the Bar Gate
|x2= Open/close Bar Gate automatically:
[[if]] ([[isServer]]) [[then]]
<sqf>
//--- init of the Bar Gate
if (isServer) then
{
{
_gateTrigger = [[createTrigger]] ["EmptyDetector", [[getPosWorld]] [[Magic Variables#this_2|this]], [[false]]];
_gateTrigger = createTrigger ["EmptyDetector", getPosWorld this, false];
_gateTrigger [[setVariable]] ["BarGateObj", [[Magic Variables#this_2|this]]];
_gateTrigger setVariable ["BarGateObj", this];
_gateTrigger [[setTriggerActivation]] ["ANYPLAYER", "PRESENT", [[true]]];
_gateTrigger setTriggerActivation ["ANYPLAYER", "PRESENT", true];
_gateTrigger [[setTriggerArea]] [5, 25, [[getDir]] [[Magic Variables#this_2|this]], [[true]]];
_gateTrigger setTriggerArea [5, 25, getDir this, true];
_gateTrigger [[setTriggerStatements]]
_gateTrigger setTriggerStatements  
[
[
"this",  
"this",  
"[[thisTrigger]] [[getVariable]] ""BarGateObj""; [[animateSource]] [""Door_1_sound_source"", 1]",  
"thisTrigger getVariable ""BarGateObj"" animateSource [""Door_1_sound_source"", 1]",  
"[[thisTrigger]] [[getVariable]] ""BarGateObj""; [[animateSource]] [""Door_1_sound_source"", 0]"
"thisTrigger getVariable ""BarGateObj"" animateSource [""Door_1_sound_source"", 0]"
];
];
};</code>
};
</sqf>


|seealso= [[setTriggerActivation]], [[setTriggerArea]], [[setTriggerStatements]], [[setTriggerText]], [[setTriggerTimeout]], [[setTriggerType]], [[setEffectCondition]], [[setSoundEffect]], [[setMusicEffect]], [[setTitleEffect]], [[deleteVehicle]], [[synchronizeWaypoint]], [[synchronizeTrigger]], [[createGuardedPoint]], [[triggerInterval]], [[setTriggerInterval]], [[enableSimulation]], [[simulationEnabled]]
|seealso= [[setTriggerActivation]] [[setTriggerArea]] [[setTriggerStatements]] [[setTriggerText]] [[setTriggerTimeout]] [[setTriggerType]] [[setEffectCondition]] [[setSoundEffect]] [[setMusicEffect]] [[setTitleEffect]] [[deleteVehicle]] [[synchronizeWaypoint]] [[synchronizeTrigger]] [[createGuardedPoint]] [[triggerInterval]] [[setTriggerInterval]] [[enableSimulation]] [[simulationEnabled]]
}}
}}


<dl class="command_description">
{{Note
 
|user= TeaCup
<dt><dt>
|timestamp= 20130306141500
<dd class="notedate">Posted on March 6, 2013 - 14:15 (CEST)</dd>
|text= Calling [[list]] immediately after creating a trigger this way (and setting up activation, area, statements, timeout, etc..), will return <null> instead of an array. It seems the trigger needs about 1 second to initialise, after which it will behave as expected: returning an array of all the objects inside the trigger (the ones matching the criteria), or an empty array.
<dt class="note">[[User:TeaCup|teaCup]]</dt>
}}
<dd class="note">Calling [[list]] immediately after creating a trigger this way (and setting up activation, area, statements, timeout, etc..), will return <null> instead of an array. It seems the trigger needs about 1 second to initialise, after which it will behave as expected: returning an array of all the objects inside the trigger (the ones matching the criteria), or an empty array.
 
</dl>

Latest revision as of 20:20, 31 October 2024

Hover & click on the images for description

Description

Description:
Creates a trigger of the given type and at the given position. The type must be a class name in CfgNonAIVehicles or CfgVehicles with simulation = detector. An array containing all units that have activated the trigger is available via list triggerobj. Since triggers are Objects, commands such as getPosASL, setPosASL, deleteVehicle etc. work on them.
Triggers are always created on the road surface (AGL) at provided x, y coordinates. The z param is ignored. In order to place the trigger with a custom z, use a 'setPosXXX' command after trigger creation.
Since Arma 3 v1.54 triggers can be disabled/enabled using enableSimulation command.

Triggers are created with default parameters:

  • a: 50
  • b: 50
  • c: -1
  • angle: 0
  • rectangular: false
  • activationBy: None
  • activationType: Present
  • repeating: false
  • timeoutMin: 0
  • timeoutMid: 0
  • timeoutMax: 0
  • interruptable: true
  • type: None
  • text: ""
  • name: ""
  • expCond: "this"
  • expActiv: ""
  • expDesactiv: ""
  • Arma 3 logo black.png1.98 interval: 0.5
Groups:
Triggers

Syntax

Syntax:
createTrigger [type, position, makeGlobal]
Parameters:
type: String - usually "EmptyDetector"
position: Position2D, Position3D or Object (see the note in description)
since Arma 3 logo black.png1.44
makeGlobal: Boolean - (Optional - default true) locality flag
Return Value:
Object - created trigger

Examples

Example 1:
_trg = createTrigger ["EmptyDetector", getPos player]; _trg setTriggerArea [5, 5, 0, false]; _trg setTriggerActivation ["CIV", "PRESENT", true]; _trg setTriggerStatements ["this", "hint 'Civilian near player'", "hint 'no civilian near'"];
Example 2:
Open/close Bar Gate automatically:
//--- init of the Bar Gate if (isServer) then { _gateTrigger = createTrigger ["EmptyDetector", getPosWorld this, false]; _gateTrigger setVariable ["BarGateObj", this]; _gateTrigger setTriggerActivation ["ANYPLAYER", "PRESENT", true]; _gateTrigger setTriggerArea [5, 25, getDir this, true]; _gateTrigger setTriggerStatements [ "this", "thisTrigger getVariable ""BarGateObj"" animateSource [""Door_1_sound_source"", 1]", "thisTrigger getVariable ""BarGateObj"" animateSource [""Door_1_sound_source"", 0]" ]; };

Additional Information

See also:
setTriggerActivation setTriggerArea setTriggerStatements setTriggerText setTriggerTimeout setTriggerType setEffectCondition setSoundEffect setMusicEffect setTitleEffect deleteVehicle synchronizeWaypoint synchronizeTrigger createGuardedPoint triggerInterval setTriggerInterval enableSimulation simulationEnabled

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
TeaCup - c
Posted on Mar 06, 2013 - 14:15 (UTC)
Calling list immediately after creating a trigger this way (and setting up activation, area, statements, timeout, etc..), will return <null> instead of an array. It seems the trigger needs about 1 second to initialise, after which it will behave as expected: returning an array of all the objects inside the trigger (the ones matching the criteria), or an empty array.