Col. Ben Sherman 3 Posted March 3, 2018 Hi there, I've pretty much just got into headless client and I wonder if there is a way for event handlers to figure out that this guy killed this AI, I had this before and if they're spawned with Zeus they work just fine but when I use headless client it seems it doesn't track the kills. Below you can find how their setup so far. description.ext class Extended_Hit_EventHandlers { class CAManBase { hit = "_this call fnc_handleHit;"; }; }; class Extended_Killed_EventHandlers { class CAManBase { killed = "_this call fnc_handleKill;"; }; }; class Extended_FiredBIS_Eventhandlers { class CAManBase { fired = "_this call fnc_handleFired;"; }; }; class Extended_Respawn_Eventhandlers { class CAManBase { respawn = "_this call fnc_handleRespawn;"; }; }; fn_handleKill.sqf params ["_unit", ["_instigator", objNull], "_instigator"]; if ((isNull _instigator) || {_instigator == _unit}) then { private _aceSource = _unit getVariable ["ace_medical_lastDamageSource", objNull]; if ((!isNull _aceSource) && {_aceSource != _unit}) then { _instigator = _aceSource; }; }; if ((!isNull _instigator) && {!(_instigator isKindof "CAManBase")}) then { _instigator = effectiveCommander _instigator; }; if (_instigator == _unit) exitWith { _instigator setVariable ["deaths", (_instigator getVariable "deaths") + 1, true]; } else { _instigator setVariable ["kills", (_instigator getVariable "kills") + 1, true]; }; 1 Share this post Link to post Share on other sites
ezremake 13 Posted March 4, 2018 Move your fn_handleKill.sqf to the serverside, make a precompiled function out of it. When you create your ai units, attach the event handlers like this [_aiUnitHere,["killed", {[[_this,(_this select 1)],'FN_HandleKillFunctionHere',false,false] call BIS_fnc_MP}]] remoteExec ["addEventHandler",0,true]; Share this post Link to post Share on other sites
Col. Ben Sherman 3 Posted March 7, 2018 On 3/4/2018 at 6:35 AM, ezremake said: Move your fn_handleKill.sqf to the serverside, make a precompiled function out of it. When you create your ai units, attach the event handlers like this [_aiUnitHere,["killed", {[[_this,(_this select 1)],'FN_HandleKillFunctionHere',false,false] call BIS_fnc_MP}]] remoteExec ["addEventHandler",0,true]; You wouldn\t maybe know if there is a way to inject that as my AI's are dynamic, mostly through Zeus but CQB is managed through the ALiVE mod. Otherwise thanks for the help, not sure how I will do this as I use a mod to transfer the AI from Zeus to HC. Share this post Link to post Share on other sites
Col. Ben Sherman 3 Posted April 2, 2018 So I've kinda gone through this process and for some reason can't seem to get it to work completely especially since my entire mission is dynamic I wonder if there is a way for me to loop through NPC/AI in which I can assign a variable to them and assign the data at that point instead. Does anyone have any clue? Maybe something like this would work? (Code is just a concept, not sure if the spawn function keeps looping or not) [] spawn { if (!hasInterface) then { { if (local _x && (_x getVariable "handlersSet" == true || isNull _x getVariable "handlersSet")) then { [_x,["killed", {[[_this,(_this select 1)],'FN_HandleKillFunctionHere',false,false] call BIS_fnc_MP}]] remoteExec ["addEventHandler",0,true]; _x setVariable ["handlersSet", true, true]; }; } forEach allUnits; }; }; Share this post Link to post Share on other sites
computer 113 Posted April 3, 2018 I've been just using this to add to all units(run on all clients on init) ["CAManBase", "initPost", {_this call score_fnc_unitInit},true,[],true] call CBA_fnc_addClassEventHandler; Share this post Link to post Share on other sites
Col. Ben Sherman 3 Posted April 3, 2018 7 hours ago, computer said: I've been just using this to add to all units(run on all clients on init) ["CAManBase", "initPost", {_this call score_fnc_unitInit},true,[],true] call CBA_fnc_addClassEventHandler; Very good idea, never thought about that the problem I have now is that everything I add to the function that is being called through initPost is giving errors even a simple one such as diag_log format["Assigning Events to data: %1", name _this]; // Giving this error, Error in expression < format["Assigning Events to data: %1", name _this]; diag_log format["Assigning Events to data: %1", name player]; // Works but only outputs the HC and not the rest of the players/units spawned on the map Edit: Figured out the problem, the data transferred ended up in an array Share this post Link to post Share on other sites
Col. Ben Sherman 3 Posted April 3, 2018 Somehow I managed to get it to work, using CBA I managed to split the event handles both client and headless client. It seems silly but I got no clue why it didn't work before and adjusting it to this it works just fine. Old code (description.ext) class Extended_Hit_EventHandlers { class All { hit = "_this call alive_fnc_handleHit;"; }; }; class Extended_Killed_EventHandlers { class All { killed = "_this call alive_fnc_handleKill;"; }; }; class Extended_FiredBIS_Eventhandlers { class CAManBase { fired = "_this call alive_fnc_handleFired;"; }; }; class Extended_Respawn_Eventhandlers { class CAManBase { respawn = "_this call alive_fnc_handleRespawn;"; }; }; New code (initPlayerLocal.sqf) if !(hasInterface or isServer) then { ["All", "Hit", {_this call custom_fnc_handleHit;}] call CBA_fnc_addClassEventHandler; ["All", "Killed", {_this call custom_fnc_handleKill;}] call CBA_fnc_addClassEventHandler; } else { ["CAManBase", "Fired", {_this call custom_fnc_handleFired;}] call CBA_fnc_addClassEventHandler; ["CAManBase", "Respawn", {_this call custom_fnc_handleRespawn;}] call CBA_fnc_addClassEventHandler; }; Share this post Link to post Share on other sites