Jump to content
Sign in to follow this  
Faron

[SOLVED] Make local EventHandler global

Recommended Posts

Dear Community,

 

I'm trying to trigger an effect for a vehicle when it's hit by a flare (kind of a superman EMP flare). The only function that triggers when a vehicle is hit by a flare is the "HitPart" eventhandler. Unfortunely this only works local, but I'd really like the engine to break for every client! I already tried adding the following lines in the function that spawns the vehicle:

[[_vehicle, {_this addEventHandler ["HitPart", {_this call life_fnc_handleVehDamage}]}], "BIS_fnc_spawn", true, true] spawn BIS_fnc_MP;
[[_vehicle, {_this addEventHandler ["HitPart", {_this call life_fnc_handleVehDamage}]}], "BIS_fnc_call", true, true] call BIS_fnc_MP;

Created a file that adds the eventhandler:

[[_vehicle], "life_fnc_addVehEH", true, true, false] call BIS_fnc_MP;
[_vehicle] remoteExec ["life_fnc_addVehEH", 0, true];

Neither client log nor server log are showing any errors.

 

 

None of these does work...

Do you have any suggestions or see any mistakes? I'd appreciate it!

 

Cheers,

Faron

  • Thanks 1

Share this post


Link to post
Share on other sites

Hi, give it a try with remoteExec :

[_vehicle, ["HitPart", {_this call life_fnc_handleVehDamage}]] remoteExec ["addEventHandler", 0, true];

 

  • Thanks 1

Share this post


Link to post
Share on other sites
[_vehicle] remoteExec ["life_fnc_addVehEH", 0, true];

For me looks like the function isn't global. Make sure it is.

Edited by davidoss
  • Thanks 1

Share this post


Link to post
Share on other sites

It shouldn't matter since the function is remoteExec'd on all machines?

Share this post


Link to post
Share on other sites

Not function , its executions only..

 

Quote

Validity verification

Validity of remote execution request is verified in 2 steps: when the request is initiated (issued from a client machine) when the server is going to broadcast the request. If the request is initialized directly from the server, step 1 is skipped (this applies for hosted server admins as well).

For a remote execution request to be valid following criteria need to be met:

  1. input parameters must be properly defined
  2. function/command must exist on the machine
  3. function/command remote execution request must be allowed in CfgRemoteExec
    • remote execution must be either fully open (mode=2)
    • or the particular function/command must be whitelisted
  4. if JIP is used (isPersistent flag is not false), JIP must be allowed in CfgRemoteExec (jip=1)

If any of the aforementioned is not met remote execution is blocked.

 

Or i am understanding this wrong..

Share this post


Link to post
Share on other sites
13 hours ago, davidoss said:

Not function , its executions only..

 

 

Or i am understanding this wrong..

The function is meeting all criteria, as it only param is _vehicle wich is being created right before. The function is whitelisted and JIP is on. And it does exist in all clients mission folder.

 

@haleks I'll give it a try, but is it even possible to hand the arguments to the eventhandler right in front of the addEventHandler? Or does remoteExec allow this?

Share this post


Link to post
Share on other sites

The syntax you use with remoteExec will depend on the syntax of the script/function you want, sometimes it does look weird when you're not used to it. ^^

Share this post


Link to post
Share on other sites

Might this cause the problem?

 

While you can add "HitPart" handler to a remote unit, the respectful addEventHandler command must be executed on the shooter's PC and will only fire on shooter's PC as well. The event will not fire if the shooter is not local, even if the target itself is local. Additionally, if the unit gets damaged by any means other than shooter's shooting, "HitPart" will not fire. 

 

Because that's actually what I wanted to work around...

Share this post


Link to post
Share on other sites

I'm probably a bit fuzzy since I didn't get any sleep today, but the example I posted above should take care of that : it broadcasts the EH to all machines, so you don't really need to worry about locality - the EH will fire on the shooter's machine and trigger your global function.

Did you actually try it?

Share this post


Link to post
Share on other sites
55 minutes ago, haleks said:

I'm probably a bit fuzzy since I didn't get any sleep today, but the example I posted above should take care of that : it broadcasts the EH to all machines, so you don't really need to worry about locality - the EH will fire on the shooter's machine and trigger your global function.

Did you actually try it?

I just wanted to copy paste but your post is gone...

 

EDIT: Ah no I just found it.... I'm a bit fuzzy as well ;)

I'll just be able to try it later.

Share this post


Link to post
Share on other sites

yea the hitpart EH is weird like that, unfortunately.

 

would probably make more sense to run the function inside it remote.

 

since no matter where the EH has been assigned it will always only fire on the shooter. it's been a while since i messed with it though. probably best to get a buddy and test it in an empty MP session.

Share this post


Link to post
Share on other sites
21 minutes ago, bad benson said:

since no matter where the EH has been assigned it will always only fire on the shooter.

 

That's not how I understand the wiki description : the shooter has to be local, in other words the addEventHandler must have been run on his machine.

So you do need to remoteExec the EH addition on all clients - but yeah now that I think of it, the function called by the EH might need to be broadcasted too, depends on what it actually does I guess...

Share this post


Link to post
Share on other sites

what you quoted there is how it works.

 

i'm wondering, if the EH exists where the victim is local (lets say the server) and where the shooter is local (lets say the client), wouldn't that cause the event to be triggered twice? (nope since it only ever fires on the shooter IF he has the EH assigned to the shot vehicle on his machine)

 

EDIT:

nvm. i missed this part

Quote

The event will not fire if the shooter is not local

 

looks like i'm besting you all in fuzziness.....

 

Quote

but yeah now that I think of it, the function called by the EH might need to be broadcasted too, depends on what it actually does I guess...

 

yea he mentioned an effect so i was thinking particles which can always cause problems in MP but info is not provided so my brainfarts can be ignored.

Share this post


Link to post
Share on other sites
6 hours ago, haleks said:

 

That's not how I understand the wiki description : the shooter has to be local, in other words the addEventHandler must have been run on his machine.

So you do need to remoteExec the EH addition on all clients - but yeah now that I think of it, the function called by the EH might need to be broadcasted too, depends on what it actually does I guess...

I'd think that it would be enough to broadcast the EH on all clients as it's triggered to ALL clients when the vehicle is being hit. So broadcasting the function would trigger it twice.

Share this post


Link to post
Share on other sites

i know i have caused confusion already. but i feel it highly depends on who you want to be able to see the effect and what commands and functionality the effect function actually uses.

 

3 hours ago, Faron said:

I'd think that it would be enough to broadcast the EH on all clients as it's triggered to ALL clients (i don't think this is true) when the vehicle is being hit. So broadcasting the function would trigger it twice.

 

i'm still not sure if this is actually true. read again the underlined sections.

 

Quote

While you can add "HitPart" handler to a remote unit, the respectful addEventHandler command must be executed on the shooter's PC and will only fire on shooter's PC as well. The event will not fire if the shooter is not local, even if the target itself is local. Additionally, if the unit gets damaged by any means other than shooter's shooting, "HitPart" will not fire. 

 

so the EH must be added on the shooters machine (no matter to what vehicle), right, but then will also only fire there.

 

i'm still trying to grasp this whole issue myself but i feel it's not 100% cleared out yet.

 

let's say...

 

- client A and client B both have their local EH on the same vehicle C (achieved through remoteExec addeventhandler).

 

- client A is shooting the vehicle C.

 

as far as i understand the above text, no matter what, the actual event will only fire on client A's machine and not client B's machine (eventhough he has the EH on vehicle C) since he is NOT the shooter.

 

i don't get why else the emphasis would be on the actual "shooter" in several places in the text.

 

but maybe i just need to get some sleep.

 

 

EDIT: note that this specific EH is very unique in its limitations. if you only ever want the actual shooter to see things, then you're good.

Share this post


Link to post
Share on other sites

BLAME ON MY FUZZY HEAD!!! Jip was disabled...

Share this post


Link to post
Share on other sites

@haleks @davidoss @bad benson So a little update:

[_vehicle, ["HitPart", {_this remoteExec ["life_fnc_handleVehDamage", 0, true]}]] remoteExec ["addEventHandler", 0, true];

This code works fine as long as it's local, but I didn't test it with another guy yet. I also tried to apply this in my @life_server when a vehicle spawns (from the altis life framework), but this doesn't work. So it seems like remote execution still doesn't work completely as it should, but I'll test it and update this post when I know more!

 

EDIT: Code works global if the spawning vehicle function is executed in the mission file, but doesn't work at all if written in the script in life server that spawns the vehicle. I'm really confused...

  • Like 1

Share this post


Link to post
Share on other sites

Hard to say without seeing the script, but what's wrong with running it from the mission?

Share this post


Link to post
Share on other sites
3 minutes ago, haleks said:

Hard to say without seeing the script, but what's wrong with running it from the mission?

It's working completely fine from the mission. But to apply the EH to all vehicles I also have to add it to the spawn script for unparking vehicles, wich is located in the life_server addon.

Share this post


Link to post
Share on other sites

@Jawshy I'm not trying to bother you, but you probably know more about how the life_server works. I added the following to the life_server/functions/systems/fn_vehicleCreate

[_vehicle, ["HitPart", {_this remoteExec ["life_fnc_handleVehDamage", 0, true]}]] remoteExec ["addEventHandler", 0, true];

This isn't being executed (the EH doesn't trigger) and I can't see a reason why, as there are no errors messages showing up. Any ideas/suggestions?

Share this post


Link to post
Share on other sites

for remoteExec there is a CfgRemoteExec that defines which functions are allowed to be broadcasted. o personally don't do stuff with it because i play mostly with friends so security is not a concern but since you are working with a given mod that is made for public serve (i'm guessing), this might be your issue.

 

i'm not sure if this will bypass that but try it more generic like this

 

[_vehilce,
{
	_this addEventHandler ["HitPart",
	{
		[_this,
		{
			_this call your_fnc_function;
		}] remoteExec ["call", 0, false];
	}];
}] remoteExec ["call", 0, true];

 

i don't know if "call" is blocked by default too. but try it like this just for testing.

 

 

or of course do proper whitelisting in CfgRemoteExec

Share this post


Link to post
Share on other sites
2 hours ago, bad benson said:

for remoteExec there is a CfgRemoteExec that defines which functions are allowed to be broadcasted. o personally don't do stuff with it because i play mostly with friends so security is not a concern but since you are working with a given mod that is made for public serve (i'm guessing), this might be your issue.

 

i'm not sure if this will bypass that but try it more generic like this

 


[_vehilce,
{
	_this addEventHandler ["HitPart",
	{
		[_this,
		{
			_this call your_fnc_function;
		}] remoteExec ["call", 0, false];
	}];
}] remoteExec ["call", 0, true];

 

i don't know if "call" is blocked by default too. but try it like this just for testing.

 

 

or of course do proper whitelisting in CfgRemoteExec

Could adding another CfgRemoteExec solve the problem as well?

Share this post


Link to post
Share on other sites
7 hours ago, Faron said:

Could adding another CfgRemoteExec solve the problem as well?

 

Have you tried it yourself?

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  

×