Jump to content
Sign in to follow this  
phronk

Remove EHs from dead unit?

Recommended Posts

Quick question:

Is it necessary to remove eventHandlers from units that are killed upon death? I'm working on a large insurgency mission which will have quite a bit of AI active at a time, each AI unit with eventHandlers.

For example:

_badMan addEventHandler["Killed",{(_this select 1)addRating 2000;(_this select 0)removeAllEventHandlers "Killed";}];};

Do the EHs get automatically removed when the units are dead, whether it be a killed EH or not, or do they need to be removed? I'm asking from an optimization standpoint. Would it help memory, for example?

Share this post


Link to post
Share on other sites

If you delete unit, all EHs will be removed with it. If you are not deleting, some of the EH will continue to operate, like for example HandleDamage even if unit is dead. Killed EH will obviously not fire again because unit will be dead. Some event handlers will not fire after unit is dead but will still be checked. So it is better to remove all event handlers on killed event to be sure.

Share this post


Link to post
Share on other sites

You could introduce some bugs doing by removing all EHs (e.g mods). I'd suggest just checking if the unit is alive before doing anything.

Share this post


Link to post
Share on other sites

So is it plausably more optimized to give all spawned AI a killed EH like this:
 

_badMan addEventHandler["Killed",{
(_this select 1)addRating 2000;(_this select 0)removeAllEventHandlers "Killed";(_this select 0)removeAllEventHandlers "AnimChanged";(_this select 0)removeAllEventHandlers "HandleDamage";}];
};

  • Like 1

Share this post


Link to post
Share on other sites

So is it plausably more optimized to give all spawned AI a killed EH like this:

 

_badMan addEventHandler["Killed",{

(_this select 1)addRating 2000;(_this select 0)removeAllEventHandlers "Killed";(_this select 0)removeAllEventHandlers "AnimChanged";(_this select 0)removeAllEventHandlers "HandleDamage";}];

};

 

I would say remove only EHs you added as cuel pointed out, there could be mods using own EHs, but then there could be bad mods that wont do cleanup too. Also https://community.bistudio.com/wiki/addRating has to be executed where killer is local and it most probably will not be where Killed is executed.

Share this post


Link to post
Share on other sites

Thanks for the help.  Had no idea rating was local...

 

While I'm asking questions, does anyone know how to remoteExec a simple hint parseText format ["I'm here: %1",mapGridPosition player]; command?  I'm still new to remoteExec.

Share this post


Link to post
Share on other sites

Try this one:

format ["I'm here: %1",mapGridPosition player] remoteExec ["hint"];
  • Like 1

Share this post


Link to post
Share on other sites

format parseText ["I'm here: %1",mapGridPosition player] remoteExec ["hint"];

​Also works, thanks a lot fellas!

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

×