OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: CAS_Daniel on 28 Nov 2008, 01:38:18

Title: Triggering when enemy opens fire (SOLVED)
Post by: CAS_Daniel on 28 Nov 2008, 01:38:18
Hi.

What's a simple method for triggering a trigger when an OPFOR unit fires?
Other than using the "detected by" method.

Thanks!
Title: Re: Triggering when enemy opens fire
Post by: Spooner on 28 Nov 2008, 03:05:23
Detected-by doesn't really imply firing, so as I'm sure you've already worked out, it isn't entirely useful. Perhaps add a FIRED handler to each OPFOR unit?

Code: (init.sqf / init.sqs) [Select]
fired = false;

Code: (enemy init) [Select]
this addEventHandler ["KILLED", { fired = true }];

And then use a trigger with a condition of "fired" (or just run a script or whatever from the event handler directly).
Title: Re: Triggering when enemy opens fire
Post by: Luke on 28 Nov 2008, 06:45:31
Spooner,

Just to touch on a previous project (http://www.ofpec.com/forum/index.php?topic=31672.msg217739#msg217739),
is there any way to add this to all the units via the init, .ext, or mission files,
as opposed to adding it individually to each unit in the editor?

Luke
Title: Re: Triggering when enemy opens fire
Post by: Wolfrug on 28 Nov 2008, 10:44:29
Just create an island-spanning trigger, activated by whatever side you want (say, OPFOR), and do a simple foreach thislist:
Code: [Select]
condition : this
on activation : {_x addeventhandler ["fired", {hint "wham!"}]} foreach thisList

:)

Wolfrug out.
Title: Re: Triggering when enemy opens fire
Post by: savedbygrace on 28 Nov 2008, 15:27:40
While you guys are covering this subject.....What is the definition of an EventHandler? What does it do? And what does each set of qoutes represent within the array? I noticed Spooner inserted "Killed" in the one while Wolfrug inserted "Fired". Are these standard commands or are they author chosen terms?
Title: Re: Triggering when enemy opens fire
Post by: Ext3rmin4tor on 28 Nov 2008, 15:45:48
An event handler is a way to manage a certain event linked to a unit. You can find a full list of ArmA event handlers here:

http://community.bistudio.com/wiki/ArmA:_Event_Handlers

the command addEventHandler take an array as argument containing the name of the even handler, in this case "fired", and code to execute when the event happens. So the code posted by Wolfrug basically displays "Wham" in the hint window every time an OPFOR unit fire (the command forEach thisList add an event handler for each unit that's satisfing the trigger condition, that is every unit in the OPFOR side that's inside the trigger area). Maybe Spooner made a mistake and used the "killed" event handler which triggers when the unit is killed.

Note that every event handler creates an array named "_this " when triggered which can be passed to a script as argument. For example the "fired" event handler creates a _this array containing infos about the unit who fired, the used weapon, the muzzle used, the current mode of the fired weapon and the ammo classname used.
Title: Re: Triggering when enemy opens fire
Post by: Luke on 29 Nov 2008, 07:03:16
Just create an island-spanning trigger, activated by whatever side you want (say, OPFOR), and do a simple foreach thislist:
Code: [Select]
condition : this
on activation : {_x addeventhandler ["fired", {hint "wham!"}]} foreach thisList

Will that be for only that side, or everyone in the trigger?

Luke
Title: Re: Triggering when enemy opens fire
Post by: Wolfrug on 29 Nov 2008, 10:46:45
As mentioned, the "activated by" decides which side it will be for - make it BLUFOR for west, OPFOR for east, RACS for resistance and so on and so forth. Anybody for, well, anybody :D

Wolfrug out.
Title: Re: Triggering when enemy opens fire
Post by: CAS_Daniel on 29 Nov 2008, 13:48:31
That's exactly what I was after there Wulfrug! Thanks mate, and everybody else that replied.
Learned something new there too.  :)
Title: Re: Triggering when enemy opens fire
Post by: Spooner on 30 Nov 2008, 03:46:12
I noticed Spooner inserted "Killed" in the one while Wolfrug inserted "Fired". Are these standard commands or are they author chosen terms?
Very sorry! My mind is thinking one thing and my fingers are typing another. Should indeed have been "FIRED" (or "fired" or whatever, since it is case-independent).