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

Gunbag - Add weapon swapping #7713

Merged
merged 21 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
be4c034
Gunbag Update
mjc4wilton May 16, 2020
d4a537c
Update stringtable.xml
mjc4wilton May 16, 2020
1b814b4
Update addons/gunbag/functions/fnc_swapWeapon.sqf
mjc4wilton May 17, 2020
3d04ae2
Update addons/gunbag/functions/fnc_swapWeaponCallback.sqf
mjc4wilton May 17, 2020
e59cd4c
Update addons/gunbag/functions/fnc_swapWeaponCallback.sqf
mjc4wilton May 17, 2020
e664bd8
Update stringtable.xml
mjc4wilton May 17, 2020
cfef49c
Update French translation
mjc4wilton May 18, 2020
8dfa157
Remove non-English translations
mjc4wilton May 19, 2020
16fc7ed
Add CBA setting to enable weapon switching (Default false)
mjc4wilton May 20, 2020
ebc2cf2
Fixed variables and updated names for consistancy
mjc4wilton May 20, 2020
b7e096a
Convert from ACE Settings to CBA Settings
mjc4wilton May 21, 2020
345377e
Fix stringtable.xml indentation
mjc4wilton May 21, 2020
50821f6
Update addons/gunbag/initSettings.sqf
mjc4wilton May 22, 2020
f548531
Update addons/gunbag/initSettings.sqf
mjc4wilton May 22, 2020
8589b23
Update addons/gunbag/functions/fnc_swapGunbagCallback.sqf
mjc4wilton May 23, 2020
9c0c180
Update addons/gunbag/functions/fnc_swapGunbag.sqf
mjc4wilton May 23, 2020
24e06b4
Update addons/gunbag/functions/fnc_swapGunbagCallback.sqf
mjc4wilton May 23, 2020
6f4b658
Update addons/gunbag/initSettings.sqf
mjc4wilton May 23, 2020
ad9b6b4
Update addons/gunbag/initSettings.sqf
mjc4wilton Jun 14, 2020
070b2e9
Update initSettings.sqf
mjc4wilton Jun 14, 2020
ce936ab
Update CfgVehicles.hpp
mjc4wilton Jun 14, 2020
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
14 changes: 14 additions & 0 deletions addons/gunbag/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ class CfgVehicles {
showDisabled = 0;
icon = QPATHTOF(ui\gunbag_icon_ca.paa);
};
class GVAR(weaponSwap) {
displayName = CSTRING(SwapGunbag);
condition = QUOTE(([_target] call FUNC(hasGunbag)) && {[ARR_2(_player,_target)] call FUNC(canInteract) == 2} && (GVAR(swapGunbagEnabled)));
mjc4wilton marked this conversation as resolved.
Show resolved Hide resolved
statement = QUOTE([ARR_2(_player,_target)] call FUNC(swapGunbag));
showDisabled = 0;
icon = QPATHTOF(ui\gunbag_icon_ca.paa);
};
class GVAR(weaponOff) {
displayName = CSTRING(OffGunbag);
condition = QUOTE(([_target] call FUNC(hasGunbag)) && {[ARR_2(_player,_target)] call FUNC(canInteract) == 1});
Expand Down Expand Up @@ -41,6 +48,13 @@ class CfgVehicles {
showDisabled = 0;
icon = QPATHTOF(ui\gunbag_icon_ca.paa);
};
class GVAR(weaponSwap) {
displayName = CSTRING(SwapGunbag);
condition = QUOTE(([ARR_2(_player,_player)] call FUNC(canInteract) == 2) && (GVAR(swapGunbagEnabled)));
mjc4wilton marked this conversation as resolved.
Show resolved Hide resolved
statement = QUOTE([ARR_2(_player,_player)] call FUNC(swapGunbag));
showDisabled = 0;
icon = QPATHTOF(ui\gunbag_icon_ca.paa);
};
class GVAR(weaponOff) {
displayName = CSTRING(OffGunbag);
condition = QUOTE([ARR_2(_player,_player)] call FUNC(canInteract) == 1);
Expand Down
2 changes: 2 additions & 0 deletions addons/gunbag/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

PREP(toGunbag);
PREP(toGunbagCallback);
PREP(swapGunbag);
PREP(swapGunbagCallback);
PREP(offGunbag);
PREP(offGunbagCallback);
PREP(status);
Expand Down
2 changes: 2 additions & 0 deletions addons/gunbag/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

#include "initSettings.sqf"

// restore gunbag info after respawn
["CAManBase", "respawn", {
[{
Expand Down
6 changes: 4 additions & 2 deletions addons/gunbag/functions/fnc_canInteract.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* 1: Target <OBJECT>
*
* Return Value:
* -1: can't interact 0: empty gunbag 1: full gunbag <NUMBER>
* -1: can't interact 0: empty gunbag 1: full gunbag 2: full gunbag & has primary <NUMBER>
*
* Example:
* _canInteract = [player, target] call ace_gunbag_fnc_canInteract
Expand All @@ -29,5 +29,7 @@ if ((_gunbag getVariable [QGVAR(gunbagWeapon), []]) isEqualTo [] && {_weapon !=
if (!((_gunbag getVariable [QGVAR(gunbagWeapon), []]) isEqualTo []) && {_weapon == ""}) then {
_result = 1;
};

if (!((_gunbag getVariable [QGVAR(gunbagWeapon), []]) isEqualTo []) && {_weapon != ""}) then {
_result = 2;
};
_result
34 changes: 34 additions & 0 deletions addons/gunbag/functions/fnc_swapGunbag.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/*
* Author: Ir0n1E and mjc4wilton
* Swap primary weapon and weapon in gunbag.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, target] call ace_gunbag_fnc_swapGunbag
*
* Public: No
*/

params ["_unit", "_target"];

private _gunbag = backpackContainer _target;

_unit call EFUNC(common,goKneeling);

// play sound
if (["ace_backpacks"] call EFUNC(common,isModLoaded)) then {
[_target, _gunbag] call EFUNC(backpacks,backpackOpened);
};

[(PROGRESSBAR_TIME * 1.5), _this, {
jokoho48 marked this conversation as resolved.
Show resolved Hide resolved
(_this select 0) call FUNC(swapGunbagCallback)
}, {}, LLSTRING(swapGunbag),
{(_this select 0) call FUNC(canInteract) == 2}
] call EFUNC(common,progressBar);
76 changes: 76 additions & 0 deletions addons/gunbag/functions/fnc_swapGunbagCallback.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "script_component.hpp"
/*
* Author: Ir0n1E and mjc4wilton
* Swap primary weapon and weapon in gunbag.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player, target] call ace_gunbag_fnc_swapGunbag
*
* Public: No
*/

params ["_unit", "_target"];
private _currentWeapon = primaryWeapon _unit; //Get Current Weapon
private _gunbag = backpackContainer _target;


//---Set up current weapon for storing
private _currentWeaponState = [_unit, _currentWeapon] call EFUNC(common,getWeaponState); //Gets weapon attachments

/*
* example return value _state
* [["","","optic_Aco",""],["arifle_MX_GL_ACO_F","GL_3GL_F"],["30Rnd_65x39_caseless_mag","1Rnd_HE_Grenade_shell"],[30,1]]
*/

_currentWeaponState params ["_currentWeaponItems", "", "_currentWeaponMagazines", "_currentWeaponAmmo"]; //Extract Weapon Attachments to separate arrays

private _currentWeaponMass = [_currentWeapon, _currentWeaponItems, _currentWeaponMagazines] call FUNC(calculateMass);

{
_currentWeaponMagazines set [_forEachIndex, [_x, _currentWeaponAmmo select _forEachIndex]];
} forEach _currentWeaponMagazines;

//---Set up weapon in gunbag
private _newWeaponState = _gunbag getVariable [QGVAR(gunbagWeapon), []];

if (_newWeaponState isEqualTo []) exitWith {
[LLSTRING(empty)] call EFUNC(common,displayTextStructured);
};

_newWeaponState params ["_newWeapon", "_newWeaponItems", "_newWeaponMagazines"];

//---Swap Weapons
_unit removeWeapon _currentWeapon;
_unit addWeapon _newWeapon;

// Game will auto add magazines from player's inventory, put these back in player inventory as they will be overwritten
([_unit, _newWeapon] call EFUNC(common,getWeaponState)) params ["", "", "_addedMags", "_addedAmmo"];
{
if (((_x select 0) != "") && {(_addedMags select _forEachIndex) != ""}) then {
TRACE_2("Re-adding mag",_x,_addedMags select _forEachIndex);
_unit addMagazine [_addedMags select _forEachIndex, _addedAmmo select _forEachIndex];
};
} forEach _newWeaponMagazines;

removeAllPrimaryWeaponItems _unit;

{
_unit addWeaponItem [_newWeapon, _x];
} forEach (_newWeaponItems + _newWeaponMagazines);

_unit selectWeapon _newWeapon;

_newWeaponMagazines = _newWeaponMagazines apply {_x select 0};

private _newWeaponMass = [_newWeapon, _newWeaponItems, _newWeaponMagazines] call FUNC(calculateMass);

// update virtual load
[_target, _gunbag, _currentWeaponMass - _newWeaponMass] call EFUNC(movement,addLoadToUnitContainer);
_gunbag setVariable [QGVAR(gunbagWeapon), [_currentWeapon, _currentWeaponItems, _currentWeaponMagazines], true]; //Replace weapon in gunbag
9 changes: 9 additions & 0 deletions addons/gunbag/initSettings.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// CBA Settings [ADDON: ace_gunbag]:

[
QGVAR(swapGunbagEnabled), "CHECKBOX",
[LSTRING(SwapGunbagEnabled_DisplayName), LSTRING(SwapGunbagEnabled_Description)],
LSTRING(DisplayName_Settings),
mjc4wilton marked this conversation as resolved.
Show resolved Hide resolved
false, // default value
mjc4wilton marked this conversation as resolved.
Show resolved Hide resolved
true // isGlobal
] call CBA_fnc_addSetting;
25 changes: 25 additions & 0 deletions addons/gunbag/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
<Turkish>Silah Çantası (Tan)</Turkish>
<Spanish>Funda de arma (Tan)</Spanish>
</Key>
<Key ID="STR_ACE_Gunbag_DisplayName_Settings">
<English>ACE Gunbag</English>
<German>ACE Waffentasche</German>
<French>ACE Housse d'arme</French>
<Russian>ACE Чехол</Russian>
<Czech>ACE Pouzdro na zbraň</Czech>
<Japanese>ACE ガンバッグ</Japanese>
<Polish>ACE Torba na broń</Polish>
<Korean>ACE 총가방</Korean>
<Italian>ACE Borsa per Armi</Italian>
<Chinesesimp>ACE 枪袋</Chinesesimp>
<Chinese>ACE 槍袋</Chinese>
<Portuguese>ACE Bolsa de Arma</Portuguese>
<Turkish>ACE Silah Çantası</Turkish>
<Spanish>ACE Funda de arma</Spanish>
</Key>
<Key ID="STR_ACE_Gunbag_ToGunbag">
<English>Put weapon into gunbag</English>
<German>Lege Waffe in Waffentasche</German>
Expand All @@ -49,6 +65,15 @@
<Turkish>Silahını silah çantasına koy</Turkish>
<Spanish>Poner el arma en la funda</Spanish>
</Key>
<Key ID="STR_ACE_Gunbag_SwapGunbag">
<English>Exchange weapon in gunbag</English>
</Key>
<Key ID="STR_ACE_Gunbag_SwapGunbagEnabled_DisplayName">
<English>Enable Weapon Swap</English>
</Key>
<Key ID="STR_ACE_Gunbag_SwapGunbagEnabled_Description">
<English>Allows interaction to directly swap the primary weapon and stored weapon.</English>
</Key>
<Key ID="STR_ACE_Gunbag_OffGunbag">
<English>Get weapon out of gunbag</English>
<German>Hole Waffe aus Waffentasche</German>
Expand Down