Jump to content
Mungo Turkey

Is there a way to contain a Fired eventhandler to a trigger area? [SOLVED]

Recommended Posts

Hello everyone.


Apologies for being useless and having to come on here, but I'm stuck.


Using VCOM AI (when units are grouped) the firefights are really good.


My goal is to make the AI behave naturally to gunfire before they all 'knowsabout' you. At default it is really, really bad. My idea was to simulate the sound of gunfire carrying realistic distances (using triggers of up to 1km or more) and then have the AI react appropriately within these trigger areas when any shots are fired.


I am nearly there. I don't understand SQF, but I spliced these things together from looking through the forums.


Player squad is called GT.

OPFOR units named a1, a2, a3, a4, a5.


In the (player's) Object Init box -


{_x addEventHandler['Fired',{shotIsFired = true}]} forEach (units GT);                                 note - I would do it for all OPFOR units as well so they react the same if OPFOR fired first.


In the Trigger named T1 -


Activation -  Any group member

Activation type - Present


Condition Expression - shotIsFired

On Activation - [a2,a3,a4,a5] join a1; a1 reveal [GT, 1.7]


This works brilliantly. They don't know exactly where I am, but they break out of ambient animations/patrol cycles instantly, huddle up (group) and take appropriate action. As they would in reality when hearing the shot. 


The problem is it will trigger if GT shoots outside the trigger area, they could be on the moon and it triggers! It is completely irrelevant to what settings I use in the trigger, what size or who I try to group to sync to, any of it.


If anyone could help that would be great. Thanks in advance.



Share this post

Link to post
Share on other sites

Close but no cigar...


In the Trigger named T1 -


Condition - shotIsFired and this              also tried              shotisfired and GT in thislist


This prevented activation when shooting from outside the trigger, but then the trigger activated as soon as I walked in. This would be the case for all further triggers.

If I walked in the trigger area without firing in that session it would not be activated until a shot went off, but from anywhere.


Must be a way to contain the 'fired' eventhandler to a trigger area somehow.


It's probably something really simple. Please put me out of my misery.

Share this post

Link to post
Share on other sites

I think you need inArea command.

{_x addEventHandler['Fired',{if (_this#0 inArea T1) then {shotIsFired = true}}]} forEach (units GT);


  • Like 2
  • Thanks 1

Share this post

Link to post
Share on other sites

POLPOX thank you so much.


Spot on.


I was on the verge of using stones dotted around everywhere with fired near Eventhandlers! 🤡


Much appreciated, hope it helps others as well.

Share this post

Link to post
Share on other sites

Sorry for diggin up this old stuff but i confused. Im tryin to create trigger in wich if player will open fire Independent become from friends to a hostile.
So i put in init of player:
this addEventHandler ["Fired", { if (this inArea CheckFireTrigger) then {ShootingInVillage=true}} ];

And in trigger (CheckFireTrigger) condition:
ShootingInVillage && (player in thislist)

On Activation:
west setFriend [resistance, 0];
resistance setFriend [west, 0];

But it doesnt work. So where i am wrong here?

Share this post

Link to post
Share on other sites

Event handlers generally pass certain parameters to their code block.

this addEventHandler ["Fired", {
	params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
//unit: Object - Object the event handler is assigned to
//weapon: String - Fired weapon
//muzzle: String - Muzzle that was used
//mode: String - Current mode of the fired weapon
//ammo: String - Ammo used
//magazine: String - magazine name which was used
//projectile: Object - Object of the projectile that was shot out
//gunner: Object - gunner whose weapons are firing.

So, try 

this addEventHandler ["Fired", { if (_unit inArea CheckFireTrigger) then {ShootingInVillage=true}} ];

There may be other issues.

  • Like 1
  • Thanks 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