diff --git a/addons/events/fnc_weaponEvents.sqf b/addons/events/fnc_weaponEvents.sqf index e6dc73b1b..a1ddd167d 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,66 @@ 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 _pelvis = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis"); + private _camera = _unit modelToWorldVisualWorld (_unit selectionPosition "camera"); + private _bodyUp = _pelvis vectorFromTo _camera; + + 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 + (_weaponDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd + (_weaponLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd + (_weaponUp vectorMultiply _cartridgeEjectPosition#2); + + private _cartridge = _cartridgeType createVehicleLocal ASLToAGL _position; + + _cartridge setVectorDirAndUp [ + vectorNormalized _weaponDir, + vectorNormalized _weaponUp + ]; + + private _velocity = velocity _unit vectorAdd + (_weaponDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd + (_weaponLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd + (_weaponUp vectorMultiply _cartridgeEjectVelocity#2); + + [{ + params ["_cartridge", "_velocity"]; + _cartridge setVelocity _velocity; + }, [_cartridge, _velocity]] call CBA_fnc_execNextFrame; + }, [ + _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; };