diff --git a/addons/common/CfgVehicles.hpp b/addons/common/CfgVehicles.hpp index 69d6f99924..7c5c9295f9 100644 --- a/addons/common/CfgVehicles.hpp +++ b/addons/common/CfgVehicles.hpp @@ -140,4 +140,10 @@ class CfgVehicles { isBicycle = 1; XEH_DISABLED; }; + + class Bag_Base; + class ACE_FakeBackpack: Bag_Base { + scope = 1; + maximumLoad = 1E6; + }; }; diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index 639070cc92..ff06c1c3e3 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -146,8 +146,10 @@ PREP(resetAllDefaults); PREP(restoreVariablesJIP); PREP(runAfterSettingsInit); PREP(sanitizeString); +PREP(selectWeaponMode); PREP(sendRequest); PREP(serverLog); +PREP(setAllGear); PREP(setCaptivityStatus); PREP(setDefinedVariable); PREP(setDisableUserInputStatus); @@ -221,6 +223,10 @@ PREP(getDoorTurrets); PREP(getTurretsFFV); PREP(getTurretsOther); +// missing inventory commands +PREP(binocularMagazine); +PREP(removeBinocularMagazine); + // ACE_Debug PREP(exportConfig); PREP(getChildren); diff --git a/addons/common/functions/fnc_binocularMagazine.sqf b/addons/common/functions/fnc_binocularMagazine.sqf new file mode 100644 index 0000000000..db88e29488 --- /dev/null +++ b/addons/common/functions/fnc_binocularMagazine.sqf @@ -0,0 +1,35 @@ +/* + * Author: commy2 + * Returns the magazine of the units rangefinder. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Magazine of the units binocular + * + * Example: + * [player] call ace_common_fnc_binocularMagazine + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit"]; + +private ["_binocular", "_muzzle", "_mode", "_magazine"]; + +_binocular = binocular _unit; + +if (_binocular == "") exitWith {""}; + +_muzzle = currentMuzzle _unit; +_mode = currentWeaponMode _unit; + +_unit selectWeapon _binocular; + +_magazine = currentMagazine _unit; + +[_unit, _muzzle, _mode] call FUNC(selectWeaponMode); + +_magazine diff --git a/addons/common/functions/fnc_dropBackpack.sqf b/addons/common/functions/fnc_dropBackpack.sqf index fc2b0bba64..26c902a057 100644 --- a/addons/common/functions/fnc_dropBackpack.sqf +++ b/addons/common/functions/fnc_dropBackpack.sqf @@ -18,7 +18,7 @@ private ["_backpackObject", "_holder"]; _backpackObject = backpackContainer _unit; -_unit addBackpack "Bag_Base"; +_unit addBackpack "ACE_FakeBackpack"; removeBackpack _unit; objectParent _backpackObject // return diff --git a/addons/common/functions/fnc_getAllGear.sqf b/addons/common/functions/fnc_getAllGear.sqf index 97b28fddd6..715966b176 100644 --- a/addons/common/functions/fnc_getAllGear.sqf +++ b/addons/common/functions/fnc_getAllGear.sqf @@ -25,6 +25,7 @@ * 16: Handgun Magazines * 17: Assigned Items (map, compass, watch, etc.) * 18: Binoculars + * 19: Binocular Magazine (E.g. Laserbatteries) * * Public: Yes * @@ -44,6 +45,7 @@ if (isNull _unit) exitWith {[ "", ["","","",""], [], "", ["","","",""], [], [], + "", "" ]}; @@ -57,5 +59,6 @@ if (isNull _unit) exitWith {[ secondaryWeapon _unit, secondaryWeaponItems _unit, secondaryWeaponMagazine _unit, handgunWeapon _unit, handgunItems _unit, handgunMagazine _unit, assignedItems _unit, - binocular _unit + binocular _unit, + [_unit] call FUNC(binocularMagazine) ] diff --git a/addons/common/functions/fnc_removeBinocularMagazine.sqf b/addons/common/functions/fnc_removeBinocularMagazine.sqf new file mode 100644 index 0000000000..3d2252390a --- /dev/null +++ b/addons/common/functions/fnc_removeBinocularMagazine.sqf @@ -0,0 +1,30 @@ +/* + * Author: commy2 + * Removes the magazine of the units rangefinder. + * + * Arguments: + * 0: Unit + * + * Return Value: + * None + * + * Example: + * [player] call ace_common_fnc_removeBinocularMagazine + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit"]; + +private ["_binocular", "_selectBinocular"]; + +_binocular = binocular _unit; + +_selectBinocular = currentWeapon _unit == _binocular; + +_unit addWeapon _binocular; + +if (_selectBinocular) then { + _unit selectWeapon _binocular; +}; diff --git a/addons/common/functions/fnc_selectWeaponMode.sqf b/addons/common/functions/fnc_selectWeaponMode.sqf new file mode 100644 index 0000000000..f255c63e98 --- /dev/null +++ b/addons/common/functions/fnc_selectWeaponMode.sqf @@ -0,0 +1,31 @@ +/* + * Author: commy2 + * Unit selects given muzzle and weapon mode. + * + * Arguments: + * 0: unit + * 1: weapon or Muzzle + * 2: weapon Mode + * + * Return Value: + * Successful? + * + * Example: + * [player, primaryWeapon player, "FullAuto"] call ace_common_fnc_selectWeaponMode + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit", "_muzzle", "_mode"]; + +local _index = 0; + +while { + _index < 100 && {currentMuzzle _unit != _muzzle || {currentWeaponMode _unit != _mode}} +} do { + _unit action ["SwitchWeapon", _unit, _unit, _index]; + _index = _index + 1; +}; + +_index < 100 // return diff --git a/addons/common/functions/fnc_setAllGear.sqf b/addons/common/functions/fnc_setAllGear.sqf new file mode 100644 index 0000000000..e25045a685 --- /dev/null +++ b/addons/common/functions/fnc_setAllGear.sqf @@ -0,0 +1,172 @@ +/* + * Author: bux578, commy2 + * Applies gear to unit. + * + * Arguments: + * 0: Unit + * 1: All Gear based on return value of ACE_common_fnc_getAllGear + * 2: Remove all attachments from weapons? (default: false) + * 3: Remove all items from prefilled backpacks? (default: false) + * + * Return Value: + * None + * + * Example: + * [player, gear_array, true, true] call ace_common_fnc_setAllGear + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit", "_allGear", ["_clearAttachments", false], ["_clearBackpack", false]]; + +// remove all starting gear of a player +removeAllWeapons _unit; +removeGoggles _unit; +removeHeadgear _unit; +removeVest _unit; +removeUniform _unit; +removeAllAssignedItems _unit; +removeBackpack _unit; + +_allGear params [ + "_headgear", "_goggles", + "_uniform", "_uniformitems", + "_vest", "_vestitems", + "_backpack", "_backpackitems", + "_primaryweapon", "_primaryweaponitems", "_primaryweaponmagazine", + "_secondaryweapon", "_secondaryweaponitems", "_secondaryweaponmagazine", + "_handgunweapon", "_handgunweaponitems", "_handgunweaponmagazine", + "_assigneditems", + "_binocular", + "_binocularmagazine" +]; + +// start restoring the items +if (_headgear != "") then {_unit addHeadgear _headgear}; +if (_goggles != "") then {_unit addGoggles _goggles}; + +// ensure all weapons being loaded +_unit addBackpack "ACE_FakeBackpack"; + +// primaryWeapon +if (_primaryweapon != "") then { + { + _unit addMagazine _x; + false + } count _primaryweaponmagazine; + + _unit addWeapon _primaryweapon; + + if (_clearAttachments) then { + removeAllPrimaryWeaponItems _unit; + }; + + { + if (_x != "") then { + _unit addPrimaryWeaponItem _x; + }; + false + } count _primaryweaponitems; +}; + +// secondaryWeapon +if (_secondaryweapon != "") then { + { + _unit addMagazine _x; + false + } count _secondaryweaponmagazine; + + _unit addWeapon _secondaryweapon; + + if (_clearAttachments) then { + //removeAllSecondaryWeaponItems _unit; + { + _unit removeSecondaryWeaponItem _x; + false + } count secondaryWeaponItems _unit; + }; + + { + if (_x != "") then { + _unit addSecondaryWeaponItem _x; + }; + false + } count _secondaryweaponitems; +}; + +// handgun +if (_handgunweapon != "") then { + { + _unit addMagazine _x; + false + } count _handgunweaponmagazine; + + _unit addWeapon _handgunweapon; + + if (_clearAttachments) then { + removeAllHandgunItems _unit; + }; + + { + if (_x != "") then { + _unit addHandgunItem _x; + }; + false + } count _handgunweaponitems; +}; + +// binocular +_unit addWeapon _binocular; +_unit addMagazine _binocularmagazine; + +// done with dummy backpack. now remove +removeBackpack _unit; + +// uniform +if (_uniform != "") then { + _unit forceAddUniform _uniform; +}; + +{ + _unit addItemToUniform _x; + false +} count _uniformitems; + +// vest +if (_vest != "") then { + _unit addVest _vest; +}; + +{ + _unit addItemToVest _x; + false +} count _vestitems; + +// backpack +if (_backpack != "") then { + _unit addBackpack _backpack; + + if (_clearBackpack) then { + local _backpackObject = unitBackpack _unit; + + clearMagazineCargoGlobal _backpackObject; + clearWeaponCargoGlobal _backpackObject; + clearItemCargoGlobal _backpackObject; + }; + + { + _unit addItemToBackpack _x; + false + } count _backpackitems; +}; + +// assigned items +_assignedItems deleteAt (_assignedItems find _binocular); + +{ + _unit linkItem _x; + false +} count _assignedItems; + +nil diff --git a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf index de7cdefd70..c371c8d5a5 100644 --- a/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf +++ b/addons/disposable/functions/fnc_takeLoadedATWeapon.sqf @@ -35,7 +35,7 @@ if (isClass _config && {getText (_config >> "ACE_UsedTube") != ""} && {getNumber _unit removeMagazines _magazine; if (backpack _unit == "") then { - _unit addBackpack "Bag_Base"; + _unit addBackpack "ACE_FakeBackpack"; _unit removeWeapon _launcher; _unit addMagazine _magazine; _didAdd = _magazine in (magazines _unit); diff --git a/addons/respawn/functions/fnc_handleKilled.sqf b/addons/respawn/functions/fnc_handleKilled.sqf index 200e3c98c8..cd1ad33491 100644 --- a/addons/respawn/functions/fnc_handleKilled.sqf +++ b/addons/respawn/functions/fnc_handleKilled.sqf @@ -24,7 +24,7 @@ if (ACE_player == _unit) then { if (GVAR(SavePreDeathGear)) then { GVAR(unitGear) = [_unit] call EFUNC(common,getAllGear); - GVAR(unitGear) pushBack [currentWeapon _unit, currentMuzzle _unit, currentWeaponMode _unit]; + GVAR(unitGear) append [currentWeapon _unit, currentMuzzle _unit, currentWeaponMode _unit]; }; }; diff --git a/addons/respawn/functions/fnc_restoreGear.sqf b/addons/respawn/functions/fnc_restoreGear.sqf index e8a512e127..d01e45dd50 100644 --- a/addons/respawn/functions/fnc_restoreGear.sqf +++ b/addons/respawn/functions/fnc_restoreGear.sqf @@ -1,5 +1,5 @@ /* - * Author: bux578 + * Author: bux578, commy2 * Restores previously saved gear. * * Arguments: @@ -10,150 +10,16 @@ * None * * Example: - * [ACE_Player, stored_allGear] call ace_respawn_fnc_restoreGear + * [ACE_Player, stored_allGear, active_weapon_muzzle_and_mode] call ace_respawn_fnc_restoreGear * * Public: No */ #include "script_component.hpp" -params ["_unit", "_allGear"]; +params ["_unit", "_allGear", "_activeWeaponAndMuzzle"]; -// remove all starting gear of a player -removeAllWeapons _unit; -removeGoggles _unit; -removeHeadgear _unit; -removeVest _unit; -removeUniform _unit; -removeAllAssignedItems _unit; -clearAllItemsFromBackpack _unit; -removeBackpack _unit; - -_allGear params [ - "_headgear", "_goggles", - "_uniform", "_uniformitems", - "_vest", "_vestitems", - "_backpack", "_backpackitems", - "_primaryweapon", "_primaryweaponitems", "_primaryweaponmagazine", - "_secondaryweapon", "_secondaryweaponitems", "_secondaryweaponmagazine", - "_handgunweapon", "_handgunweaponitems", "_handgunweaponmagazine", - "_assigneditems", "_binocular", - "_activeWeaponAndMuzzle" -]; - -// start restoring the items -if (_headgear != "") then {_unit addHeadgear _headgear}; -if (_goggles != "") then {_unit addGoggles _goggles}; -if (_uniform != "") then {_unit forceAddUniform _uniform}; -if (_vest != "") then {_unit addVest _vest}; - -{ - _unit addItemToUniform _x; - false -} count _uniformitems; - -{ - _unit addItemToVest _x; - false -} count _vestitems; - -private "_flagRemoveDummyBag"; - -if (format ["%1", _backpack] != "") then { - _unit addBackpack _backpack; - - // make sure the backpack is empty. Some bags are prefilled by config - private "_backpackObject"; - _backpackObject = unitBackpack _unit; - - clearMagazineCargoGlobal _backpackObject; - clearWeaponCargoGlobal _backpackObject; - clearItemCargoGlobal _backpackObject; - - { - _unit addItemToBackpack _x; - false - } count _backpackitems; - - _flagRemoveDummyBag = false; -} else { - // dummy backpack to ensure mags being loaded - _unit addBackpack "Bag_Base"; - - _flagRemoveDummyBag = true; -}; - -// primaryWeapon -if ((_primaryweapon != "") && {_primaryweapon != "ACE_FakePrimaryWeapon"}) then { - { - _unit addMagazine _x; - false - } count _primaryweaponmagazine; - - _unit addWeapon _primaryweapon; - - { - if (_x != "") then { - _unit addPrimaryWeaponItem _x; - }; - false - } count _primaryweaponitems; -}; - -// secondaryWeapon -if (_secondaryweapon != "") then { - { - _unit addMagazine _x; - false - } count _secondaryweaponmagazine; - - _unit addWeapon _secondaryweapon; - - { - if (_x != "") then { - _unit addSecondaryWeaponItem _x; - }; - false - } count _secondaryweaponitems; -}; - -// handgun -if (_handgunweapon != "") then { - { - _unit addMagazine _x; - false - } count _handgunweaponmagazine; - - _unit addWeapon _handgunweapon; - - { - if (_x != "") then { - _unit addHandgunItem _x; - }; - false - } count _handgunweaponitems; -}; - -// remove dummy bagpack -if (_flagRemoveDummyBag) then { - removeBackpack _unit; -}; - -_assignedItems deleteAt (_assignedItems find _binocular); - -// items -{_unit linkItem _x; false} count _assignedItems; - -_unit addWeapon _binocular; - -// reload Laserdesignator -// we assume that if the unit had a Laserdesignator it probably had batteries for it -if ("Laserdesignator" in assignedItems _unit) then { - _unit selectWeapon "Laserdesignator"; - - if (currentMagazine _unit == "") then { - _unit addMagazine "Laserbatteries"; - }; -}; +// restore all gear +[_unit, _allGear, true, true] call EFUNC(common,setAllGear); // restore the last active weapon, muzzle and weaponMode _activeWeaponAndMuzzle params ["_activeWeapon", "_activeMuzzle", "_activeWeaponMode"]; @@ -171,8 +37,7 @@ if ( }; if (currentWeapon _unit != "") then { - private "_index"; - _index = 0; + local _index = 0; while { _index < 100 && {currentWeaponMode _unit != _activeWeaponMode}