From 71fd9ddc7e342bb63101169e3223d1f5363ddb82 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 9 Dec 2017 14:40:35 +0100 Subject: [PATCH 1/9] add weapon eventhandler framework --- addons/events/CfgFunctions.hpp | 1 + addons/events/config.cpp | 20 ++++++++ addons/events/fnc_weaponEvents.sqf | 80 ++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 addons/events/fnc_weaponEvents.sqf diff --git a/addons/events/CfgFunctions.hpp b/addons/events/CfgFunctions.hpp index 6a274659f..670a274c9 100644 --- a/addons/events/CfgFunctions.hpp +++ b/addons/events/CfgFunctions.hpp @@ -88,6 +88,7 @@ class CfgFunctions { PATHTO_FNC(addMarkerEventHandler); PATHTO_FNC(removeMarkerEventHandler); PATHTO_FNC(registerChatCommand); + PATHTO_FNC(weaponEvents); }; }; }; diff --git a/addons/events/config.cpp b/addons/events/config.cpp index 340cb1003..5b4019ec5 100644 --- a/addons/events/config.cpp +++ b/addons/events/config.cpp @@ -24,3 +24,23 @@ class RscDisplayChat { false\ ); }; + +#define DEBUG_MODE_FULL +#ifdef DEBUG_MODE_FULL +class CfgWeapons { + class arifle_MX_Base_F; + class arifle_MX_F: arifle_MX_Base_F { + class EventHandlers { + fired = "_this call CBA_fnc_weaponEvents"; + }; + + class CBA_weaponEvents { + onEmpty = 0; + handAction = "gestureNo"; + sound = "Alarm"; // from CfgSounds + soundLocation = "LeftHandMiddle1"; // alternative: "RightHandMiddle1" + delay = 0.5; // in seconds + }; + }; +}; +#endif diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf new file mode 100644 index 000000000..029a2e2f9 --- /dev/null +++ b/addons/events/fnc_weaponEvents.sqf @@ -0,0 +1,80 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_weaponEvents + +Description: + Execute weapon events framework. + + class MyWeapon: MyWeapon_base { + class EventHandlers { + fired = "_this call CBA_fnc_weaponEvents"; + }; + }; + +Parameters: + _unit - Unit that fired the weapon + _weapon - The weapon fired by the unit + +Returns: + Nothing + +Examples: + (begin example) + fired = "_this call CBA_fnc_weaponEvents"; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" + +params ["_unit", "_weapon"]; + +private _config = configFile >> "CfgWeapons" >> _weapon >> "CBA_WeaponEvents"; + +private _isEmpty = _unit ammo _weapon == 0; +private _onEmpty = true; + +if (isNumber (_config >> "onEmpty")) then { + _onEmpty = getNumber (_config >> "onEmpty") == 1; +}; + +private _fnc_soundSource = { + private _soundSourceName = format [QGVAR(soundSource_%1), _soundLocation]; + private _soundSource = _unit getVariable [_soundSourceName, objNull]; + + if !(_soundSource in attachedObjects _unit) then { + _soundSource = "Building" createVehicleLocal [0,0,0]; + _soundSource attachTo [_unit, [0,0,0], _soundLocation]; + _unit setVariable [_soundSourceName, _soundSource]; + }; + + _soundSource +}; + +if (isEmpty) then { + private _sound = getText (_config >> "soundEmpty"); + private _soundLocation = getText (_config >> "soundLocationEmpty"); + + if (_sound != "") then { + (call _fnc_soundSource) say3D _sound; + }; +}; + +if (!_isEmpty || _onEmpty) then { + private _handAction = getText (_config >> "handAction"); + private _sound = getText (_config >> "sound"); + private _soundLocation = getText (_config >> "soundLocation"); + private _delay = getNumber (_config >> "delay"); + + [{ + params ["_unit", "_handAction", "_sound", "_soundSource"]; + + if (local _unit) then { + _unit playAction _handAction; + }; + + if (_sound != "") then { + _soundSource say3D _sound; + }; + }, [_unit, _handAction, _sound, call _fnc_soundSource], _delay] call CBA_fnc_waitAndExecute; +}; From 230d21eb5d33622b6e9d160c8df2f31b092fa7a1 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 9 Dec 2017 14:55:15 +0100 Subject: [PATCH 2/9] disable debug --- addons/events/config.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/events/config.cpp b/addons/events/config.cpp index 5b4019ec5..76bc96eb7 100644 --- a/addons/events/config.cpp +++ b/addons/events/config.cpp @@ -25,21 +25,22 @@ class RscDisplayChat { ); }; -#define DEBUG_MODE_FULL +//#define DEBUG_MODE_FULL #ifdef DEBUG_MODE_FULL class CfgWeapons { class arifle_MX_Base_F; class arifle_MX_F: arifle_MX_Base_F { class EventHandlers { - fired = "_this call CBA_fnc_weaponEvents"; + fired = "_this call CBA_fnc_weaponEvents"; // this weapon eventhandler is required! }; - class CBA_weaponEvents { - onEmpty = 0; - handAction = "gestureNo"; + handAction = "gestureNo"; // hand animation, from CfgGesturesMale\States sound = "Alarm"; // from CfgSounds - soundLocation = "LeftHandMiddle1"; // alternative: "RightHandMiddle1" - delay = 0.5; // in seconds + soundLocation = "LeftHandMiddle1"; // Where the sound is played. Selection on the soldier, not the weapon! Alternative: RightHandMiddle1 + delay = 0.5; // delay for sound and hand animation, in seconds + onEmpty = 0; // 1: play sound and action defined above on the last round, 0: don't, default 1; the sound below is played anyway + soundEmpty = ""; // sound played on the last round + soundLocationEmpty = ""; // Where the sound for the last round is played. }; }; }; From bb820582ab509a3af654deda0af48c1ed591fda9 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 9 Dec 2017 15:16:37 +0100 Subject: [PATCH 3/9] Update fnc_weaponEvents.sqf --- addons/events/fnc_weaponEvents.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 029a2e2f9..f8370d79a 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -51,7 +51,7 @@ private _fnc_soundSource = { _soundSource }; -if (isEmpty) then { +if (_isEmpty) then { private _sound = getText (_config >> "soundEmpty"); private _soundLocation = getText (_config >> "soundLocationEmpty"); From 6c369679890cfb9f02cf42aa2cd8d948918b49ff Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 9 Dec 2017 15:36:48 +0100 Subject: [PATCH 4/9] particle source dummy --- addons/events/fnc_weaponEvents.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index f8370d79a..ba991fca2 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -43,7 +43,7 @@ private _fnc_soundSource = { private _soundSource = _unit getVariable [_soundSourceName, objNull]; if !(_soundSource in attachedObjects _unit) then { - _soundSource = "Building" createVehicleLocal [0,0,0]; + _soundSource = "#particlesource" createVehicleLocal [0,0,0]; _soundSource attachTo [_unit, [0,0,0], _soundLocation]; _unit setVariable [_soundSourceName, _soundSource]; }; From 699d609e9e585ff57dac054d13d5e416b7b26d29 Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 10 Dec 2017 13:15:36 +0100 Subject: [PATCH 5/9] reuse sound source from corpse --- addons/events/fnc_weaponEvents.sqf | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index ba991fca2..abeba0575 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -43,7 +43,9 @@ private _fnc_soundSource = { private _soundSource = _unit getVariable [_soundSourceName, objNull]; if !(_soundSource in attachedObjects _unit) then { - _soundSource = "#particlesource" createVehicleLocal [0,0,0]; + if (isNull _soundSource) then { + _soundSource = "#particlesource" createVehicleLocal [0,0,0]; + }; _soundSource attachTo [_unit, [0,0,0], _soundLocation]; _unit setVariable [_soundSourceName, _soundSource]; }; From 28610f37692d4edd7a97ca46a55f4dc0525db967 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 11 Dec 2017 13:43:54 +0100 Subject: [PATCH 6/9] work around gestures eating magazines --- addons/events/fnc_weaponEvents.sqf | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index abeba0575..c913123a7 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -68,8 +68,13 @@ if (!_isEmpty || _onEmpty) then { private _soundLocation = getText (_config >> "soundLocation"); private _delay = getNumber (_config >> "delay"); + private _expectedMagazineCount = count magazines _unit; + [{ - params ["_unit", "_handAction", "_sound", "_soundSource"]; + params ["_unit", "_handAction", "_sound", "_soundSource", "_expectedMagazineCount"]; + + // exit if unit started reloading + if (count magazines _unit != _expectedMagazineCount) exitWith {}; if (local _unit) then { _unit playAction _handAction; @@ -78,5 +83,5 @@ if (!_isEmpty || _onEmpty) then { if (_sound != "") then { _soundSource say3D _sound; }; - }, [_unit, _handAction, _sound, call _fnc_soundSource], _delay] call CBA_fnc_waitAndExecute; + }, [_unit, _handAction, _sound, call _fnc_soundSource, _expectedMagazineCount], _delay] call CBA_fnc_waitAndExecute; }; From 5678a806d81b4cda655bc4c4589d0de9d597c00a Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 11 Dec 2017 17:55:30 +0100 Subject: [PATCH 7/9] fix no sound played in arsenal --- addons/events/fnc_weaponEvents.sqf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index c913123a7..022e4e977 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -42,10 +42,11 @@ private _fnc_soundSource = { private _soundSourceName = format [QGVAR(soundSource_%1), _soundLocation]; private _soundSource = _unit getVariable [_soundSourceName, objNull]; + if (isNull _soundSource) then { + _soundSource = "#particlesource" createVehicleLocal [0,0,0]; + }; + if !(_soundSource in attachedObjects _unit) then { - if (isNull _soundSource) then { - _soundSource = "#particlesource" createVehicleLocal [0,0,0]; - }; _soundSource attachTo [_unit, [0,0,0], _soundLocation]; _unit setVariable [_soundSourceName, _soundSource]; }; From a99b2e7332a339c0bfd314587a40bc18407a6194 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 19 Dec 2017 17:16:51 +0100 Subject: [PATCH 8/9] don't reload while in gunner view --- addons/events/config.cpp | 2 +- addons/events/fnc_weaponEvents.sqf | 32 ++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/addons/events/config.cpp b/addons/events/config.cpp index 76bc96eb7..ee0b36e3a 100644 --- a/addons/events/config.cpp +++ b/addons/events/config.cpp @@ -25,7 +25,7 @@ class RscDisplayChat { ); }; -//#define DEBUG_MODE_FULL +#define DEBUG_MODE_FULL #ifdef DEBUG_MODE_FULL class CfgWeapons { class arifle_MX_Base_F; diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 022e4e977..92243a9de 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -27,7 +27,7 @@ Author: ---------------------------------------------------------------------------- */ #include "script_component.hpp" -params ["_unit", "_weapon"]; +params ["_unit", "_weapon", "_muzzle"]; private _config = configFile >> "CfgWeapons" >> _weapon >> "CBA_WeaponEvents"; @@ -70,12 +70,30 @@ if (!_isEmpty || _onEmpty) then { private _delay = getNumber (_config >> "delay"); private _expectedMagazineCount = count magazines _unit; + private _optic = weaponsItems _unit select {_x select 0 == _weapon} param [0, []] param [3, ""]; [{ - params ["_unit", "_handAction", "_sound", "_soundSource", "_expectedMagazineCount"]; + params [ + "_unit", "_weapon", "_muzzle", "_optic", + "_handAction", "_sound", "_soundSource", + "_expectedMagazineCount", "_time", "_delay" + ]; + + // exit if unit switched weapon + if (currentWeapon _unit != _weapon) exitWith {true}; // exit if unit started reloading - if (count magazines _unit != _expectedMagazineCount) exitWith {}; + if (count magazines _unit != _expectedMagazineCount) exitWith {true}; + + // while in gunner view, keep waiting + if (cameraView == "GUNNER" && _optic != "") exitWith { + _this set [8, CBA_missionTime]; + _unit setWeaponReloadingTime [_unit, _muzzle, 1]; + false + }; + + // keep waiting until time over + if (CBA_missionTime < _time + _delay) exitWith {false}; if (local _unit) then { _unit playAction _handAction; @@ -84,5 +102,11 @@ if (!_isEmpty || _onEmpty) then { if (_sound != "") then { _soundSource say3D _sound; }; - }, [_unit, _handAction, _sound, call _fnc_soundSource, _expectedMagazineCount], _delay] call CBA_fnc_waitAndExecute; + + true // exit loop + }, {}, [ + _unit, _weapon, _muzzle, _optic, + _handAction, _sound, call _fnc_soundSource, + _expectedMagazineCount, CBA_missionTime, _delay + ]] call CBA_fnc_waitUntilAndExecute; }; From fe7c10e71be7a88454ff8628a5178834d4ebd413 Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 19 Dec 2017 19:04:57 +0100 Subject: [PATCH 9/9] hasOptic check --- addons/events/config.cpp | 3 ++- addons/events/fnc_weaponEvents.sqf | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/events/config.cpp b/addons/events/config.cpp index ee0b36e3a..1f6c46ab2 100644 --- a/addons/events/config.cpp +++ b/addons/events/config.cpp @@ -25,7 +25,7 @@ class RscDisplayChat { ); }; -#define DEBUG_MODE_FULL +//#define DEBUG_MODE_FULL #ifdef DEBUG_MODE_FULL class CfgWeapons { class arifle_MX_Base_F; @@ -39,6 +39,7 @@ class CfgWeapons { soundLocation = "LeftHandMiddle1"; // Where the sound is played. Selection on the soldier, not the weapon! Alternative: RightHandMiddle1 delay = 0.5; // delay for sound and hand animation, in seconds onEmpty = 0; // 1: play sound and action defined above on the last round, 0: don't, default 1; the sound below is played anyway + hasOptic = 1; // Set to 1 to do optic check with inbuild optic (no attachment) soundEmpty = ""; // sound played on the last round soundLocationEmpty = ""; // Where the sound for the last round is played. }; diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 92243a9de..8636f2c38 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -68,10 +68,15 @@ if (!_isEmpty || _onEmpty) then { private _sound = getText (_config >> "sound"); private _soundLocation = getText (_config >> "soundLocation"); private _delay = getNumber (_config >> "delay"); + private _hasOptic = getNumber (_config >> "hasOptic") == 1; private _expectedMagazineCount = count magazines _unit; private _optic = weaponsItems _unit select {_x select 0 == _weapon} param [0, []] param [3, ""]; + if (_optic isEqualTo "" && _hasOptic) then { + _optic = _weapon; + }; + [{ params [ "_unit", "_weapon", "_muzzle", "_optic",