From e55c9a0751f4d0c8701c749bec132b9cc5dc3a5f Mon Sep 17 00:00:00 2001 From: IndigoFox Date: Tue, 13 Feb 2024 20:50:09 -0800 Subject: [PATCH] trial implementation --- framework/CfgFunctions.hpp | 1 + framework/client/functions/fn_bindEventHandlers.sqf | 11 ++++++++++- .../client/functions/fn_bindUnconsciousListener.sqf | 13 +++++++++++++ framework/client/functions/fn_initClient.sqf | 3 +++ .../init/functions/fn_addRespawnChatHandler.sqf | 12 +++++++++++- 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 framework/client/functions/fn_bindUnconsciousListener.sqf diff --git a/framework/CfgFunctions.hpp b/framework/CfgFunctions.hpp index 48fee2b..59f53f9 100644 --- a/framework/CfgFunctions.hpp +++ b/framework/CfgFunctions.hpp @@ -28,6 +28,7 @@ class DOUBLES(PREFIX,client) { class addZenModules {}; class bindEmptyGroupGarbageCleanup {}; class bindEventHandlers {}; + class bindUnconsciousListener {}; class bindVehicleActions {}; }; }; diff --git a/framework/client/functions/fn_bindEventHandlers.sqf b/framework/client/functions/fn_bindEventHandlers.sqf index 802c2c5..61948d2 100644 --- a/framework/client/functions/fn_bindEventHandlers.sqf +++ b/framework/client/functions/fn_bindEventHandlers.sqf @@ -7,11 +7,20 @@ player addEventHandler["Respawn", params ["_unit", "_corpse"]; private _killer = _corpse getVariable ["ace_medical_causeOfDeath", "#scripted"]; if (_killer == "respawn_button") then { + private _timeWentUnconscious = _unit getVariable [QGVARMAIN(lastTimeKnockedOut), -1]; + private _durationSpentUnconscious = diag_tickTime - _timeWentUnconscious; [ LEVEL_INFO, QUOTE(COMPONENT), "RESPAWNED WHILE UNCONSCIOUS", - [_unit] call EFUNC(common,addPlayerInfoToArray) + [_unit, [[ + "durationSpentUnconscious", + (if (_timeWentUnconscious > - 1) then { + _durationSpentUnconscious + } else { + -1 + }) + ]]] call EFUNC(common,addPlayerInfoToArray) ] remoteExec [QEFUNC(common,log), 2]; // format["%1 was unconscious then clicked the respawn button", name _unit] remoteExec["systemChat", 0]; }; diff --git a/framework/client/functions/fn_bindUnconsciousListener.sqf b/framework/client/functions/fn_bindUnconsciousListener.sqf new file mode 100644 index 0000000..f2bfb4b --- /dev/null +++ b/framework/client/functions/fn_bindUnconsciousListener.sqf @@ -0,0 +1,13 @@ +#include "..\script_component.hpp" + +if (!hasInterface) exitWith {}; + +["ace_medical_knockOut", { // local event that's also used directly by the ACE medical statemachine + private _unit = _this; + _this setVariable [QGVARMAIN(lastTimeKnockedOut), diag_tickTime]; +}] call CBA_fnc_addEventHandler; + +["ace_medical_WakeUp", { // local event that's also used directly by the ACE medical statemachine + private _unit = _this; + _this setVariable [QGVARMAIN(lastTimeKnockedOut), nil]; +}] call CBA_fnc_addEventHandler; \ No newline at end of file diff --git a/framework/client/functions/fn_initClient.sqf b/framework/client/functions/fn_initClient.sqf index f3d8fac..37e12aa 100644 --- a/framework/client/functions/fn_initClient.sqf +++ b/framework/client/functions/fn_initClient.sqf @@ -9,6 +9,9 @@ call FUNC(bindEmptyGroupGarbageCleanup); call FUNC(bindEventHandlers); call FUNC(bindVehicleActions); +// add listener that tracks when the player goes unconscious and saves a variable with time +call FUNC(bindUnconsciousListener); + [ LEVEL_DEBUG, QUOTE(COMPONENT), diff --git a/framework/init/functions/fn_addRespawnChatHandler.sqf b/framework/init/functions/fn_addRespawnChatHandler.sqf index 3a08fbf..ad7dd7c 100644 --- a/framework/init/functions/fn_addRespawnChatHandler.sqf +++ b/framework/init/functions/fn_addRespawnChatHandler.sqf @@ -8,12 +8,22 @@ if (!hasInterface) exitWith {}; _clientID = _thisArgs select 0; player setDamage 1; + private _timeWentUnconscious = player getVariable [QGVARMAIN(lastTimeKnockedOut), -1]; + private _durationSpentUnconscious = diag_tickTime - _timeWentUnconscious; + // log to server RPT [ LEVEL_INFO, QUOTE(COMPONENT), "CHAT COMMAND RESPAWN", - [player] call EFUNC(common,addPlayerInfoToArray) + [player, [[ + "durationSpentUnconscious", + (if (_timeWentUnconscious > - 1) then { + _durationSpentUnconscious + } else { + -1 + }) + ]]] call EFUNC(common,addPlayerInfoToArray) ] remoteExec [QEFUNC(common,log), 2]; // systemChat to all remote machines