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

Add trigger options to weapon events / repetition #1107

Merged
merged 9 commits into from
Apr 7, 2019
20 changes: 20 additions & 0 deletions addons/events/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,23 @@ if (isServer) then {
};
};
}] call CBA_fnc_addEventHandler;

// trigger pressed
// using display EH due to better reliance compared to inputAction
["MouseButtonDown", {
params ["", "_button"];

// TODO Support non-LMB (?)
if (_button == 0) then {
GVAR(triggerPressed) = true;
};
}] call CBA_fnc_addDisplayHandler;

["MouseButtonUp", {
params ["", "_button"];

// TODO Support non-LMB (?)
if (_button == 0) then {
GVAR(triggerPressed) = false;
};
}] call CBA_fnc_addDisplayHandler;
1 change: 1 addition & 0 deletions addons/events/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (isServer) then {
};

#include "backwards_comp.sqf"
#include "initSettings.sqf"

ADDON = true;

Expand Down
27 changes: 23 additions & 4 deletions addons/events/fnc_weaponEvents.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ if (!_isEmpty || _onEmpty) then {
_optic = _weapon;
};

private _triggerReleased = false;

[{
params [
"_unit", "_weapon", "_muzzle", "_optic",
"_handAction", "_sound", "_soundSource",
"_expectedMagazineCount", "_time", "_delay"
"_expectedMagazineCount", "_time", "_delay",
"_triggerReleased"
];

// exit if unit switched weapon
Expand All @@ -90,8 +93,23 @@ if (!_isEmpty || _onEmpty) then {
// exit if unit started reloading
if (count magazines _unit != _expectedMagazineCount) exitWith {true};

// while in gunner view, keep waiting
if (cameraView == "GUNNER" && _optic != "") exitWith {
// mode 0: while in gunner view, keep waiting
// mode 1: while holding trigger, keep waiting
// mode 2: while holding trigger and not pressing it, keep waiting
private _wait = call ([{
cameraView == "GUNNER" && _optic != ""
}, {
GVAR(triggerPressed)
}, {
!_triggerReleased || !GVAR(triggerPressed)
}] select GVAR(repetitionMode));

if (_wait) exitWith {
// Detect trigger release
if (GVAR(repetitionMode) == 2 && !GVAR(triggerPressed)) then {
_this set [10, true];
};

_this set [8, CBA_missionTime];
_unit setWeaponReloadingTime [_unit, _muzzle, 1];
false
Expand All @@ -112,6 +130,7 @@ if (!_isEmpty || _onEmpty) then {
}, {}, [
_unit, _weapon, _muzzle, _optic,
_handAction, _sound, call _fnc_soundSource,
_expectedMagazineCount, CBA_missionTime, _delay
_expectedMagazineCount, CBA_missionTime, _delay,
_triggerReleased
]] call CBA_fnc_waitUntilAndExecute;
};
12 changes: 12 additions & 0 deletions addons/events/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
QGVAR(repetitionMode),
"LIST",
[LLSTRING(RepetitionMode), LLSTRING(RepetitionModeTooltip)],
LLSTRING(WeaponsCategory),
[[0, 1, 2], [
[LLSTRING(RepetitionModeOptic), LLSTRING(RepetitionModeOpticTooltip)], // Exit optic view
[LLSTRING(RepetitionModeTriggerRelease), LLSTRING(RepetitionModeTriggerReleaseTooltip)], // Stop holding trigger
[LLSTRING(RepetitionModeTriggerPress), LLSTRING(RepetitionModeTriggerPressTooltip)] // Click trigger again
], 1],
2
] call CBA_fnc_addSetting;
36 changes: 36 additions & 0 deletions addons/events/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,41 @@
<Polish>Community Base Addons - Zdarzenia</Polish>
<Turkish>Community Base Addons - Durumlar</Turkish>
</Key>
<Key ID="STR_CBA_Events_WeaponsCategory">
<English>CBA Weapons</English>
<German>CBA Waffen</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionMode">
<English>Weapon Repetition Mode</English>
<German>Repetierwaffe laden</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeTooltip">
<English>Mode of bolting or pumping weapons.</English>
<German>Art eine Waffe zu repetieren.</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeOptic">
<English>Leave Optics View</English>
<German>Optikansicht verlassen</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeOpticTooltip">
<English>Bolt or rack weapon by leaving optics view.</English>
<German>Waffe beim Verlassen der Optikansicht repetieren.</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeTriggerRelease">
<English>Release Trigger</English>
<German>Abzug losslassen</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeTriggerReleaseTooltip">
<English>Bolt or rack weapon by releasing trigger (hold trigger to prevent immediate action).</English>
<German>Waffe beim Loslassen des Abzugs repetieren (Abzug halten, um Repetieren zu verzögern).</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeTriggerPress">
<English>Press Trigger</English>
<German>Abzug betätigen</German>
</Key>
<Key ID="STR_CBA_Events_RepetitionModeTriggerPressTooltip">
<English>Bolt or rack weapon by pressing the trigger again.</English>
<German>Waffe beim erneuten Betätigen des Abzugs repetieren.</German>
</Key>
</Package>
</Project>