Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make alarm notification togglable and decrease alarm chance #85

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/vehicles/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PREP(carAlarm);
PREP(carAlarmLoop);
PREP(carAlarmNotification);
PREP(createVehicle);
PREP(disableCarAlarm);
PREP(initCarAlarm);
Expand Down
10 changes: 9 additions & 1 deletion addons/vehicles/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -12,7 +21,6 @@ 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);
}] call CBA_fnc_addEventHandler;
};
2 changes: 1 addition & 1 deletion addons/vehicles/functions/fnc_carAlarmLoop.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
47 changes: 47 additions & 0 deletions addons/vehicles/functions/fnc_carAlarmNotification.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Sends notification of a car alarm according to configured settings.
*
* Arguments:
* 0: Vehicle which has alarm going off <OBJECT>
*
* Return Value:
* True if notification was shown <BOOL>
*
* Example:
* None
*
* Public: No
*/

params ["_vehicle"];

if (!isServer) exitWith {};

// No notification
if (GVAR(alarmCopsNotification) isEqualTo 3) exitWith { false };

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_SIDE && {!([_x] call EFUNC(jail,isHandcuffed))}}} != -1;

if (_anyNearbyUnrestrainedCivilians) then { true } else { false };
};

if (_notify) exitWith {
LOG("Cops are notified about a car alarm.");

[QEGVAR(common,showSideChatMsg), [WEST, _this call FUNC(vehicleStolenMsg)]] call CBA_fnc_globalEvent;

true
};

LOG("Cops were not notified about a car alarm.");

false
2 changes: 1 addition & 1 deletion addons/vehicles/functions/fnc_initVehicles.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 1 + GVAR(alarmMinimumChance)] call FUNC(initCarAlarm);
[_vehicle, random [GVAR(alarmMinimumChance), GVAR(alarmAverageChance), GVAR(alarmMaximumChance)]] call FUNC(initCarAlarm);
};
_i = _i - 1;
};
Expand Down
48 changes: 46 additions & 2 deletions addons/vehicles/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,3 +96,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;
42 changes: 39 additions & 3 deletions addons/vehicles/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
<English>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.</English>
<Polish>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.</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmCopsNotification">
<English>Notify cops of alarm</English>
<Polish>Powiadomienie dla policji o alarmie</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmCopsNotification_Description">
<English>When should the cops be notified that an alarm went off?</English>
<Polish>Kiedy policja powinna być informowana o włączonym alarmie?</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmCopsNotificationDelay">
<English>Cops notification delay</English>
<Polish>Opóźnienie powiadomienia dla policji</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmCopsNotificationDelay_Description">
<English>Delay between an alarm going off and possible notification for cops.</English>
<Polish>Opóźnienie pomiędzy włączeniem alarmu a możliwym powiadomieniem dla Policji.</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmDisarmIfFailed">
<English>Alarm disarm if didn't go off</English>
<Polish>Rozbrój alarm jeżeli się nie włączył</Polish>
Expand All @@ -37,13 +53,21 @@
<English>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.</English>
<Polish>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.</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmAverageChance">
<English>Alarm Average Chance</English>
<Polish>Średnia szansa na alarm</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmMaximumChance">
<English>Alarm Maximum Chance</English>
<Polish>Maksymalna szansa na alarm</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmMinimumChance">
<English>Alarm Minimum Chance</English>
<Polish>Minimalna szansa na alarm</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmMinimumChance_Description">
<English>Controls the chance of an alarm going off in a car that has the alarm armed.</English>
<Polish>Ustala szansę na uruchomienie alarmu w pojeździe posiadającym alarm.</Polish>
<Key ID="STR_AFSK_Vehicles_AlarmChance_Description">
<English>Controls the chance of an alarm going off in a car that has the alarm armed. Normal distribution of [min, mid, max].</English>
<Polish>Ustala szansę na uruchomienie alarmu w pojeździe posiadającym alarm. Rozkład normalny [minimum, średnia, maksimum].</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_AlarmDuration">
<English>Alarm Duration</English>
Expand Down Expand Up @@ -85,5 +109,17 @@
<English>High</English>
<Polish>Dużo</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_Always">
<English>Always</English>
<Polish>Zawsze</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_Never">
<English>Never</English>
<Polish>Nigdy</Polish>
</Key>
<Key ID="STR_AFSK_Vehicles_IfCiviliansNearby">
<English>If civilians nearby</English>
<Polish>Jeżeli są cywile w pobliżu</Polish>
</Key>
</Package>
</Project>