Jump to content
mathiasstahle

Quick eventhandler question

Recommended Posts

Where's the proper place to initiate an eventHandler "Fired" in a multiplayer mission? In the playable units init field? In init.sqf? 

The eventHandler will execute a scripting command and I want it to fire on all machines, regardles of which player triggers it. In this case all playable units belong to the same group and start the game seated in the same vehicle, if that matters.

Share this post


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

which eh?

Yes. English isn't my native language.

Share this post


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

Where's the proper place to initiate an eventHandler "Fired" in a multiplayer mission? In the playable units init field? In init.sqf? 

The eventHandler will execute a scripting command and I want it to fire on all machines regardles of wich player triggers it. In this case all playable units belong to the same group and start the game seated in the same vehicle, if that matters.

 

The EH "fired" is usually placed in init.sqf or initPlayerLocal.sqf , sometimes directly in init field of the unit(s)...

That depends on what you want to run with that, for which unit(s) or player(s)

So, the probable correct answer is : initPlayerLocal.sqf if I guess what you want.

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Fired

 

Quote

Special multiplayer behaviour: When added to a remote unit or vehicle, this EH will only fire if said entity is within range of the camera. That range is determined by the fired ammo's highest visibleFire and audibleFire config value. In case of units, muzzle attachment coefficients are applied too.

 

So attach the EH to the desired unit in whatever way you wish, then remoteExec any commands from there.

HARZ_fired_mult = 0;
this addEventHandler ["Fired", {
	params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];
	HARZ_fired_mult = HARZ_fired_mult + 1;
	format ["%1 has fired their %2 %3 time(s)", _unit, _weapon, HARZ_fired_mult] remoteExec ["hint", 0];
}];

This example only works when attached to one specific unit, but that's because of the output I chose.

Share this post


Link to post
Share on other sites

I ended up placing it in the init field of every playable unit and it seems to work fine for this mission. It's an eventhandler that moves a marker and an invisible helipad to the players position if he throws an orange smoke grenade. Rather simple commands with global effects. And since all players belong to the same group and share a vehicle upon mission start no locality issues seems to be at hand. Tested it in hosted MP yesterday. Dedicated servers are another issue, but for me it's enough if it works in hosted environment atm. Thanks for the help.

Share this post


Link to post
Share on other sites
On 8/22/2022 at 11:19 AM, mathiasstahle said:

I ended up placing it in the init field of every playable unit

Just do it in the initPlayerLocal.sqf. There is no need for each client to add the event to each other clients as well as their own. This is what will happen if it's placed in the units init in the editor.

  • Thanks 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

×