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(weaponEventMode));

if (_wait) exitWith {
// Detect trigger release
if (GVAR(weaponEventMode) == 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(weaponEventMode),
"LIST",
[LLSTRING(WeaponEventMode), LLSTRING(WeaponEventModeTooltip)],
LLSTRING(Category),
[[0, 1, 2], [
[LLSTRING(WeaponEventModeOptic), LLSTRING(WeaponEventModeOpticTooltip)], // Exit optic view
[LLSTRING(WeaponEventModeTriggerRelease), LLSTRING(WeaponEventModeTriggerReleaseTooltip)], // Stop holding trigger
[LLSTRING(WeaponEventModeTriggerPress), LLSTRING(WeaponEventModeTriggerPressTooltip)] // Click trigger again
], 1],
2
] call (uiNamespace getVariable "cba_settings_fnc_init");
commy2 marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions addons/events/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,32 @@
<Polish>Community Base Addons - Zdarzenia</Polish>
<Turkish>Community Base Addons - Durumlar</Turkish>
</Key>
<Key ID="STR_CBA_Events_Category">
<English>CBA Events</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventMode">
<English>Weapon Event Mode</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeTooltip">
<English>Mode of bolting or pumping weapons supporting Weapon Animations Framework.</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeOptic">
<English>Leave Optics View</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeOpticTooltip">
<English>Bolt or rack weapon by leaving optics view.</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeTriggerRelease">
<English>Release Trigger</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeTriggerReleaseTooltip">
<English>Bolt or rack weapon by releasing trigger (hold trigger to prevent immediate action).</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeTriggerPress">
<English>Press Trigger</English>
</Key>
<Key ID="STR_CBA_Events_WeaponEventModeTriggerPressTooltip">
<English>Bolt or rack weapon by pressing the trigger again.</English>
</Key>
</Package>
</Project>