|
1 | 1 | #include "..\script_component.hpp" |
2 | 2 | /* |
3 | | - * Author: Ir0n1E and mjc4wilton |
| 3 | + * Author: Ir0n1E, mjc4wilton |
4 | 4 | * Swap primary weapon and weapon in gunbag. |
5 | 5 | * |
6 | 6 | * Arguments: |
|
11 | 11 | * None |
12 | 12 | * |
13 | 13 | * Example: |
14 | | - * [player, target] call ace_gunbag_fnc_swapGunbagCallback |
| 14 | + * [player, cursorObject] call ace_gunbag_fnc_swapGunbagCallback |
15 | 15 | * |
16 | 16 | * Public: No |
17 | 17 | */ |
18 | 18 |
|
19 | 19 | params ["_unit", "_target"]; |
20 | | -private _currentWeapon = primaryWeapon _unit; //Get Current Weapon |
21 | | -private _gunbag = backpackContainer _target; |
22 | | - |
23 | | - |
24 | | -//---Set up current weapon for storing |
25 | | -private _currentWeaponState = [_unit, _currentWeapon] call EFUNC(common,getWeaponState); //Gets weapon attachments |
26 | 20 |
|
27 | | -/* |
28 | | - * example return value _state |
29 | | - * [["","","optic_Aco",""],["arifle_MX_GL_ACO_F","GL_3GL_F"],["30Rnd_65x39_caseless_mag","1Rnd_HE_Grenade_shell"],[30,1]] |
30 | | - */ |
| 21 | +// Set up current weapon for storing |
| 22 | +private _gunbag = backpackContainer _target; |
| 23 | +private _currentItems = (getUnitLoadout _unit) select 0; |
31 | 24 |
|
32 | | -_currentWeaponState params ["_currentWeaponItems", "", "_currentWeaponMagazines", "_currentWeaponAmmo"]; //Extract Weapon Attachments to separate arrays |
| 25 | +private _currentMagazines = _currentItems select [4, 2]; |
| 26 | +_currentItems deleteRange [4, 2]; |
33 | 27 |
|
34 | | -private _currentWeaponMass = [_currentWeapon, _currentWeaponItems, _currentWeaponMagazines] call FUNC(calculateMass); |
| 28 | +private _currentWeapon = _currentItems deleteAt 0; |
35 | 29 |
|
36 | | -{ |
37 | | - _currentWeaponMagazines set [_forEachIndex, [_x, _currentWeaponAmmo select _forEachIndex]]; |
38 | | -} forEach _currentWeaponMagazines; |
| 30 | +private _currentMass = [_currentWeapon, _currentItems, _currentMagazines apply {_x select 0}] call FUNC(calculateMass); |
39 | 31 |
|
40 | | -//---Set up weapon in gunbag |
41 | | -private _newWeaponState = _gunbag getVariable [QGVAR(gunbagWeapon), []]; |
| 32 | +// Set up weapon in gunbag |
| 33 | +private _newState = _gunbag getVariable [QGVAR(gunbagWeapon), []]; |
42 | 34 |
|
43 | | -if (_newWeaponState isEqualTo []) exitWith { |
| 35 | +if (_newState isEqualTo []) exitWith { |
44 | 36 | [LLSTRING(empty)] call EFUNC(common,displayTextStructured); |
45 | 37 | }; |
46 | 38 |
|
47 | | -_newWeaponState params ["_newWeapon", "_newWeaponItems", "_newWeaponMagazines"]; |
| 39 | +_newState params ["_newWeapon", "_newItems", "_newMagazines"]; |
48 | 40 |
|
49 | | -//---Swap Weapons |
| 41 | +// Swap Weapons |
50 | 42 | _unit removeWeapon _currentWeapon; |
51 | | -_unit addWeapon _newWeapon; |
52 | | - |
53 | | -// Game will auto add magazines from player's inventory, put these back in player inventory as they will be overwritten |
54 | | -([_unit, _newWeapon] call EFUNC(common,getWeaponState)) params ["", "", "_addedMags", "_addedAmmo"]; |
55 | | -{ |
56 | | - if (((_x select 0) != "") && {(_addedMags select _forEachIndex) != ""}) then { |
57 | | - TRACE_2("Re-adding mag",_x,_addedMags select _forEachIndex); |
58 | | - _unit addMagazine [_addedMags select _forEachIndex, _addedAmmo select _forEachIndex]; |
59 | | - }; |
60 | | -} forEach _newWeaponMagazines; |
61 | 43 |
|
62 | | -removeAllPrimaryWeaponItems _unit; |
| 44 | +[_unit, _newWeapon, true, _newMagazines] call EFUNC(common,addWeapon); |
63 | 45 |
|
| 46 | +// Add attachments |
64 | 47 | { |
65 | | - _unit addWeaponItem [_newWeapon, _x]; |
66 | | -} forEach (_newWeaponItems + _newWeaponMagazines); |
| 48 | + _unit addWeaponItem [_newWeapon, _x, true]; |
| 49 | +} forEach (_newItems select {_x != ""}); |
67 | 50 |
|
68 | 51 | _unit selectWeapon _newWeapon; |
69 | 52 |
|
70 | | -_newWeaponMagazines = _newWeaponMagazines apply {_x select 0}; |
| 53 | +private _newMass = [_newWeapon, _newItems, _newMagazines apply {_x select 0}] call FUNC(calculateMass); |
71 | 54 |
|
72 | | -private _newWeaponMass = [_newWeapon, _newWeaponItems, _newWeaponMagazines] call FUNC(calculateMass); |
| 55 | +// Update virtual load |
| 56 | +[_target, _gunbag, _currentMass - _newMass] call EFUNC(movement,addLoadToUnitContainer); |
73 | 57 |
|
74 | | -// update virtual load |
75 | | -[_target, _gunbag, _currentWeaponMass - _newWeaponMass] call EFUNC(movement,addLoadToUnitContainer); |
76 | | -_gunbag setVariable [QGVAR(gunbagWeapon), [_currentWeapon, _currentWeaponItems, _currentWeaponMagazines], true]; //Replace weapon in gunbag |
| 58 | +// Replace weapon in gunbag |
| 59 | +_gunbag setVariable [QGVAR(gunbagWeapon), [_currentWeapon, _currentItems, _currentMagazines], true]; |
0 commit comments