From cbc27007cc915d5bb771854e5503abd6ac5c4f60 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Tue, 9 Apr 2024 00:37:36 +0200 Subject: [PATCH] Improve score changes logging (#98) * Log score changes * Fix log macro * Log score change reason if available --- addons/score/XEH_PREP.hpp | 1 + addons/score/XEH_postInit.sqf | 10 +---- .../score/functions/fnc_addKillersScore.sqf | 1 + addons/score/functions/fnc_changeScore.sqf | 40 +++++++++++++++++++ 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 addons/score/functions/fnc_changeScore.sqf diff --git a/addons/score/XEH_PREP.hpp b/addons/score/XEH_PREP.hpp index ffd2aece..07d4c422 100644 --- a/addons/score/XEH_PREP.hpp +++ b/addons/score/XEH_PREP.hpp @@ -1,5 +1,6 @@ PREP(addKillersScore); PREP(addPoliceScore); +PREP(changeScore); PREP(endMissionClient); PREP(endMissionServer); PREP(monitorTimeLimit); diff --git a/addons/score/XEH_postInit.sqf b/addons/score/XEH_postInit.sqf index 41687e2d..61c2eda4 100644 --- a/addons/score/XEH_postInit.sqf +++ b/addons/score/XEH_postInit.sqf @@ -23,15 +23,7 @@ if (isServer) then { [QGVAR(endMission), [KILLERS_SCORE_REACHED]] call CBA_fnc_globalEvent; }] call CBA_fnc_addEventHandler; - [QGVAR(changeScore), { - params ["_side", "_change", ["_reason", ""]]; - if (_side isEqualTo WEST) then { - [_change, _reason] call FUNC(addPoliceScore); - } else { - [_change, _reason] call FUNC(addKillersScore); - }; - [QGVAR(scoreChanged), _this] call CBA_fnc_globalEvent; - }] call CBA_fnc_addEventHandler; + [QGVAR(changeScore), FUNC(changeScore)] call CBA_fnc_addEventHandler; /* Serverside score logic init */ // Idle timeout init diff --git a/addons/score/functions/fnc_addKillersScore.sqf b/addons/score/functions/fnc_addKillersScore.sqf index 331b8f09..476ed4f0 100644 --- a/addons/score/functions/fnc_addKillersScore.sqf +++ b/addons/score/functions/fnc_addKillersScore.sqf @@ -33,6 +33,7 @@ publicVariable QGVAR(killersScoreChange); // Save change time GVAR(killersScoreLastChangeTime) = CBA_missionTime; +// Keep last score change for 5 seconds to "stack it" visually if many events occur in short succession. [{ if (GVAR(killersScoreChange) isEqualTo (_this select 0)) then { GVAR(killersScoreChange) = 0; diff --git a/addons/score/functions/fnc_changeScore.sqf b/addons/score/functions/fnc_changeScore.sqf new file mode 100644 index 00000000..e5e71a3b --- /dev/null +++ b/addons/score/functions/fnc_changeScore.sqf @@ -0,0 +1,40 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Function changes score for given side by given amount. + * + * Arguments: + * 0: Side which has score changed + * 1: Score change + * 2: Reason (Optional) + * + * Return Value: + * 0: New score + * + * Example: + * [WEST, 1] call afsk_score_fnc_changeScore + * + * Public: No + */ + +params ["_side", "_change", ["_reason", ""]]; + +private _previousScore = [_side] call FUNC(getSideScore); + +if (_side isEqualTo WEST) then { + [_change, _reason] call FUNC(addPoliceScore); +} else { + [_change, _reason] call FUNC(addKillersScore); +}; + +private _newScore = [_side] call FUNC(getSideScore); + +if (_reason isEqualTo "") then { + INFO_4("Changed score for %1: %2 + %3 = %4",_side,_previousScore,_change,_newScore); +} else { + INFO_5("Changed score for %1: %2 + %3 = %4, caused by %5",_side,_previousScore,_change,_newScore,_reason); +}; + +[QGVAR(scoreChanged), [_side, _change, _newScore, _reason]] call CBA_fnc_globalEvent; + +_newScore