From bed7edcf23aee1e4706871ab6cb6fe6df00e569a Mon Sep 17 00:00:00 2001 From: freghar Date: Wed, 18 May 2016 00:14:20 +0200 Subject: [PATCH] initial import Signed-off-by: freghar --- COPYING.txt | 4 + addons/chestpack/config.cpp | 103 ++++++++++++++++++ .../chestpack/functions/fn_removeBackpack.sqf | 12 ++ .../functions/fn_removeChestpack.sqf | 13 +++ addons/chestpack/functions/fn_setBackpack.sqf | 9 ++ .../chestpack/functions/fn_setChestpack.sqf | 26 +++++ mod.cpp | 4 + 7 files changed, 171 insertions(+) create mode 100644 COPYING.txt create mode 100644 addons/chestpack/config.cpp create mode 100644 addons/chestpack/functions/fn_removeBackpack.sqf create mode 100644 addons/chestpack/functions/fn_removeChestpack.sqf create mode 100644 addons/chestpack/functions/fn_setBackpack.sqf create mode 100644 addons/chestpack/functions/fn_setChestpack.sqf create mode 100644 mod.cpp diff --git a/COPYING.txt b/COPYING.txt new file mode 100644 index 0000000..3cfbcd4 --- /dev/null +++ b/COPYING.txt @@ -0,0 +1,4 @@ +Copyright 2016 Freghar (https://forums.bistudio.com/user/1115862-freghar/) + +Content licensed under CC BY 4.0 +https://creativecommons.org/licenses/by/4.0/ diff --git a/addons/chestpack/config.cpp b/addons/chestpack/config.cpp new file mode 100644 index 0000000..1cca7d6 --- /dev/null +++ b/addons/chestpack/config.cpp @@ -0,0 +1,103 @@ +class CfgPatches +{ + class Chestpack + { + units[] = {}; + weapons[] = {}; + //requiredAddons[] = {}; + requiredAddons[] = {"ace_interact_menu"}; + }; +}; + +class CfgVehicles { + class Man; + class CAManBase : Man { + class ACE_SelfActions { + class ACE_Equipment { + class Chestpack_onChest { + displayName = "Backpack on Chest"; + statement = "[(_this select 0), ((_this select 0) call Chestpack_fnc_removeBackpack)] call Chestpack_fnc_setChestpack;"; + condition = "isNil {(_this select 0) getVariable ""Chestpack_pack""} && !isNull unitBackpack (_this select 0)"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + class Chestpack_onBack { + displayName = "Chestpack on Back"; + statement = "[(_this select 0), ((_this select 0) call Chestpack_fnc_removeChestpack)] call Chestpack_fnc_setBackpack;"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""} && isNull unitBackpack (_this select 0)"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + /*class Chestpack_onGround { + displayName = "Chestpack on Ground"; + statement = "call Chestpack_onGround"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""}"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + };*/ + class Chestpack_swapPacks { + displayName = "Swap Chest/Back packs"; + statement = "private _back = (_this select 0) call Chestpack_fnc_removeBackpack; [(_this select 0), ((_this select 0) call Chestpack_fnc_removeChestpack)] call Chestpack_fnc_setBackpack; [(_this select 0), _back] call Chestpack_fnc_setChestpack;"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""} && !isNull unitBackpack (_this select 0)"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + }; + }; + class ACE_Actions { + class ACE_MainActions { + /* corpse or unconscious */ + class Chestpack_onChest { + displayName = "Backpack on Chest"; + statement = "[(_this select 0), ((_this select 0) call Chestpack_fnc_removeBackpack)] call Chestpack_fnc_setChestpack;"; + condition = "isNil {(_this select 0) getVariable ""Chestpack_pack""} && !isNull unitBackpack (_this select 0) && {!alive (_this select 0) || (_this select 0) getVariable [""ACE_isUnconscious"", false]}"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + class Chestpack_onBack { + displayName = "Chestpack on Back"; + statement = "[(_this select 0), ((_this select 0) call Chestpack_fnc_removeChestpack)] call Chestpack_fnc_setBackpack;"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""} && isNull unitBackpack (_this select 0) && {!alive (_this select 0) || (_this select 0) getVariable [""ACE_isUnconscious"", false]}"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + /*class Chestpack_onGround { + displayName = "Chestpack on Ground"; + statement = "call Chestpack_onGround"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""} && {!alive (_this select 0) || (_this select 0) getVariable [""ACE_isUnconscious"", false]}"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + };*/ + class Chestpack_swapPacks { + displayName = "Swap Chest/Back packs"; + statement = "private _back = (_this select 0) call Chestpack_fnc_removeBackpack; [(_this select 0), ((_this select 0) call Chestpack_fnc_removeChestpack)] call Chestpack_fnc_setBackpack; [(_this select 0), _back] call Chestpack_fnc_setChestpack;"; + condition = "!isNil {(_this select 0) getVariable ""Chestpack_pack""} && !isNull unitBackpack (_this select 0) && {!alive (_this select 0) || (_this select 0) getVariable [""ACE_isUnconscious"", false]}"; + exceptions[] = {"isNotInside", "isNotSwimming"}; + }; + }; + }; + /* vanilla Actions */ + /*class UserActions { + class Chestpack_onChest {}; + class Chestpack_onBack {}; + };*/ + }; + /*class Reammobox; + class Bag_base : Reammobox { + class ACE_Actions { + class ACE_MainActions { + class Chestpack_onChest { + displayName = "Groundpack on Chest"; + statement = "call Chestpack_fromGround"; + condition = "!isNil {(_this select 1) getVariable ""Chestpack_pack""}"; + }; + }; + }; + };*/ +}; + +class CfgFunctions { + class Chestpack { + class All { + file = "\chestpack\functions"; + //class init { postInit = 1; }; + class setChestpack; + class removeChestpack; + class setBackpack; + class removeBackpack; + }; + }; +}; diff --git a/addons/chestpack/functions/fn_removeBackpack.sqf b/addons/chestpack/functions/fn_removeBackpack.sqf new file mode 100644 index 0000000..b9d2908 --- /dev/null +++ b/addons/chestpack/functions/fn_removeBackpack.sqf @@ -0,0 +1,12 @@ +/* delete the backpack of '_unit', returning its class and contents, + * as getUnitLoadout provides it */ + +params ["_unit"]; + +private _packinfo = getUnitLoadout _unit; +if (count _packinfo > 0) then { + /* https://community.bistudio.com/wiki/Talk:getUnitLoadout */ + _packinfo = _packinfo select 5; + removeBackpackGlobal _unit; +}; +_packinfo; diff --git a/addons/chestpack/functions/fn_removeChestpack.sqf b/addons/chestpack/functions/fn_removeChestpack.sqf new file mode 100644 index 0000000..88cb714 --- /dev/null +++ b/addons/chestpack/functions/fn_removeChestpack.sqf @@ -0,0 +1,13 @@ +/* delete the chestpack of '_unit', returning its class and contents, + * as getUnitLoadout provides it */ + +params ["_unit"]; + +private _chestpack = _unit getVariable "Chestpack_pack"; +if (isNil "_chestpack") exitWith {}; +_unit setVariable ["Chestpack_pack", nil, true]; +_unit forceWalk false; + +_chestpack params ["_obj", "_packinfo"]; +deleteVehicle _obj; +_packinfo; diff --git a/addons/chestpack/functions/fn_setBackpack.sqf b/addons/chestpack/functions/fn_setBackpack.sqf new file mode 100644 index 0000000..91d3584 --- /dev/null +++ b/addons/chestpack/functions/fn_setBackpack.sqf @@ -0,0 +1,9 @@ +/* add backpack to '_unit', according to getUnitLoadout-formatted + * '_backinfo' (backpack array), saved by fn_delBackpack */ + +params ["_unit", "_packinfo"]; + +private _loadout = getUnitLoadout _unit; +/* https://community.bistudio.com/wiki/Talk:getUnitLoadout */ +_loadout set [5, _packinfo]; +_unit setUnitLoadout _loadout; diff --git a/addons/chestpack/functions/fn_setChestpack.sqf b/addons/chestpack/functions/fn_setChestpack.sqf new file mode 100644 index 0000000..4befc4d --- /dev/null +++ b/addons/chestpack/functions/fn_setChestpack.sqf @@ -0,0 +1,26 @@ +/* add chestpack to '_unit', according to getUnitLoadout-formatted + * '_backinfo' (backpack array), saved by fn_delBackpack */ + +params ["_unit", "_packinfo"]; +_packinfo params ["_packclass"]; + +/* sometimes has .p3d, sometimes doesn't, starts with leading \, etc. */ +//getText (configFile >> "CfgVehicles" >> _packclass >> "model"); + +private _temp = _packclass createVehicleLocal [0,0,0]; +private _model = (getModelInfo _temp) select 1; +deleteVehicle _temp; + +private _obj = createSimpleObject [_model, [0,0,0]]; +_obj attachTo [_unit, [0.02,-0.04,-0.3], "pelvis"]; + +_unit forceWalk true; +_unit setVariable ["Chestpack_pack", [_obj, _packinfo], true]; + + +/* +obj = createVehicle ["GroundWeaponHolder", player, [], 0, "CAN_COLLIDE"]; +obj addBackpackCargoGlobal [(typeof unitbackpack player), 1]; +obj attachTo [player, [0.02,-0.04,-0.3], "pelvis"]; +obj setVectorUp [0,1,0]; +*/ diff --git a/mod.cpp b/mod.cpp new file mode 100644 index 0000000..1da3de5 --- /dev/null +++ b/mod.cpp @@ -0,0 +1,4 @@ +name = "Chestpack"; +author = "Freghar"; +hideName = 0; +overview = "Yet another mod for moving backpacks on one's chest/belly.";