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 cartridge ejection effect on repeat #1158

Merged
merged 5 commits into from
Jun 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions addons/events/fnc_weaponEvents.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
};