Jump to content
snakeplissken

How to activate the trigger when one side fires a weapon?

Recommended Posts

I ask you to help him create a trigger with the above action, which I even found a few lines of script here in the forum that recognizes this.

The command line I found was the one below which I set a trigger condition.

 

*script inside Trigger in COND

{
	if ((side _x isEqualTo independent)) then
	{
		_x addEventHandler ["firedMan",
		{
			_unit = param [0, objNull];
			if ((isNull _unit)) exitWith {};
			hintSilent "The enemy knows he is being attacked!";
		}];
	};
} forEach allUnits;

¹ Even if I delete the trigger above the command still recognizes the enemy firing.
 

The problem now is that I can't disable this function, even if I delete the trigger that has this command, and since I can't disable this event handler, every shot an AI fires, the command within its line repeats.

 

So if anyone knows how I disable this or some other command that I can use where it is activated when one side fires a weapon and that command is canceled shortly thereafter, I would be very grateful.


² I tried to use the event handler that cancels the command, but the game throws error while executing these command below.

{
	if ((side _x isEqualTo independent)) then
	{
		_x removeAllEventHandlers ["firedMan",
		{
			_unit = param [0, objNull];
			if ((isNull _unit)) exitWith {};
		}];
	};
} forEach allUnits;

I am quite layman in script and English is not my default language, so always having to find on my own the script or command that I seek with the help of Google translator, but if I can't find what I'm looking for, or can't put it to work the way I hope, I come here in the forum to ask your help.

 

** I'm doing a mission from which a team will infiltrate the illegal weapons negotiation site, so if someone on the enemy side sees the invaders and starts firing, the trigger is triggered and the mission fails.
But if the invading side (the players) reaches the marked location (at the top of the building) for the attack at the scheduled time, the above command will be canceled, so if the enemies start firing the mission will no longer fail.

 

In short, all I'm looking for is a condition that activates when any enemy side soldier fires his weapon, and another command that cancels that first condition.

Share this post


Link to post
Share on other sites
10 hours ago, snakeplissken said:

The problem now is that I can't disable this function, even if I delete the trigger that has this command, and since I can't disable this event handler, every shot an AI fires, the command within its line repeats.

You need to store the result of "addEventHandler" and call "removeEventHandler" with it.

I'd recommend storing it directly on the unit (_x) using setVariable.

Do Triggers have a "OnDeactivation"?

Otherwise you could check inside the eventhandler if the marked location has been reached (put a trigger on the target location, and just set a global variable) and then remove the eventhandler using _thisEventHandler variable.

 

https://community.bistudio.com/wiki/addEventHandler

https://community.bistudio.com/wiki/removeEventHandler

https://community.bistudio.com/wiki/setVariable

 

10 hours ago, snakeplissken said:

so if someone on the enemy side sees the invaders and starts firing, the trigger is triggered and the mission fails.

Isn't it enough to just trigger once the enemy side sees the invaders? Why go to such great effort to try to detect shooting?

Afaik there is a "Detected by X" trigger type that you might be able to use?

 

 

10 hours ago, snakeplissken said:

I am quite layman in script and English is not my default language

I'm not good enough at explaining stuff, so I'll have to leave that to someone else.

Share this post


Link to post
Share on other sites
On 10/16/2019 at 9:49 AM, Dedmen said:

You need to store the result of "addEventHandler" and call "removeEventHandler" with it.

I'd recommend storing it directly on the unit (_x) using setVariable.

Do Triggers have a "OnDeactivation"?

Otherwise you could check inside the eventhandler if the marked location has been reached (put a trigger on the target location, and just set a global variable) and then remove the eventhandler using _thisEventHandler variable.

 

https://community.bistudio.com/wiki/addEventHandler

https://community.bistudio.com/wiki/removeEventHandler

https://community.bistudio.com/wiki/setVariable

 

Isn't it enough to just trigger once the enemy side sees the invaders? Why go to such great effort to try to detect shooting?

Afaik there is a "Detected by X" trigger type that you might be able to use?

 

 

I'm not good enough at explaining stuff, so I'll have to leave that to someone else.

 

The reason for not using the trigger presence detection option is that it activates as soon as AI looks at you, where the trigger activates even if you eliminate AI before it reacts by firing your weapon.

 

Therefore, if this AI is isolated at a location on the map a bit away from other AI, and just by spotting the invaders, the trigger this activating without the AI firing its weapon, the immersion of the real logic will disappear, because if you eliminate a enemy before he shoots, there will be no way for enemy on the other side of the map to know that they are being attacked.

 

So, wanting to get a little realism, I wanted the presence of the invaders to be alarmed only when one of the AI fires his weapon, because in real logic, the noise of the firing will alert others that they are being attacked.

 

But I can finally do it the way I am looking for.

 

What I did was use another event handler that removes the first handler that activates after firing the weapon.
Shortly thereafter it releases a public variable that is recognized inside the trigger condition, which triggers the mission failure module.

 

*inside the init.sqf file if you want the mission start to fail if the enemy shoots you

///Creation of the name variable "Alert" as "False" that will be used to activate the trigger when it becomes "True" ///

alert = false; 


///Command that recognizes the firing of a weapon from some AI on the side "Independent", then removes the handler, and turns the variable named "Alert" to true, which will trigger the trigger in the editor. ///

{ 
 if ((side _x isEqualTo independent)) then 
 { 
  _x addEventHandler ["firedMan", 
  { 
   _unit = param [0, objNull]; 
   if ((isNull _unit)) exitWith {}; 
   hintSilent "Você foi descoberto imbecil!";

 {  
 if ((side _x isEqualTo independent)) then  
 {  
  _x removeEventHandler ["firedMan", 0]; 
 };  
} forEach allUnits;	
	
	alert = true;
	publicVariable "alert";
	alert remoteExec ["true"];
  }];
	
 }; 
} forEach allUnits;

If I use all of the above within the INIT file, it will already be recognized at the beginning of the mission, so that would be for the mission's first purpose.

 

If I want to use this for another purpose, I simply execute the second command within the activation of a trigger, or call that command from within an SQF file.

 

 

To remove the activation of this handler, I just use the command lines below.

{  
 if ((side _x isEqualTo independent)) then  
 {  
  _x removeEventHandler ["firedMan", 0]; 
 };  
} forEach allUnits;

 

From which I can also use this command within Trigger Activation, or called from an SQF file.

 

After that the side independent can fire their weapons that the mission will no longer fail.

 

Anyway, thank you so much for trying to help me in finding the solution to my question.

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

×