Skip to content

Commit

Permalink
Improve score changes logging (#98)
Browse files Browse the repository at this point in the history
* Log score changes

* Fix log macro

* Log score change reason if available
  • Loading branch information
3Mydlo3 authored Apr 8, 2024
1 parent 68e6b98 commit cbc2700
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
1 change: 1 addition & 0 deletions addons/score/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREP(addKillersScore);
PREP(addPoliceScore);
PREP(changeScore);
PREP(endMissionClient);
PREP(endMissionServer);
PREP(monitorTimeLimit);
Expand Down
10 changes: 1 addition & 9 deletions addons/score/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions addons/score/functions/fnc_addKillersScore.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions addons/score/functions/fnc_changeScore.sqf
Original file line number Diff line number Diff line change
@@ -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 <SIDE>
* 1: Score change <NUMBER>
* 2: Reason <STRING> (Optional)
*
* Return Value:
* 0: New score <NUMBER>
*
* 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

0 comments on commit cbc2700

Please sign in to comment.