2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2020-06-19 15:35:19 +00:00
|
|
|
/*
|
2024-06-05 13:22:19 +00:00
|
|
|
* Author: Ir0n1E, mjc4wilton
|
2020-06-19 15:35:19 +00:00
|
|
|
* Swap primary weapon and weapon in gunbag.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Target <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
2024-06-05 13:22:19 +00:00
|
|
|
* [player, cursorObject] call ace_gunbag_fnc_swapGunbagCallback
|
2020-06-19 15:35:19 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_unit", "_target"];
|
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Set up current weapon for storing
|
|
|
|
private _gunbag = backpackContainer _target;
|
|
|
|
private _currentItems = (getUnitLoadout _unit) select 0;
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
private _currentMagazines = _currentItems select [4, 2];
|
|
|
|
_currentItems deleteRange [4, 2];
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
private _currentWeapon = _currentItems deleteAt 0;
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
private _currentMass = [_currentWeapon, _currentItems, _currentMagazines apply {_x select 0}] call FUNC(calculateMass);
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Set up weapon in gunbag
|
|
|
|
private _newState = _gunbag getVariable [QGVAR(gunbagWeapon), []];
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
if (_newState isEqualTo []) exitWith {
|
2020-06-19 15:35:19 +00:00
|
|
|
[LLSTRING(empty)] call EFUNC(common,displayTextStructured);
|
|
|
|
};
|
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
_newState params ["_newWeapon", "_newItems", "_newMagazines"];
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Swap Weapons
|
2020-06-19 15:35:19 +00:00
|
|
|
_unit removeWeapon _currentWeapon;
|
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
[_unit, _newWeapon, true, _newMagazines] call EFUNC(common,addWeapon);
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Add attachments
|
2020-06-19 15:35:19 +00:00
|
|
|
{
|
2024-06-05 13:22:19 +00:00
|
|
|
_unit addWeaponItem [_newWeapon, _x, true];
|
|
|
|
} forEach (_newItems select {_x != ""});
|
2020-06-19 15:35:19 +00:00
|
|
|
|
|
|
|
_unit selectWeapon _newWeapon;
|
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
private _newMass = [_newWeapon, _newItems, _newMagazines apply {_x select 0}] call FUNC(calculateMass);
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Update virtual load
|
|
|
|
[_target, _gunbag, _currentMass - _newMass] call EFUNC(movement,addLoadToUnitContainer);
|
2020-06-19 15:35:19 +00:00
|
|
|
|
2024-06-05 13:22:19 +00:00
|
|
|
// Replace weapon in gunbag
|
|
|
|
_gunbag setVariable [QGVAR(gunbagWeapon), [_currentWeapon, _currentItems, _currentMagazines], true];
|