From b937cdbcf916336384278958a73cec388a960785 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 10 Jun 2019 09:32:19 +0200 Subject: [PATCH 1/4] add cartridge effect on repeat --- addons/events/fnc_weaponEvents.sqf | 57 ++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index e6dc73b1b..8c16ca77a 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -84,7 +84,7 @@ if (!_isEmpty || _onEmpty) then { "_unit", "_weapon", "_muzzle", "_optic", "_handAction", "_sound", "_soundSource", "_expectedMagazineCount", "_time", "_delay", - "_triggerReleased" + "_triggerReleased", "_config" ]; // exit if unit switched weapon @@ -126,11 +126,64 @@ if (!_isEmpty || _onEmpty) then { _soundSource say3D _sound; }; + // eject cartidge on repeat + private _cartridgeType = getText (_config >> "cartridgeType"); + + if (_cartridgeType != "") then { + private _cartridgeEjectPosition = getArray (_config >> "cartridgeEjectPosition"); + private _cartridgeEjectVelocity = getArray (_config >> "cartridgeEjectVelocity"); + private _cartridgeEjectDelay = getNumber (_config >> "cartridgeEjectDelay"); + + if (_cartridgeEjectPosition isEqualTo []) then { + _cartridgeEjectPosition = [0,0,0]; + }; + + if (_cartridgeEjectVelocity isEqualTo []) then { + _cartridgeEjectVelocity = [0,1,0]; + }; + + [{ + params ["_unit", "_weapon", "_cartridgeType", "_cartridgeEjectPosition", "_cartridgeEjectVelocity"]; + + private _aim = _unit modelToWorldVisualWorld (_unit selectionPosition "aimPoint"); + private _cam = _unit modelToWorldVisualWorld (_unit selectionPosition "camera"); + private _uUp = _aim vectorFromTo _cam; + + private _wDir = _unit weaponDirection _weapon; + private _wLat = vectorNormalized (_wDir vectorCrossProduct _uUp); + private _wUp = _wLat vectorCrossProduct _wDir; + + private _origin = _unit modelToWorldVisualWorld (_unit selectionPosition "proxy:\a3\characters_f\proxies\weapon.001"); + + private _position = _origin vectorAdd + (_wDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd + (_wLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd + (_wUp vectorMultiply _cartridgeEjectPosition#2); + + private _cartridge = _cartridgeType createVehicleLocal [0,0,0]; + _cartridge setPosWorld _position; + + _cartridge setVectorDirAndUp [ + vectorNormalized _wDir, + vectorNormalized _wUp + ]; + + private _velocity = velocity _unit vectorAdd + (_wDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd + (_wLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd + (_wUp vectorMultiply _cartridgeEjectVelocity#2); + + _cartridge setVelocity _velocity; + }, [ + _unit, _weapon, _cartridgeType, _cartridgeEjectPosition, _cartridgeEjectVelocity + ], _cartridgeEjectDelay] call CBA_fnc_waitAndExecute; + }; + true // exit loop }, {}, [ _unit, _weapon, _muzzle, _optic, _handAction, _sound, call _fnc_soundSource, _expectedMagazineCount, CBA_missionTime, _delay, - _triggerReleased + _triggerReleased, _config ]] call CBA_fnc_waitUntilAndExecute; }; From f61d40441f8f5fdb15a323e81c8780d275bd5a07 Mon Sep 17 00:00:00 2001 From: commy2 Date: Mon, 10 Jun 2019 12:41:10 +0200 Subject: [PATCH 2/4] optimize --- addons/events/fnc_weaponEvents.sqf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 8c16ca77a..05771d7e5 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -160,8 +160,7 @@ if (!_isEmpty || _onEmpty) then { (_wLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd (_wUp vectorMultiply _cartridgeEjectPosition#2); - private _cartridge = _cartridgeType createVehicleLocal [0,0,0]; - _cartridge setPosWorld _position; + private _cartridge = _cartridgeType createVehicleLocal ASLToAGL _position; _cartridge setVectorDirAndUp [ vectorNormalized _wDir, From 8c8bb6b3e4aad85d982a0becaedd2f0b74cb25a5 Mon Sep 17 00:00:00 2001 From: commy2 Date: Fri, 14 Jun 2019 00:01:37 +0200 Subject: [PATCH 3/4] velocity one frame later to fix drawn position in frame 0 --- addons/events/fnc_weaponEvents.sqf | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 05771d7e5..3bacaa86f 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -145,7 +145,7 @@ if (!_isEmpty || _onEmpty) then { [{ params ["_unit", "_weapon", "_cartridgeType", "_cartridgeEjectPosition", "_cartridgeEjectVelocity"]; - private _aim = _unit modelToWorldVisualWorld (_unit selectionPosition "aimPoint"); + private _aim = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis"); private _cam = _unit modelToWorldVisualWorld (_unit selectionPosition "camera"); private _uUp = _aim vectorFromTo _cam; @@ -172,7 +172,10 @@ if (!_isEmpty || _onEmpty) then { (_wLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd (_wUp vectorMultiply _cartridgeEjectVelocity#2); - _cartridge setVelocity _velocity; + [{ + params ["_cartridge", "_velocity"]; + _cartridge setVelocity _velocity; + }, [_cartridge, _velocity]] call CBA_fnc_execNextFrame; }, [ _unit, _weapon, _cartridgeType, _cartridgeEjectPosition, _cartridgeEjectVelocity ], _cartridgeEjectDelay] call CBA_fnc_waitAndExecute; From 9fecfa98ce7525b0189b0973f443c7bf6315846c Mon Sep 17 00:00:00 2001 From: commy2 Date: Sat, 15 Jun 2019 09:42:50 +0200 Subject: [PATCH 4/4] update variable names --- addons/events/fnc_weaponEvents.sqf | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index 3bacaa86f..a1ddd167d 100644 --- a/addons/events/fnc_weaponEvents.sqf +++ b/addons/events/fnc_weaponEvents.sqf @@ -145,32 +145,32 @@ if (!_isEmpty || _onEmpty) then { [{ params ["_unit", "_weapon", "_cartridgeType", "_cartridgeEjectPosition", "_cartridgeEjectVelocity"]; - private _aim = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis"); - private _cam = _unit modelToWorldVisualWorld (_unit selectionPosition "camera"); - private _uUp = _aim vectorFromTo _cam; + private _pelvis = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis"); + private _camera = _unit modelToWorldVisualWorld (_unit selectionPosition "camera"); + private _bodyUp = _pelvis vectorFromTo _camera; - private _wDir = _unit weaponDirection _weapon; - private _wLat = vectorNormalized (_wDir vectorCrossProduct _uUp); - private _wUp = _wLat vectorCrossProduct _wDir; + private _weaponDir = _unit weaponDirection _weapon; + private _weaponLat = vectorNormalized (_weaponDir vectorCrossProduct _bodyUp); + private _weaponUp = _weaponLat vectorCrossProduct _weaponDir; private _origin = _unit modelToWorldVisualWorld (_unit selectionPosition "proxy:\a3\characters_f\proxies\weapon.001"); private _position = _origin vectorAdd - (_wDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd - (_wLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd - (_wUp vectorMultiply _cartridgeEjectPosition#2); + (_weaponDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd + (_weaponLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd + (_weaponUp vectorMultiply _cartridgeEjectPosition#2); private _cartridge = _cartridgeType createVehicleLocal ASLToAGL _position; _cartridge setVectorDirAndUp [ - vectorNormalized _wDir, - vectorNormalized _wUp + vectorNormalized _weaponDir, + vectorNormalized _weaponUp ]; private _velocity = velocity _unit vectorAdd - (_wDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd - (_wLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd - (_wUp vectorMultiply _cartridgeEjectVelocity#2); + (_weaponDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd + (_weaponLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd + (_weaponUp vectorMultiply _cartridgeEjectVelocity#2); [{ params ["_cartridge", "_velocity"];