Home   Help Search Login Register  

Author Topic: Triggering when enemy opens fire (SOLVED)  (Read 1621 times)

0 Members and 1 Guest are viewing this topic.

Offline CAS_Daniel

  • Members
  • *
  • Rifleman
Triggering when enemy opens fire (SOLVED)
« 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!
« Last Edit: 29 Nov 2008, 14:13:27 by CAS_Daniel »
Romeo 2.5 UK-based Light Infantry Platoon
forums.romeo25.com/

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Triggering when enemy opens fire
« Reply #1 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).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Triggering when enemy opens fire
« Reply #2 on: 28 Nov 2008, 06:45:31 »
Spooner,

Just to touch on a previous project,
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
Pesky Human!!
Wort Wort Wort.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Triggering when enemy opens fire
« Reply #3 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.
"When 900 years YOU reach, look as good you will not!"

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Triggering when enemy opens fire
« Reply #4 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?

Offline Ext3rmin4tor

  • Members
  • *
Re: Triggering when enemy opens fire
« Reply #5 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.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Triggering when enemy opens fire
« Reply #6 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
Pesky Human!!
Wort Wort Wort.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Triggering when enemy opens fire
« Reply #7 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.
"When 900 years YOU reach, look as good you will not!"

Offline CAS_Daniel

  • Members
  • *
  • Rifleman
Re: Triggering when enemy opens fire
« Reply #8 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.  :)
Romeo 2.5 UK-based Light Infantry Platoon
forums.romeo25.com/

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Triggering when enemy opens fire
« Reply #9 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).
« Last Edit: 30 Nov 2008, 03:48:20 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)