From c3fe10e04841ee97058e947feab0199a6d05e5e3 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Sat, 24 Feb 2024 12:20:30 +0100 Subject: [PATCH 1/6] Add settings for car alarm notifications --- addons/vehicles/XEH_PREP.hpp | 1 + addons/vehicles/XEH_postInit.sqf | 6 ++- .../functions/fnc_carAlarmNotification.sqf | 39 +++++++++++++++++++ addons/vehicles/initSettings.sqf | 22 +++++++++++ addons/vehicles/stringtable.xml | 28 +++++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 addons/vehicles/functions/fnc_carAlarmNotification.sqf diff --git a/addons/vehicles/XEH_PREP.hpp b/addons/vehicles/XEH_PREP.hpp index da527e3b..7c39e77d 100644 --- a/addons/vehicles/XEH_PREP.hpp +++ b/addons/vehicles/XEH_PREP.hpp @@ -1,5 +1,6 @@ PREP(carAlarm); PREP(carAlarmLoop); +PREP(carAlarmNotification); PREP(createVehicle); PREP(disableCarAlarm); PREP(initCarAlarm); diff --git a/addons/vehicles/XEH_postInit.sqf b/addons/vehicles/XEH_postInit.sqf index dad32fb1..51db079e 100644 --- a/addons/vehicles/XEH_postInit.sqf +++ b/addons/vehicles/XEH_postInit.sqf @@ -12,7 +12,11 @@ if (hasInterface) then { [QGVAR(alarmOff), { params ["_vehicle"]; - [QEGVAR(common,showSideChatMsg), [WEST, [_vehicle] call FUNC(vehicleStolenMsg)]] call CBA_fnc_localEvent; [_vehicle, true, GVAR(alarmDuration)] call FUNC(carAlarmLoop); + + // Delay notification + [{ + _this call FUNC(carAlarmNotification); + }, [_vehicle], GVAR(alarmCopsNotificationDelay)] call CBA_fnc_waitAndExecute; }] call CBA_fnc_addEventHandler; }; diff --git a/addons/vehicles/functions/fnc_carAlarmNotification.sqf b/addons/vehicles/functions/fnc_carAlarmNotification.sqf new file mode 100644 index 00000000..6f041b41 --- /dev/null +++ b/addons/vehicles/functions/fnc_carAlarmNotification.sqf @@ -0,0 +1,39 @@ +#include "script_component.hpp" +/* + * Author: 3Mydlo3 + * Displays notification of a car alarm according to configured settings. + * + * Arguments: + * 0: Vehicle which has alarm going off + * + * Return Value: + * None + * + * Example: + * None + * + * Public: No + */ + +params ["_vehicle"]; + +// No notification +if (GVAR(alarmCopsNotification isEqualTo 3)) exitWith {}; + +private _notify = if (GVAR(alarmCopsNotification) isEqualTo 1) then { + // Always notify + true +} else { + // Notify only if civilians nearby (alarmAudibleDistance/2 as no one would really care about an alarm far from him) + private _nearbyUnits = _vehicle nearEntities ["Man", GVAR(alarmAudibleDistance)/2]; + private _anyNearbyUnrestrainedCivilians = _nearbyUnits + findIf {alive _x && {side _x isEqualTo CIVILIAN} && {!([_x] call FUNC(jail,isHandcuffed))}} != -1; + + if (_anyNearbyUnrestrainedCivilians) then { true } else { false }; +}; + +if (_notify) then { + [QEGVAR(common,showSideChatMsg), [WEST, _this call FUNC(vehicleStolenMsg)]] call CBA_fnc_localEvent; +}; + +nil diff --git a/addons/vehicles/initSettings.sqf b/addons/vehicles/initSettings.sqf index b55c6de9..ee822c50 100644 --- a/addons/vehicles/initSettings.sqf +++ b/addons/vehicles/initSettings.sqf @@ -74,3 +74,25 @@ {}, true ] call CBA_fnc_addSetting; + +[ + QGVAR(alarmCopsNotification), + "LIST", + [LSTRING(AlarmCopsNotification), LSTRING(AlarmCopsNotification_Description)], + [LSTRING(DisplayName), LSTRING(CarAlarm)], + [[1, 2, 3], [LSTRING(Always), LSTRING(IfCiviliansNearby), LSTRING(Never)], 1], + true, + {}, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(alarmCopsNotificationDelay), + "SLIDER", + [LSTRING(AlarmCopsNotificationDelay), LSTRING(AlarmCopsNotificationDelay_Description)], + [LSTRING(DisplayName), LSTRING(CarAlarm)], + [0, 300, 30, 1], + true, + {}, + true +] call CBA_fnc_addSetting; diff --git a/addons/vehicles/stringtable.xml b/addons/vehicles/stringtable.xml index 16239c25..0660f6a2 100644 --- a/addons/vehicles/stringtable.xml +++ b/addons/vehicles/stringtable.xml @@ -29,6 +29,22 @@ Control exact distance (in meters) at which an alarm can be heard. Increasing the distance makes it easier for cops to spot a stolen vehicle. Kontroluje dokładną odległość (w metrach), z której alarm będzie słyszalny. Zwiększenie tej odległości ułatwia policji zlokalizowanie skradzionego pojazdu. + + Notify cops of alarm + Powiadomienie dla policji o alarmie + + + When should the cops be notified that an alarm went off? + Kiedy policja powinna być informowana o włączonym alarmie? + + + Cops notification delay + Opóźnienie powiadomienia dla policji + + + Delay between an alarm going off and possible notification for cops. + Opóźnienie pomiędzy włączeniem alarmu a możliwym powiadomieniem dla Policji. + Alarm disarm if didn't go off Rozbrój alarm jeżeli się nie włączył @@ -85,5 +101,17 @@ High Dużo + + Always + Zawsze + + + Never + Nigdy + + + If civilians nearby + Jeżeli są cywile w pobliżu + From 225480e93e27ad44abfdf9a135552406ce01d7cf Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Sat, 24 Feb 2024 19:20:03 +0100 Subject: [PATCH 2/6] Fix alarm being half as long as it should be --- addons/vehicles/functions/fnc_carAlarmLoop.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/vehicles/functions/fnc_carAlarmLoop.sqf b/addons/vehicles/functions/fnc_carAlarmLoop.sqf index c9e78f78..5fd565f7 100644 --- a/addons/vehicles/functions/fnc_carAlarmLoop.sqf +++ b/addons/vehicles/functions/fnc_carAlarmLoop.sqf @@ -31,7 +31,7 @@ if (_currentSoundDuration > ALARM_LENGTH) then { _currentSoundDuration = _currentSoundDuration + ALARM_INTERVAL; }; -_remainingDuration = _remainingDuration - 1; +_remainingDuration = _remainingDuration - ALARM_INTERVAL; // player sideChat format ["Remaining alarm: %1", _remainingDuration]; From bb35c57c9d2bf82c5dee693bc3a2e590f2c6244a Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Sat, 24 Feb 2024 19:20:21 +0100 Subject: [PATCH 3/6] Fix carAlarmNotification function --- .../functions/fnc_carAlarmNotification.sqf | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/vehicles/functions/fnc_carAlarmNotification.sqf b/addons/vehicles/functions/fnc_carAlarmNotification.sqf index 6f041b41..80951591 100644 --- a/addons/vehicles/functions/fnc_carAlarmNotification.sqf +++ b/addons/vehicles/functions/fnc_carAlarmNotification.sqf @@ -7,7 +7,7 @@ * 0: Vehicle which has alarm going off * * Return Value: - * None + * True if notification was shown * * Example: * None @@ -18,7 +18,7 @@ params ["_vehicle"]; // No notification -if (GVAR(alarmCopsNotification isEqualTo 3)) exitWith {}; +if (GVAR(alarmCopsNotification) isEqualTo 3) exitWith { false }; private _notify = if (GVAR(alarmCopsNotification) isEqualTo 1) then { // Always notify @@ -27,13 +27,19 @@ private _notify = if (GVAR(alarmCopsNotification) isEqualTo 1) then { // Notify only if civilians nearby (alarmAudibleDistance/2 as no one would really care about an alarm far from him) private _nearbyUnits = _vehicle nearEntities ["Man", GVAR(alarmAudibleDistance)/2]; private _anyNearbyUnrestrainedCivilians = _nearbyUnits - findIf {alive _x && {side _x isEqualTo CIVILIAN} && {!([_x] call FUNC(jail,isHandcuffed))}} != -1; + findIf {alive _x && {side _x isEqualTo CIVILIAN_SIDE && {!([_x] call EFUNC(jail,isHandcuffed))}}} != -1; if (_anyNearbyUnrestrainedCivilians) then { true } else { false }; }; -if (_notify) then { +if (_notify) exitWith { + LOG("Cops are notified about a car alarm."); + [QEGVAR(common,showSideChatMsg), [WEST, _this call FUNC(vehicleStolenMsg)]] call CBA_fnc_localEvent; + + true }; -nil +LOG("Cops were not notified about a car alarm."); + +false From f95d53a3f4af9d41be824e893b30b0789747f4cf Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Mon, 26 Feb 2024 19:41:21 +0100 Subject: [PATCH 4/6] Move notification logic to server to avoid unexplainable issues --- addons/vehicles/XEH_postInit.sqf | 14 +++++++++----- .../functions/fnc_carAlarmNotification.sqf | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/vehicles/XEH_postInit.sqf b/addons/vehicles/XEH_postInit.sqf index 51db079e..732786c5 100644 --- a/addons/vehicles/XEH_postInit.sqf +++ b/addons/vehicles/XEH_postInit.sqf @@ -4,6 +4,15 @@ if (isServer) then { [QGVAR(carAlarm), FUNC(carAlarm)] call CBA_fnc_addEventHandler; [QGVAR(disableCarAlarm), FUNC(disableCarAlarm)] call CBA_fnc_addEventHandler; + + [QGVAR(alarmOff), { + params ["_vehicle"]; + + // Delay notification + [{ + _this call FUNC(carAlarmNotification); + }, [_vehicle], GVAR(alarmCopsNotificationDelay)] call CBA_fnc_waitAndExecute; + }] call CBA_fnc_addEventHandler; }; if (hasInterface) then { @@ -13,10 +22,5 @@ if (hasInterface) then { params ["_vehicle"]; [_vehicle, true, GVAR(alarmDuration)] call FUNC(carAlarmLoop); - - // Delay notification - [{ - _this call FUNC(carAlarmNotification); - }, [_vehicle], GVAR(alarmCopsNotificationDelay)] call CBA_fnc_waitAndExecute; }] call CBA_fnc_addEventHandler; }; diff --git a/addons/vehicles/functions/fnc_carAlarmNotification.sqf b/addons/vehicles/functions/fnc_carAlarmNotification.sqf index 80951591..0d2bac97 100644 --- a/addons/vehicles/functions/fnc_carAlarmNotification.sqf +++ b/addons/vehicles/functions/fnc_carAlarmNotification.sqf @@ -1,7 +1,7 @@ #include "script_component.hpp" /* * Author: 3Mydlo3 - * Displays notification of a car alarm according to configured settings. + * Sends notification of a car alarm according to configured settings. * * Arguments: * 0: Vehicle which has alarm going off @@ -17,6 +17,8 @@ params ["_vehicle"]; +if (!isServer) exitWith {}; + // No notification if (GVAR(alarmCopsNotification) isEqualTo 3) exitWith { false }; @@ -35,7 +37,7 @@ private _notify = if (GVAR(alarmCopsNotification) isEqualTo 1) then { if (_notify) exitWith { LOG("Cops are notified about a car alarm."); - [QEGVAR(common,showSideChatMsg), [WEST, _this call FUNC(vehicleStolenMsg)]] call CBA_fnc_localEvent; + [QEGVAR(common,showSideChatMsg), [WEST, _this call FUNC(vehicleStolenMsg)]] call CBA_fnc_globalEvent; true }; From 44845913b43677e4989676f73b398fae8892b9f0 Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 21 Mar 2024 16:30:23 +0100 Subject: [PATCH 5/6] Use normal distribution instead of uniform for alarm chance --- addons/vehicles/functions/fnc_initVehicles.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/vehicles/functions/fnc_initVehicles.sqf b/addons/vehicles/functions/fnc_initVehicles.sqf index 3a69fd55..0affcb39 100644 --- a/addons/vehicles/functions/fnc_initVehicles.sqf +++ b/addons/vehicles/functions/fnc_initVehicles.sqf @@ -38,7 +38,7 @@ while {_i > 0} do { // Create vehicle on given position. We need some way to prevent instant damage to vehicle as these empty positions are not perfect. private _vehicle = [_carType, _pos] call FUNC(createVehicle); if (GVAR(alarmEnabled)) then { - [_vehicle, random 1 + GVAR(alarmMinimumChance)] call FUNC(initCarAlarm); + [_vehicle, random [GVAR(alarmMinimumChance), 0.5, 1]] call FUNC(initCarAlarm); }; _i = _i - 1; }; From a6503a9f5bef0fc2ebb29b388e27e5b82ecdd79e Mon Sep 17 00:00:00 2001 From: 3Mydlo3 Date: Thu, 21 Mar 2024 16:39:00 +0100 Subject: [PATCH 6/6] Add settings for avg and max alarm chance + decrease min chance to 0 --- .../vehicles/functions/fnc_initVehicles.sqf | 2 +- addons/vehicles/initSettings.inc.sqf | 26 +++++++++++++++++-- addons/vehicles/stringtable.xml | 14 +++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/addons/vehicles/functions/fnc_initVehicles.sqf b/addons/vehicles/functions/fnc_initVehicles.sqf index d7c180a7..ca131142 100644 --- a/addons/vehicles/functions/fnc_initVehicles.sqf +++ b/addons/vehicles/functions/fnc_initVehicles.sqf @@ -50,7 +50,7 @@ while {_i > 0} do { // Create vehicle on given position. We need some way to prevent instant damage to vehicle as these empty positions are not perfect. private _vehicle = [_carType, _pos] call FUNC(createVehicle); if (GVAR(alarmEnabled)) then { - [_vehicle, random [GVAR(alarmMinimumChance), 0.5, 1]] call FUNC(initCarAlarm); + [_vehicle, random [GVAR(alarmMinimumChance), GVAR(alarmAverageChance), GVAR(alarmMaximumChance)]] call FUNC(initCarAlarm); }; _i = _i - 1; }; diff --git a/addons/vehicles/initSettings.inc.sqf b/addons/vehicles/initSettings.inc.sqf index ee822c50..c2dd2b4d 100644 --- a/addons/vehicles/initSettings.inc.sqf +++ b/addons/vehicles/initSettings.inc.sqf @@ -42,12 +42,34 @@ true ] call CBA_fnc_addSetting; +[ + QGVAR(alarmAverageChance), + "SLIDER", + [LSTRING(AlarmAverageChance), LSTRING(AlarmChance_Description)], + [LSTRING(DisplayName), LSTRING(CarAlarm)], + [-1, 1, 0.5, 1], + true, + {}, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(alarmMaximumChance), + "SLIDER", + [LSTRING(AlarmMaximumChance), LSTRING(AlarmChance_Description)], + [LSTRING(DisplayName), LSTRING(CarAlarm)], + [-1, 1, 1, 1], + true, + {}, + true +] call CBA_fnc_addSetting; + [ QGVAR(alarmMinimumChance), "SLIDER", - [LSTRING(AlarmMinimumChance), LSTRING(AlarmMinimumChance_Description)], + [LSTRING(AlarmMinimumChance), LSTRING(AlarmChance_Description)], [LSTRING(DisplayName), LSTRING(CarAlarm)], - [-1, 1, 0.25, 1], + [-1, 1, 0, 1], true, {}, true diff --git a/addons/vehicles/stringtable.xml b/addons/vehicles/stringtable.xml index 0660f6a2..92bfe611 100644 --- a/addons/vehicles/stringtable.xml +++ b/addons/vehicles/stringtable.xml @@ -53,13 +53,21 @@ Disarm alarm if it didn't go off when a player entered vehicle. Effective only if 'Alarm always armed' is disabled and 'Alarm Minimum Chance' is set to less than 1. Rozbrój alarm jeżeli się nie włączył gdy gracz wszedł do pojazdu. Działa tylko jeżeli ustawienie 'Alarm zawsze uzbrojony' jest wyłączone oraz 'Minimalna szansa na alarm' jest ustawiona na mniej niż 1. + + Alarm Average Chance + Średnia szansa na alarm + + + Alarm Maximum Chance + Maksymalna szansa na alarm + Alarm Minimum Chance Minimalna szansa na alarm - - Controls the chance of an alarm going off in a car that has the alarm armed. - Ustala szansę na uruchomienie alarmu w pojeździe posiadającym alarm. + + Controls the chance of an alarm going off in a car that has the alarm armed. Normal distribution of [min, mid, max]. + Ustala szansę na uruchomienie alarmu w pojeździe posiadającym alarm. Rozkład normalny [minimum, średnia, maksimum]. Alarm Duration