Tory Xiao 5 Posted May 13, 2022 I'm trying to add hitmarkers to my escape mission, but there are so many scripts that handle spawning AI infantry units, so I'll have to search every creatUnit and add _unit addMPEventHandler ["MPHit",{call Eventhandler_fnc_MPHit}]; after it. Is there any way to add eventhandler once for all of them? Share this post Link to post Share on other sites
dreadedentity 278 Posted May 13, 2022 There is some wasted performance with this due to previous design choices but you can run a repeating loop over allUnits and set the event handler from 1 computer (server is probably best). Check against an object variable (get/setVariable) whether to add event handler or not. Adding MP event handler is already global so no need for remoteExec 2 Share this post Link to post Share on other sites
RCA3 581 Posted May 15, 2022 On 5/13/2022 at 1:42 AM, Tory Xiao said: Is there any way to add eventhandler once for all of them? If you have CBA_A3 you can run this on initServer.sqf: ["CAManBase", "init", { (_this # 0) addMPEventHandler ["MPHit",{call Eventhandler_fnc_MPHit}]; }, true, [], true] call CBA_fnc_addClassEventHandler; 1 Share this post Link to post Share on other sites
pierremgi 4739 Posted May 15, 2022 In initServer.sqf [] spawn { while {true} do { { _x setVariable [MPhitPassed",TRUE]; _x addMPEventHandler ["MPHit",{call Eventhandler_fnc_MPHit}]; // not sure calling this fnc will work as is but it's another problem } forEach (allUnits select {isNil {_x getvariable "MPhitPassed"}}); sleep 1; }; }; 1 Share this post Link to post Share on other sites
NunesSergio 17 Posted May 20, 2022 The way I did it was, upon initPlayerLocal.sqf I remotely add an Score event handler on server which, based on the value of the score, remotely fires my hitmarker function back on player machine: //initPlayerLocal.sqf params ["_player", "_didJIP"]; [_player, "configScore.sqf"] remoteExec ["execVM", 2]; //configScore.sqf params ["_player"]; _player addEventHandler ["HandleScore", { params ["_unit", "_object", "_score"]; //Score == 1 means you killed one soldier enemy unit (be it in or out of a vehicle) if (_score isEqualTo 1) then { ["hitMarkerAnimation.sqf"] remoteExec ["execVM", _unit]; }; }]; Keep in mind that if your mission has respawn of players, you'd have to re-assign the Score event handler to the respawned unit. So repeat the initPlayerLocal.sqf lines on onPlayerRespawn.sqf (changing _player for _newUnit): //onPlayerRespawn.sqf params ["_newUnit", "_oldUnit", "_respawn", "_respawnDelay"]; [_newUnit, "configScore.sqf"] remoteExec ["execVM", 2]; Whenever you kill an enemy unit, wherever it's spawned from, or how it was handled by scripts, you get your hitmarker and are free from tracking enemy unit creation process. 1 Share this post Link to post Share on other sites
Tory Xiao 5 Posted May 21, 2022 4 hours ago, NunesSergio said: The way I did it was, upon initPlayerLocal.sqf I remotely add an Score event handler on server which, based on the value of the score, remotely fires my hitmarker function back on player machine: //initPlayerLocal.sqf params ["_player", "_didJIP"]; [_player, "configScore.sqf"] remoteExec ["execVM", 2]; //configScore.sqf params ["_player"]; _player addEventHandler ["HandleScore", { params ["_unit", "_object", "_score"]; //Score == 1 means you killed one soldier enemy unit (be it in or out of a vehicle) if (_score isEqualTo 1) then { ["hitMarkerAnimation.sqf"] remoteExec ["execVM", _unit]; }; }]; Keep in mind that if your mission has respawn of players, you'd have to re-assign the Score event handler to the respawned unit. So repeat the initPlayerLocal.sqf lines on onPlayerRespawn.sqf (changing _player for _newUnit): //onPlayerRespawn.sqf params ["_newUnit", "_oldUnit", "_respawn", "_respawnDelay"]; [_newUnit, "configScore.sqf"] remoteExec ["execVM", 2]; Whenever you kill an enemy unit, wherever it's spawned from, or how it was handled by scripts, you get your hitmarker and are free from tracking enemy unit creation process. No respawn for players. In my mission once a player is down he became invincible, and respawn button is disabled, he can only wait for teammates to revive or rejoin the server Thanks a lot! I'll try the script Share this post Link to post Share on other sites