Jump to content
Sign in to follow this  
Double Doppler

Two EventHandlers interfering with each other

Recommended Posts

Is it possible that two EHs, namely "HandleDamage" EHs could be interfereing with each other? I read up on the BIKI that this is not so, you could add as many EHs of the same event on the same unit as you like. However, at the moment all fingers point at EHs interfering with each other.

My mod uses the "HandleDamage" EH to filter cartridges hit on a unit, then calls a function to spawn effects if it is the right type of cartridge. However, the community that I let test it has another script, a revive one, which also uses "HandleDamage" to handle its function. Both EHs are being added to the same unit, the commands reproduced for multiple players as they enter the role of their units (via client-side scripting). My EH doesn't seem to fire, for some reason, yet their EH works perfectly fine.

I have conducted peer to peer tests with the script in MP, and it works fine. I handed the scripts over to the community to privately test during their mission testing session, and both EHs fired without error. However, when the public server goes up (MP, multiple players, dedi), only one EH, the revive one, fires. My EH has no effect at all when the cartridges are shot at a player.

The lead SQF scripter of the community testing suggests that the two EHs are interfering with each other, however I can't make sense of how they could, being what is said on the BIKI:

You may add as many event handlers of any type as you like to every unit, if you add an event handler of type "killed" and there already exists one, the old one doesn't get overwritten.

What I would like to know, is, has anyone else experienced this problem or a similar one related to EHs? This is rather confusing as the evidence and documentation points to it not being possible, however multiple fixes and thorough testing have left all fingers pointing at this case.

Share this post


Link to post
Share on other sites

Are you using addMPEventHandler when using it on a multiplayer server? The regular EHandler won't work as far as I know. MPHit should be the equivalent to HandleDamage and should get you the same effect.

Share this post


Link to post
Share on other sites
Are you using addMPEventHandler when using it on a multiplayer server? The regular EHandler won't work as far as I know. MPHit should be the equivalent to HandleDamage and should get you the same effect.

All the non-mp variant Event Handlers work in MP just fine.

The lead SQF scripter of the community testing suggests that the two EHs are interfering with each other, however I can't make sense of how they could, being what is said on the BIKI

Whatever you write inside those Event Handlers is what may be causing the conflict.

Share this post


Link to post
Share on other sites

Whatever you write inside those Event Handlers is what may be causing the conflict.

All that remains within the EH's scope is a call to a function, which retrieves the passed array _this and performs a check on one of its variables, then passes another two variables to another function.

// Executed within client scope
player addEventHandler ["HandleDamage",{_this call fnc_handleDamage}];	

fnc_handleDamage = {
   private ["_victim","_selection","_damage","_shooter","_bullet"];
_victim    = _this select 0;
_selection = _this select 1;
_damage    = _this select 2;
_shooter   = _this select 3;
_bullet    = _this select 4;

if (_bullet in array_Bullet) then {
	[_victim,_shooter,20] spawn fnc_hit;
};

_damage
};

The problem does not seem to lie in function "fnc_hit" because there is another method that spawns it, via a hotkey, that works OK in MP, with no problems.

The revive function returns the value "false" at the end of its statement, mine returns the original values. Would this interfere with the run-time of the code within my EH's scope?

Share this post


Link to post
Share on other sites

You aware that HandleDamage event fires multiple times for each selection? Can this be the cause of your problem?

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#HandleDamage

This EH is triggered separately for every selection of the damaged object.

Also, you sure that condition in the if statement really returns true? Maybe you can add some debug.

fnc_handleDamage = {
   private ["_victim","_selection","_damage","_shooter","_bullet"];
   _victim    = _this select 0;
   _selection = _this select 1;
   _damage    = _this select 2;
   _shooter   = _this select 3;
   _bullet    = _this select 4;

   diag_log "Event has fired";

   if (_bullet in array_Bullet) then {

       diag_log "Bullet is valid";

       [_victim,_shooter,20] spawn fnc_hit;
   };

   _damage
};

Results will be in .rpt file.

Edited by neokika

Share this post


Link to post
Share on other sites
Is it possible that two EHs, namely "HandleDamage" EHs could be interfereing with each other?

Yes. You should use handleDamage only once for an object.

Reason is, handleDamage returns a value for each selection/overall damage back to the engine when it triggers. So if you have more than one handleDamage EH attached to an object one handleDamage EH script overwrites the results for the other one leading to unknown behaviour as you don't know which result the engine is using.

Xeno

Share this post


Link to post
Share on other sites
You aware that HandleDamage event fires multiple times for each selection? Can this be the cause of your problem?

http://community.bistudio.com/wiki/ArmA_2:_Event_Handlers#HandleDamage

Also, you sure that condition in the if statement really returns true? Maybe you can add some debug.

// Code

Results will be in .rpt file.

The if statement works fine, I tested it numerous times with hint debugging to make sure it worked before I started working on MP compatibility. How the EH being fired multiple times affects the running of the code within the EH I don't know, and I don't think it should, because there doesn't seem to be any documentation suggesting so.

Yes. You should use handleDamage only once for an object.

Reason is, handleDamage returns a value for each selection/overall damage back to the engine when it triggers. So if you have more than one handleDamage EH attached to an object one handleDamage EH script overwrites the results for the other one leading to unknown behaviour as you don't know which result the engine is using.

Xeno

Is there any substitute for handleDamage? I need to know what projectile a unit was hit with, who fired it, who it was fired at etc. all that handleDamage offers.

What I can't make sense of is that the code does not seem to be processed, from what I can read on the BIKI it says more or less that the only thing that would be affected by using two EHs would be the return value. My one returns the damage done, where as the revive EH returns false. While the return values are different in each EH I can't understand why they should be affecting the runtime of the code inside the EH.

Share this post


Link to post
Share on other sites

The problem Xeno was talking about that if a unit gets hit, the engine executes the EH twice. The variables may differ, and you can't know which ones the engine uses, so it can mess up if the script requires certain values.

Wouldn't MPHit be a sufficient substitute? The only thing it does not offer is a projectile .. but seeing your main post right now that's probably the main thing you need ...

I don't know if there's another way to fetch the projectile which shot the unit, but I'm pretty sure there is. Maybe someone else knows this.

Share this post


Link to post
Share on other sites
The variables may differ, and you can't know which ones the engine uses, so it can mess up if the script requires certain values.

It's not so much about the handleDamage scripts it's about what gets returned to the engine as last value in the scripts.

For example, an object with two handleDamage EHs attached to it. One handleDamage EH recalculates _this select 2 and returns the recalculated value back to the engine, a second one just returns 0 so no damage is applied. You can't say for sure which result the engine is using, you might want to make the object indestructable but the engine uses the recalculated damage value thus the object is not indestructable.

And don't forget that the handleDamage EH does not trigger once per damage but multiple times, means, overall damage plus number of selections. The EH scripts are executed 5 times for units, 7 times for tanks (afair), each time the object receives damage, no matter which damage.

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

Hi Xeno,

From a quick test, the event added first gets executed first, for each selection:

"Event 1: "
"Event 2: "
"Event 1: "
"Event 2: "
"Event 1: "
"Event 2: "
"Event 1: "
"Event 2: "
"Event 1: "
"Event 2: "

So, I'm guessing there is no problem adding multiple HandleDamage events to one object unless you mess up the returning damage.

How the EH being fired multiple times affects the running of the code within the EH I don't know, and I don't think it should, because there doesn't seem to be any documentation suggesting so.

It means that everytime you shoot a person with an HandleDamage event handler, currently, your ([_victim,_shooter,20] spawn fnc_hit;) gets executed 5 times.

Edited by neokika

Share this post


Link to post
Share on other sites

So, I'm guessing there is no problem adding multiple HandleDamage events to one object unless you mess up the returning damage.

What if an addon uses handleDamage too ?

You can't make sure that your handleDamage EH runs first or last.

And then there could also be the chance that one script uses different setHit values than the other. And so on.

It means that everytime you shoot a person with an HandleDamage event handler, currently, your ([_victim,_shooter,20] spawn fnc_hit;) gets executed 5 times.

The worst thing one can do is using spawn or execVM to run event code (why would anybody give up execution in the same frame ?) :)

handleDamage, as nice as it is, is not that easy to master (I've played around with it for months when I made ACE wounds). For example, it still triggers even when the object is not alive anymore. Shooting somebody in the leg can and will also trigger damage to other selections, and so on.

Anyway, recommended way for using handleDamage is using it once for an object.

Xeno

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
Sign in to follow this  

×