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 Backpack on Chest #722

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions addons/backpack_on_chest/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\tac\addons\backpack_on_chest
27 changes: 27 additions & 0 deletions addons/backpack_on_chest/ACE_Arsenal_Actions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class ace_arsenal_actions {
class ADDON {
displayName = CSTRING(DisplayName);
condition = QUOTE((_this select 0) call FUNC(canMovePack) && {backpack (_this select 0) != '' || {(_this select 0) call FUNC(chestpack) != ''}});
scopeEditor = 0;
tabs[] = {5};
class GVAR(chestpack) {
condition = QUOTE((_this select 0) call FUNC(chestpack) != '');
textStatement = QUOTE(getText (configFile >> 'CfgVehicles' >> (_this select 0) call FUNC(chestpack) >> 'displayName'));
};
class GVAR(onChest) {
label = CSTRING(OnChest);
condition = QUOTE((_this select 0) call FUNC(canMovePack) && {backpack (_this select 0) != ''} && {(_this select 0) call FUNC(chestpack) == ''});
statement = QUOTE((_this select 0) call FUNC(actionOnChest));
};
class GVAR(onBack) {
label = CSTRING(OnBack);
condition = QUOTE((_this select 0) call FUNC(canMovePack) && {backpack (_this select 0) == ''} && {(_this select 0) call FUNC(chestpack) != ''});
statement = QUOTE((_this select 0) call FUNC(actionOnBack));
};
class GVAR(swap) {
label = CSTRING(Swap);
condition = QUOTE((_this select 0) call FUNC(canMovePack) && {backpack (_this select 0) != ''} && {(_this select 0) call FUNC(chestpack) != ''});
statement = QUOTE((_this select 0) call FUNC(actionSwap));
};
};
};
17 changes: 17 additions & 0 deletions addons/backpack_on_chest/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
40 changes: 40 additions & 0 deletions addons/backpack_on_chest/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class GVAR(onChest) {
displayName = CSTRING(OnChest);
condition = QUOTE([_player] call FUNC(canMovePack) && {!(backpack _player isEqualTo '') && (([_player] call FUNC(chestpack)) isEqualTo '')});
exceptions[] = {"isNotInside"};
statement = QUOTE([_player] call FUNC(actionOnChest));
showDisabled = 0;
priority = 2.5;
icon = QPATHTOF(ui\onchest_ca.paa);
};
class GVAR(onBack) : GVAR(onChest) {
displayName = CSTRING(OnBack);
condition = QUOTE([_player] call FUNC(canMovePack) && {(backpack _player isEqualTo '') && !(([_player] call FUNC(chestpack)) isEqualTo '')});
statement = QUOTE([_player] call FUNC(actionOnBack));
icon = QPATHTOF(ui\onback_ca.paa);
};
class GVAR(swap) : GVAR(onChest) {
displayName = CSTRING(Swap);
condition = QUOTE([_player] call FUNC(canMovePack) && {!(backpack _player isEqualTo '') && !(([_player] call FUNC(chestpack)) isEqualTo '')});
statement = QUOTE([_player] call FUNC(actionSwap));
icon = QPATHTOF(ui\swap_ca.paa);
};
class GVAR(lower) : GVAR(onChest) {
displayName = CSTRING(lower);
condition = QUOTE([_player] call FUNC(canLower));
statement = QUOTE([_player] call FUNC(actionLower));
};
class GVAR(cutLoweringLine) : GVAR(onChest) {
displayName = CSTRING(cutLoweringLine);
condition = QUOTE([_player] call FUNC(canCutLoweringLine));
statement = QUOTE([_player] call FUNC(actionCutLoweringLine));
};
};
};
};
};
8 changes: 8 additions & 0 deletions addons/backpack_on_chest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# About

Adds Backpack on Chest REDUX, with some minor reworks and optimisations

### Authors
- [mjc4wilton](https://github.com/mjc4wilton)
- [DerZade](https://github.com/DerZade)
- [MikeMF](https://github.com/Mike-MF)
33 changes: 33 additions & 0 deletions addons/backpack_on_chest/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PREP(actionCutLoweringLine);
PREP(actionLower);
PREP(actionOnBack);
PREP(actionSwap);
PREP(addChestpack);
PREP(addItemToChestpack);
PREP(addMagToChestpack);
PREP(arsenal_onButtonClick);
PREP(arsenal_opened);
PREP(arsenal_postInit);
PREP(arsenal_updateUI);
PREP(canAddItemToChestpack);
PREP(canCutLoweringLine);
PREP(canLower);
PREP(canMovePack);
PREP(chestpack);
PREP(chestpackContainer);
PREP(chestpackLoadout);
PREP(chestpackToHolder);
PREP(chestpackVariables);
PREP(clearAllCargo);
PREP(clearAllItemsFromChestpack);
PREP(clearCargoBackpacks);
PREP(EHAnimDone);
PREP(EHGetIn);
PREP(EHGetOut);
PREP(EHHandleDisconnect);
PREP(EHKilled);
PREP(itemMass);
PREP(removeChestpack);
PREP(removeItemFromChestpack);
PREP(removeMagFromChestpack);
PREP(setBackpackLoadout);
46 changes: 46 additions & 0 deletions addons/backpack_on_chest/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "script_component.hpp"

[] call FUNC(arsenal_postInit);

// Clear inventory of a container
[QGVAR(clearAllCargo), {call FUNC(clearAllCargo)}] call CBA_fnc_addEventHandler;
// Clear inventory of every backpack in a container
[QGVAR(clearCargoBackpacks), {call FUNC(clearCargoBackpacks)}] call CBA_fnc_addEventHandler;

// Backpack classnames which will be made invisible instead of being made a chestpack. Useful for items like the vanilla legstrap.
GVAR(exceptions) = [
"B_LegStrapBag_black_F",
"B_LegStrapBag_coyote_F",
"B_LegStrapBag_olive_F"
];

if (isServer) exitWith {};

[QGVAR(handleDisconnect), {
addMissionEventHandler ["HandleDisconnect", FUNC(EHHandleDisconnect)];
}] call CBA_fnc_addEventHandler;

// holding the backpack have landed
[QGVAR(checkLandedPFH), {
params ["_ropeTop", "_holder"];

// PFH to check when the helper object _ropeTop and the WeaponHolderSimulated
[{
params ["_ropeTop", "_handle"];

if (speed _ropeTop < 1 && {((getPos _ropeTop) select 2) < 1}) exitWith {
deleteVehicle _ropeTop;
[_handle] call CBA_fnc_removePerFrameHandler;
};
}, 0, _ropeTop] call CBA_fnc_addPerFrameHandler;

[{
params ["_holder", "_handle"];
if (speed _holder < 1 && {getPos _holder # 2 < 1}) exitWith {
private _pos = getPos _holder;
_pos set [2, 0];
_holder setPos _pos;
[_handle] call CBA_fnc_removePerFrameHandler;
};
}, 0, _holder] call CBA_fnc_addPerFrameHandler;
}] call CBA_fnc_addEventHandler;
8 changes: 8 additions & 0 deletions addons/backpack_on_chest/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "script_component.hpp"

ADDON = false;

#include "XEH_PREP.hpp"
#include "initSettings.inc.sqf"

ADDON = true;
3 changes: 3 additions & 0 deletions addons/backpack_on_chest/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
19 changes: 19 additions & 0 deletions addons/backpack_on_chest/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"tac_main"};
author = ECSTRING(main,Author);
authors[] = {"DerZade", "mjc4wilton", "MikeMF"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "ACE_Arsenal_Actions.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
33 changes: 33 additions & 0 deletions addons/backpack_on_chest/functions/fnc_EHAnimDone.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "..\script_component.hpp"
/*
* Author: DerZade, mjc4wilton
* Triggered by AnimDone-Eventhandler
*
* Arguments:
* 0: unit <OBJECT>
* 1: animtaion <STRING>
*
* Return Value:
* Nothing
*
* Example:
* _this call tac_backpack_on_chest_fnc_EHAnimDone;
*
* Public: No
*/
params ["_unit","_anim"];

if (isNil "_unit") exitWith {
ERROR("No proper argument(s) given.");
};

private _chestpack = [_unit] call FUNC(chestpackContainer);
private _chestpackClass = [_unit] call FUNC(chestpack);

// freefall
if ((animationState _unit) find "halofreefall_" isEqualTo 0) then {
if !(_chestpackClass in GVAR(exceptions)) then {
_chestpack attachTo [_unit,[0,-0.4,0.05],"pelvis"];
_chestpack setVectorDirAndUp [[0,0,1],[0,1,0]];
};
};
36 changes: 36 additions & 0 deletions addons/backpack_on_chest/functions/fnc_EHGetIn.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "..\script_component.hpp"
/*
* Author: DerZade, mjc4wilton
* Triggered by GetInMan-Eventhandler
*
* Arguments:
* 0: unit <OBJECT>
* 1: position <STRING>
* 2: vehicle <OBJECT>
* 3: turret path <ARRAY>
*
* Return Value:
* Nothing
*
* Example:
* _this call tac_backpack_on_chest_fnc_EHGetIn;
*
* Public: No
*/
params ["_unit","_position","_veh"];

if (isNil "_unit" || isNil "_veh") exitWith {
ERROR("No proper argument(s) given.");
};

private _chestpack = [_unit] call FUNC(chestpackContainer);

if (_veh isKindOf "ParachuteBase") then {
_chestpack attachTo [_veh, [0, -0.03, -0.5]];
_chestpack setVectorDirAndUp [[-0.25, -1, 0], [0, 0, 1]];
_chestpack hideObjectGlobal false;
} else {
detach _chestpack;
hideObjectGlobal _chestpack;
_chestpack setPos [-10000, -10000, -100];
};
37 changes: 37 additions & 0 deletions addons/backpack_on_chest/functions/fnc_EHGetOut.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "..\script_component.hpp"
/*
* Author: DerZade, mjc4wilton
* Triggered by GetOutMan-Eventhandler
*
* Arguments:
* 0: unit <OBJECT>
* 1: position <STRING>
* 2: vehicle <OBJECT>
* 3: turret path <ARRAY>
*
* Return Value:
* Nothing
*
* Example:
* _this call tac_backpack_on_chest_fnc_EHGetOut;
*
* Public: No
*/
params ["_unit","_position","_veh"];

if (isNil "_unit" || isNil "_veh") exitWith {
ERROR("No proper argument(s) given.");
};

private _chestpack = [_unit] call FUNC(chestpackContainer);
private _chestpackClass = [_unit] call FUNC(chestpack);

if !(_chestpackClass in GVAR(exceptions)) then {
_chestpack attachTo [_unit, [0,-0.03,-0.5], "pelvis"];
_chestpack setVectorDirAndUp [[-0.25,-1,0], [0,0,1]];
_chestpack hideObjectGlobal false;
};

if (GVAR(walk)) then {
[_unit, "forceWalk", "BackpackOnChest", true] call ACEFUNC(common,statusEffect_set);
};
28 changes: 28 additions & 0 deletions addons/backpack_on_chest/functions/fnc_EHHandleDisconnect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "..\script_component.hpp"
/*
* Author: DerZade, mjc4wilton, MikeMF
* Triggered by HandleDisconnect-Eventhandler on Server.
* Handles deleting the chestpack of old units form disconnected players.
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* _this call tac_backpack_on_chest_fnc_EHHandleDisconnect;
*
* Public: Yes
*/
params ["_unit", "_id", "_uid", "_name"];

if ([_unit] call FUNC(chestpack) isEqualTo "") exitWith {};

[{
params ["_unit"];
private _container = _unit call FUNC(chestpackContainer);
if (!alive _unit) then {
deleteVehicle _container;
};
}, _unit, 1.5] call CBA_fnc_waitAndExecute;
38 changes: 38 additions & 0 deletions addons/backpack_on_chest/functions/fnc_EHKilled.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "..\script_component.hpp"
/*
* Author: DerZade, mjc4wilton, Ampersand
* Triggered by Killed-Eventhandler
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [player] call tac_backpack_on_chest_fnc_EHKilled;
*
* Public: No
*/

params ["_unit"];

private _chestpack = [_unit] call FUNC(chestpack);
private _chestpackLoadout = [_unit] call FUNC(chestpackLoadout);
private _chestpackVariables = [_unit] call FUNC(chestpackVariables);

private _holder = createVehicle ["WeaponHolderSimulated", (getPos _unit), [], 0, "CAN_COLLIDE"];

// add pack
_holder addBackpackCargoGlobal [_chestpack, 1];
private _backpack = firstBackpack _holder;

[_backpack, _chestpackLoadout] call FUNC(setBackpackLoadout);

// add variables
{
_backpack setVariable [(_x select 0), (_x select 1), true];
} forEach _chestpackVariables;

// remove the backpack from the dead unit
[_unit] call FUNC(removeChestpack);
Loading
Loading