Jump to content

Recommended Posts

Hi,

I'm still looking for the best way to manage some revive heal in SP and MP session. SP works fine but I can't find a reliable solution for MP, with the EH handleDamage.

 

Restarting from the basement, I'd like to share this test I can't explain the result:

 

I placed 2 playable groups in editor.

and 1 trigger (true) to run this code:


 

{_x addEventHandler ["handleDamage", {
    params ["_unit","","_dam"];
       hint str (getAllHitPointsDamage _unit);
       _dam min 0.86
  }];
  } forEach allunits;

 

This code is running on each hosted/clients.

The EH is supposed to limit all the hits at 0.86 max. This way the unit is wounded but never die (OK in SP or units on hosted server).

PS: I know, I can write  the hint inside of a loop rather than inside of the EH, but that doesn't change anything for the following issue:

 

If I JIP on the 2nd group leader, so the group will be remote to the client's PC. The group owner changes. Normal.

Then if I continue to fire against these remote units, the EH still fires (I can see the new value for getAllHitPointsDamage), so the hint is "ok" then the EH code runs but the remote units die!

- I can shoot the units of my group: they never die,

- all remote units are dying...

 

Everything goes as the EH fires locally (normal: E.L.) but this localization is not updated to the new localization of the unit!

This EH is hard to manage, even for so small behavior as modifying a value for hit damage.

I miss something, probably. Any help appreciated. Thanks.

  • Like 2

Share this post


Link to post
Share on other sites

The biki says

 

Quote

command: Code or String - code that should be executed once the event occurs, by default executed in missionNamespace

 

Share this post


Link to post
Share on other sites

And?

I'm not talking about the fact the hint is late because run inside the EH itself. I'm speaking about the loss of the behavior (limited damage making unit invulnerable) when the owner changes.

Did you test it, running the EH in MP hosted/client?

 

It seems I had to restart my Arma session on both PCs. No clue why.

Arrffff, I discovered a if (isServer) condition somewhere in my more complex code, so this EH was applied to all units but only on server...

In fact the BIKI notices that this EH is AG... Arguments don't have to be local...

It's more than that: EH must be run everywhere!

I change the title of the thread.

 

PS: there is one possibility to make the local code run at the right place (and not fail). I'm not sure you save something in term of server/client workload.


 

MGI_fn_EHDamage = {
  params ["_unit"];
  _unit addEventHandler ["handleDamage", {
    params ["_unit","","_dam"];
    if (local _unit) then {
       hint str [getAllHitPointsDamage _unit,local _unit]; // just a hint to check where the EH fires, don't be formal with the late info
       _dam min 0.86    //   or any code you need
    } else {
       _unit removeEventHandler ["handleDamage",_thisEventHandler];
       [_unit] remoteExec ["MGI_fn_EHDamage",_unit]
    };
  }];
};

if (isServer) then {{_x call MGI_fn_EHDamage} forEach allUnits};

This way, all AI units managed by server (leader not client player) can run a code on server only. That was my initial attempt. Not sure that's worth it.
remaining problem: you need to remove an EH to create another one, there is a blank "hit" while the AI can die if mortal.

Thanks for comments about performance.

 

  • Like 2

Share this post


Link to post
Share on other sites

Hello Pierre !

 

Is there any news about it ?

 

I 'm creating a revive script and i faced in the MP the same problem , failing to work and as i was searching i came up with this:

( Not so much tested , but i haven't notice any problem )

GF_EH_handleDamage_test = {

	params ["_unit"];
  
	_unit addEventHandler ["handleDamage", {
		params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"];
		
		_selection = _this select 2;
		
		systemchat format ["%1",damage _unit];
		
		if (local _unit) then {
			if (damage _unit + _selection >= 1) then {
				_damage = 0.99;
				hint format ["handle %1",typeOf _unit];
				_damage;
			};
		} else {
       _unit removeEventHandler ["handleDamage",_thisEventHandler];
       [_unit] remoteExec ["GF_EH_handleDamage_test",_unit]
    };
}];

};

if (isServer) then {{_x spawn GF_EH_handleDamage_test} forEach allUnits};

I've added also the remoteExec.

 

I wanted also to ask : _thisEventHandler

why there is this and it's not defined somewhere.

Is it correct ?

 _unit removeEventHandler ["handleDamage",_thisEventHandler];

Thanks !

Share this post


Link to post
Share on other sites

Yes, I don't have better explanation about that.

For _thisEventHandler, I tried to follow BIKI:

Since Arma 3 v.1.63.137807 the EH handle is also stored in _thisEventHandler variable and is available during EH code execution.

 

Finally, run the EH everywhere, not server only,

apply if (local..) condition for all codes with arguments_local.gif

but, return a value for everyone.

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

So let me get this right. The locality of the unit the EH is added to might change, but the EH doesn't change with it and so you're saying you have to run the EH everywhere?

Share this post


Link to post
Share on other sites

 

3 minutes ago, Tankbuster said:

So let me get this right. The locality of the unit the EH is added to might change, but the EH doesn't change with it and so you're saying you have to run the EH everywhere?

No, I don't say that. Just test the light scenario of my first post.

And, if you have time, while you're at it: https://forums.bohemia.net/forums/topic/205515-handledamage-event-handler-explained/?do=findComment&comment=3346171

 

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

×