{"name":"createTrigger","title":"createTrigger","type":"command","url":"https://community.bistudio.com/wiki/createTrigger","revid":370090,"updated":"2024-10-31T19:20:48Z","groups":["Triggers"],"status":"ok","games":{"ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","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.\n\n> [!IMPORTANT]\n> 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.\n\n> [!NOTE]\n> Since Arma 3 v1.54 triggers can be disabled/enabled using enableSimulation command.\n\nTriggers are created with default parameters:\n\n- `a`: 50\n- `b`: 50\n- `c`: -1\n- `angle`: 0\n- `rectangular`: false\n- `activationBy`: None\n- `activationType`: Present\n- `repeating`: false\n- `timeoutMin`: 0\n- `timeoutMid`: 0\n- `timeoutMax`: 0\n- `interruptable`: true\n- `type`: None\n- `text`: \"\"\n- `name`: \"\"\n- `expCond`: \"this\"\n- `expActiv`: \"\"\n- `expDesactiv`: \"\"\n- Arma 3 v1.98 `interval`: 0.5","syntaxes":[{"syntax":"createTrigger [type, position, makeGlobal]","params":[{"name":"type","type":"String","description":"usually \"EmptyDetector\"","type_expr":"String"},{"name":"position","type":"Position2D, Position3D or Object (see the note in description)","type_expr":"Position2D | Position3D | Object"},{"name":"makeGlobal","type":"Boolean","optional":true,"default":"true","description":"locality flag\n\n- true - trigger is global Global effect\n- false - trigger is local Local effect","type_expr":"Boolean","since":"arma3 1.44","text":"makeGlobal: Boolean - (Optional - default true) locality flag\n\n- true - trigger is global Global effect\n- false - trigger is local Local effect"}],"returns":{"type":"Object","type_expr":"Object","description":"created trigger"},"form":"unary","right":{"text":"[type, position, makeGlobal]"}}],"examples":[{"code":["_trg = createTrigger [\"EmptyDetector\", getPos player];\n_trg setTriggerArea [5, 5, 0, false];\n_trg setTriggerActivation [\"CIV\", \"PRESENT\", true];\n_trg setTriggerStatements [\"this\", \"hint 'Civilian near player'\", \"hint 'no civilian near'\"];"]},{"text":"Open/close Bar Gate automatically:\n\n```sqf\n//--- init of the Bar Gate\nif (isServer) then\n{\n    _gateTrigger = createTrigger [\"EmptyDetector\", getPosWorld this, false];\n    _gateTrigger setVariable [\"BarGateObj\", this];\n    _gateTrigger setTriggerActivation [\"ANYPLAYER\", \"PRESENT\", true];\n    _gateTrigger setTriggerArea [5, 25, getDir this, true];\n    _gateTrigger setTriggerStatements\n    [\n        \"this\",\n        \"thisTrigger getVariable \"\"BarGateObj\"\" animateSource [\"\"Door_1_sound_source\"\", 1]\",\n        \"thisTrigger getVariable \"\"BarGateObj\"\" animateSource [\"\"Door_1_sound_source\"\", 0]\"\n    ];\n};\n```","code":["//--- init of the Bar Gate\nif (isServer) then\n{\t\n\t_gateTrigger = createTrigger [\"EmptyDetector\", getPosWorld this, false];\n\t_gateTrigger setVariable [\"BarGateObj\", this];\n\t_gateTrigger setTriggerActivation [\"ANYPLAYER\", \"PRESENT\", true];\n\t_gateTrigger setTriggerArea [5, 25, getDir this, true];\n\t_gateTrigger setTriggerStatements \n\t[\n\t\t\"this\", \n\t\t\"thisTrigger getVariable \"\"BarGateObj\"\" animateSource [\"\"Door_1_sound_source\"\", 1]\", \n\t\t\"thisTrigger getVariable \"\"BarGateObj\"\" animateSource [\"\"Door_1_sound_source\"\", 0]\"\n\t];\n};"]}],"see_also":["setTriggerActivation","setTriggerArea","setTriggerStatements","setTriggerText","setTriggerTimeout","setTriggerType","setEffectCondition","setSoundEffect","setMusicEffect","setTitleEffect","deleteVehicle","synchronizeWaypoint","synchronizeTrigger","createGuardedPoint","triggerInterval","setTriggerInterval","enableSimulation","simulationEnabled"],"notes":[{"user":"TeaCup","date":"2013-03-06T14:15:00Z","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."}]}