Skip to content

Commit 6a42995

Browse files
authored
add cartridge ejection effect on repeat (#1158)
* add cartridge effect on repeat * optimize * velocity one frame later to fix drawn position in frame 0 * update variable names
1 parent cd8a239 commit 6a42995

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

addons/events/fnc_weaponEvents.sqf

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ if (!_isEmpty || _onEmpty) then {
8484
"_unit", "_weapon", "_muzzle", "_optic",
8585
"_handAction", "_sound", "_soundSource",
8686
"_expectedMagazineCount", "_time", "_delay",
87-
"_triggerReleased"
87+
"_triggerReleased", "_config"
8888
];
8989

9090
// exit if unit switched weapon
@@ -126,11 +126,66 @@ if (!_isEmpty || _onEmpty) then {
126126
_soundSource say3D _sound;
127127
};
128128

129+
// eject cartidge on repeat
130+
private _cartridgeType = getText (_config >> "cartridgeType");
131+
132+
if (_cartridgeType != "") then {
133+
private _cartridgeEjectPosition = getArray (_config >> "cartridgeEjectPosition");
134+
private _cartridgeEjectVelocity = getArray (_config >> "cartridgeEjectVelocity");
135+
private _cartridgeEjectDelay = getNumber (_config >> "cartridgeEjectDelay");
136+
137+
if (_cartridgeEjectPosition isEqualTo []) then {
138+
_cartridgeEjectPosition = [0,0,0];
139+
};
140+
141+
if (_cartridgeEjectVelocity isEqualTo []) then {
142+
_cartridgeEjectVelocity = [0,1,0];
143+
};
144+
145+
[{
146+
params ["_unit", "_weapon", "_cartridgeType", "_cartridgeEjectPosition", "_cartridgeEjectVelocity"];
147+
148+
private _pelvis = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis");
149+
private _camera = _unit modelToWorldVisualWorld (_unit selectionPosition "camera");
150+
private _bodyUp = _pelvis vectorFromTo _camera;
151+
152+
private _weaponDir = _unit weaponDirection _weapon;
153+
private _weaponLat = vectorNormalized (_weaponDir vectorCrossProduct _bodyUp);
154+
private _weaponUp = _weaponLat vectorCrossProduct _weaponDir;
155+
156+
private _origin = _unit modelToWorldVisualWorld (_unit selectionPosition "proxy:\a3\characters_f\proxies\weapon.001");
157+
158+
private _position = _origin vectorAdd
159+
(_weaponDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd
160+
(_weaponLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd
161+
(_weaponUp vectorMultiply _cartridgeEjectPosition#2);
162+
163+
private _cartridge = _cartridgeType createVehicleLocal ASLToAGL _position;
164+
165+
_cartridge setVectorDirAndUp [
166+
vectorNormalized _weaponDir,
167+
vectorNormalized _weaponUp
168+
];
169+
170+
private _velocity = velocity _unit vectorAdd
171+
(_weaponDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd
172+
(_weaponLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd
173+
(_weaponUp vectorMultiply _cartridgeEjectVelocity#2);
174+
175+
[{
176+
params ["_cartridge", "_velocity"];
177+
_cartridge setVelocity _velocity;
178+
}, [_cartridge, _velocity]] call CBA_fnc_execNextFrame;
179+
}, [
180+
_unit, _weapon, _cartridgeType, _cartridgeEjectPosition, _cartridgeEjectVelocity
181+
], _cartridgeEjectDelay] call CBA_fnc_waitAndExecute;
182+
};
183+
129184
true // exit loop
130185
}, {}, [
131186
_unit, _weapon, _muzzle, _optic,
132187
_handAction, _sound, call _fnc_soundSource,
133188
_expectedMagazineCount, CBA_missionTime, _delay,
134-
_triggerReleased
189+
_triggerReleased, _config
135190
]] call CBA_fnc_waitUntilAndExecute;
136191
};

0 commit comments

Comments
 (0)