Jump to content
Leopard20

How to find an even handler's code?

Recommended Posts

Due to incompatibility between some event handlers of the same type, one might need to remove the other event handlers.


But there are times where you might need to reuse the old EHs.

For example, let's say I want to create a "HandleDamage" EH which reduces the unit's damage, but I also have ACE running which interferes with this. So I'll have to remove the ACE's EH. However, if I were to use ACE again, it wouldn't work because its EH has been removed.

Is it possible to somehow remove an event handler temporarily? As in removing the EH but saving its code for later use?

Share this post


Link to post
Share on other sites

First, this is not really how you should think of or use event handlers. You use an event handler to react on an event, and not enabling or disabling them as you find suitable at the moment. If you have more than one event handler of a type and they interfere with each other - that is affecting the same resources - you do better merging them into one. Then you have full control over all conditions.

 

Second, is HandleDamage your example? It’s not just any example,  since it is one that returns a value that sets the unit’s health, and therefore it is more to regard as a special case i believe.

 

Third, why would you want to turn on and off Ace during a mission?

Share this post


Link to post
Share on other sites
1 hour ago, engima said:

If you have more than one event handler of a type and they interfere with each other - that is affecting the same resources - you do better merging them into one.

I know. I'm talking about event handlers added by other modders (for compatibility between my EH and theirs)

 

1 hour ago, engima said:

Second, is HandleDamage your example? It’s not just any example,  since it is one that returns a value that sets the unit’s health, and therefore it is more to regard as a special case i believe.

Not really. That's the one I'm dealing with right now.

 

1 hour ago, engima said:

Third, why would you want to turn on and off Ace during a mission?

I want to add an event handler temporarily that disables the damage from friendly fire for a very short time. Obviously I can't use enableDamage false. I simply use this:

_unit addEventHandler ["HandleDamage", {
	_unit = _this#0;
	_damage = _this#2;
	_shooter = _this#6;
	if (time <= _unit getVariable ["T_noDamageTime", 0] && [side _unit, side _shooter] call BIS_fnc_sideIsFriendly) then {_damage = 0};
	_damage
}]; 

However, if ACE is present, it'll interfere with the above code.

Share this post


Link to post
Share on other sites

BIKI EH handleDamage:

Multiple "HandleDamage" event handlers can be added to the same unit. If multiple EHs return damage value for custom damage handling, only last returned value will be considered by the engine. EHs that do not return value can be safely added after EHs that do return value.

The problem is that you don't know which code will end as the last one, so which code will return its value.

But.. you can try to challenge with these modded EHs by a short script. Not saying it works with all EHs. But, that works and worth the test:

 

0 = this addEventHandler ["handleDamage",{
  params ["_target", "", "_damage", "", "", "", "_instigator"];
  [_target,_instigator] spawn {
    params ["_target","_instigator"];
    if (side _instigator getfriend side _target >= 0.6) then {
      _target allowDamage false;  
      hint "friendly fire for nuts";
      uisleep 0.5;
      _target allowDamage true;
    } else {
      hint "mortal now";
     _target allowDamage true;
    };
  };
  _damage
}];

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

The problem is that you don't know which code will end as the last one, so which code will return its value.

 

 


0 = this addEventHandler ["handleDamage",{
  params ["_target", "", "_damage", "", "", "", "_instigator"];
  [_target,_instigator] spawn {
    params ["_target","_instigator"];
    if (side _instigator getfriend side _target >= 0.6) then {
      _target allowDamage false;  
      hint "friendly fire for nuts";
      uisleep 0.5;
      _target allowDamage true;
    } else {
      hint "mortal now";
     _target allowDamage true;
    };
  };
  _damage
}];

 

 

 

Eventhandlers return an ID, which increases with each EH of the same type that has been added.

You can track that, if you don't 0 = everything, heh.

 

Simply put, save the EH ID on the object, then when appropriate add another "test" EH of the same type, if the returned ID is yours +1 remove the "test" EH and your last EH should still be the valid one.

Bit wonky but can't think of a better solution, since there's no EH for EH addition/removal, might be handy.

 

Cheers

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 11/25/2019 at 12:11 AM, Leopard20 said:

Is it possible to somehow remove an event handler temporarily? As in removing the EH but saving its code for later use?

not in a generic manner no.

If you know you are removing the ACE eh, you can just look up ace source for where the EH was added, and do the same thing again to re-add it later. But you'd need to do that manually for every mod.

  • Thanks 1

Share this post


Link to post
Share on other sites
5 hours ago, pierremgi said:

The problem is that you don't know which code will end as the last one, so which code will return its value.

But.. you can try to challenge with these modded EHs by a short script.

I guess I should add the event handler some time after the unit was created.

 

1 hour ago, Grumpy Old Man said:

Simply put, save the EH ID on the object, then when appropriate add another "test" EH of the same type, if the returned ID is yours +1 remove the "test" EH and your last EH should still be the valid one.

Bit wonky but can't think of a better solution, since there's no EH for EH addition/removal, might be handy.

Great idea! Thank you!

 

38 minutes ago, Dedmen said:

not in a generic manner no.

If you know you are removing the ACE eh, you can just look up ace source for where the EH was added, and do the same thing again to re-add it later. But you'd need to do that manually for every mod.

There's also the hassle of keeping my code updated with the source!

 

Thanks for the replies guys!

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

×