diff --git a/addons/common/XEH_postInit.sqf b/addons/common/XEH_postInit.sqf index 1b84ff2fd6..4e11391753 100644 --- a/addons/common/XEH_postInit.sqf +++ b/addons/common/XEH_postInit.sqf @@ -19,12 +19,12 @@ //Status Effect EHs: [QGVAR(setStatusEffect), {_this call FUNC(statusEffect_set)}] call CBA_fnc_addEventHandler; -["forceWalk", false, ["ace_advanced_fatigue", "ACE_SwitchUnits", "ACE_Attach", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_Trenches", "ace_medical_fracture"]] call FUNC(statusEffect_addType); +["forceWalk", false, ["ace_advanced_fatigue", "ACE_SwitchUnits", "ACE_Attach", "ace_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_Sandbag", "ACE_refuel", "ACE_rearm", "ACE_Trenches", "ace_medical_fracture"]] call FUNC(statusEffect_addType); ["blockSprint", false, ["ace_advanced_fatigue", "ace_dragging", "ace_medical_fracture"]] call FUNC(statusEffect_addType); ["setCaptive", true, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered)]] call FUNC(statusEffect_addType); ["blockDamage", false, ["fixCollision", "ACE_cargo"]] call FUNC(statusEffect_addType); ["blockEngine", false, ["ACE_Refuel"]] call FUNC(statusEffect_addType); -["blockThrow", false, ["ACE_Attach", "ACE_concertina_wire", "ACE_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_rearm", "ACE_refuel", "ACE_Sandbag", "ACE_Trenches", "ACE_tripod"]] call FUNC(statusEffect_addType); +["blockThrow", false, ["ACE_Attach", "ACE_concertina_wire", "ace_dragging", "ACE_Explosives", "ACE_Ladder", "ACE_rearm", "ACE_refuel", "ACE_Sandbag", "ACE_Trenches", "ACE_tripod"]] call FUNC(statusEffect_addType); ["setHidden", true, ["ace_unconscious"]] call FUNC(statusEffect_addType); ["blockRadio", false, [QEGVAR(captives,Handcuffed), QEGVAR(captives,Surrendered), "ace_unconscious"]] call FUNC(statusEffect_addType); ["blockSpeaking", false, ["ace_unconscious"]] call FUNC(statusEffect_addType); diff --git a/addons/dragging/XEH_PREP.hpp b/addons/dragging/XEH_PREP.hpp index b04c15e7ec..5e85c1abba 100644 --- a/addons/dragging/XEH_PREP.hpp +++ b/addons/dragging/XEH_PREP.hpp @@ -3,6 +3,7 @@ PREP(canCarry); PREP(canDrag); PREP(canDrop); PREP(canDrop_carry); +PREP(canRun_carry); PREP(carryObject); PREP(carryObjectPFH); PREP(dragObject); diff --git a/addons/dragging/XEH_postInit.sqf b/addons/dragging/XEH_postInit.sqf index 41b0cf0754..6f7d6001c6 100644 --- a/addons/dragging/XEH_postInit.sqf +++ b/addons/dragging/XEH_postInit.sqf @@ -33,6 +33,43 @@ if (isNil QGVAR(maxWeightCarryRun)) then { // display event handler ["MouseZChanged", {_this select 1 call FUNC(handleScrollWheel)}] call CBA_fnc_addDisplayHandler; +[QGVAR(carryingContainerClosed), { + params ["_container", "_owner"]; + TRACE_2("carryingContainerClosed EH",_container,_owner); + if !(_owner getVariable [QGVAR(isCarrying), false]) exitWith { ERROR_1("not carrying - %1",_this) }; + + private _weight = 0; + if !(_container getVariable [QGVAR(ignoreWeightCarry), false]) then { + _weight = [_container] call FUNC(getWeight); + }; + + // drop the object if overweight + if (_weight > ACE_maxWeightCarry) exitWith { + [_owner, _container] call FUNC(dropObject_carry); + }; + private _canRun = [_weight] call FUNC(canRun_carry); + + // force walking based on weight + [_owner, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set); + [_owner, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set); +}] call CBA_fnc_addEventHandler; + +[QGVAR(draggingContainerClosed), { + params ["_container", "_owner"]; + TRACE_2("draggingContainerClosed EH",_container,_owner); + if !(_owner getVariable [QGVAR(isDragging), false]) exitWith { ERROR_1("not dragging - %1",_this) }; + + private _weight = 0; + if !(_container getVariable [QGVAR(ignoreWeightDrag), false]) then { + _weight = [_container] call FUNC(getWeight); + }; + + // drop the object if overweight + if (_weight > ACE_maxWeightDrag) exitWith { + [_owner, _container] call FUNC(dropObject); + }; +}] call CBA_fnc_addEventHandler; + //@todo Captivity? //Add Keybind: diff --git a/addons/dragging/functions/fnc_canRun_carry.sqf b/addons/dragging/functions/fnc_canRun_carry.sqf new file mode 100644 index 0000000000..c7385cd121 --- /dev/null +++ b/addons/dragging/functions/fnc_canRun_carry.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + * Author: LinkIsGrim + * Check if weight can be carried while running + * + * Arguments: + * 0: Weight + * + * Return Value: + * Can the weight be carried while running? + * + * Example: + * [500] call ace_dragging_fnc_canRun_carry + * + * Public: No + */ + +params ["_weight"]; + +GVAR(allowRunWithLightweight) && {_weight <= GVAR(maxWeightCarryRun)} diff --git a/addons/dragging/functions/fnc_dragObject.sqf b/addons/dragging/functions/fnc_dragObject.sqf index 499bcc8b36..99380659ce 100644 --- a/addons/dragging/functions/fnc_dragObject.sqf +++ b/addons/dragging/functions/fnc_dragObject.sqf @@ -74,7 +74,7 @@ GVAR(currentHeightChange) = 0; private _UAVCrew = _target call EFUNC(common,getVehicleUAVCrew); // fixes not being able to move when in combat pace -[_unit, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set); +[_unit, "forceWalk", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); if (_UAVCrew isNotEqualTo []) then { {_target deleteVehicleCrew _x} count _UAVCrew; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 175c2bc4e8..84b7adfb21 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -51,7 +51,7 @@ if (_target isKindOf "CAManBase") then { _unit removeWeapon "ACE_FakePrimaryWeapon"; -[_unit, "blockThrow", "ACE_dragging", false] call EFUNC(common,statusEffect_set); +[_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); // prevent object from flipping inside buildings if (_inBuilding) then { @@ -83,7 +83,7 @@ if (_target getVariable [QGVAR(isUAV), false]) then { }; // fixes not being able to move when in combat pace -[_unit, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set); +[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); // reset mass private _mass = _target getVariable [QGVAR(originalMass), 0]; diff --git a/addons/dragging/functions/fnc_dropObject_carry.sqf b/addons/dragging/functions/fnc_dropObject_carry.sqf index 606e85a090..0b43873e79 100644 --- a/addons/dragging/functions/fnc_dropObject_carry.sqf +++ b/addons/dragging/functions/fnc_dropObject_carry.sqf @@ -55,9 +55,9 @@ if (_previousWeaponIndex != -1) then { _unit action ["SwitchWeapon", _unit, _unit, _previousWeaponIndex]; }; -[_unit, "forceWalk", "ACE_dragging", false] call EFUNC(common,statusEffect_set); -[_unit, "blockSprint", "ACE_dragging", false] call EFUNC(common,statusEffect_set); -[_unit, "blockThrow", "ACE_dragging", false] call EFUNC(common,statusEffect_set); +[_unit, "forceWalk", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); +[_unit, "blockSprint", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); +[_unit, "blockThrow", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set); // prevent object from flipping inside buildings if (_inBuilding) then { diff --git a/addons/dragging/functions/fnc_getWeight.sqf b/addons/dragging/functions/fnc_getWeight.sqf index ad81661748..2603584151 100644 --- a/addons/dragging/functions/fnc_getWeight.sqf +++ b/addons/dragging/functions/fnc_getWeight.sqf @@ -2,7 +2,7 @@ /* * Author: L-H, edited by commy2, rewritten by joko // Jonas, re-rewritten by mharis001 * Returns the weight of the given object. - * Weight is calculated from the object's mass and its current inventory. + * Weight is calculated from the object's mass, its current inventory, and PhysX mass if applicable. * * Arguments: * 0: Object @@ -20,11 +20,14 @@ params ["_object"]; private _weight = loadAbs _object; -// Add the mass of the object itself -// The container object is generally of type SupplyX and has mass of zero -_weight = _weight + getNumber (configOf _object >> "mass"); +if !(GVAR(skipContainerWeight)) then { + // Add the mass of the object itself + // getMass handles PhysX mass, this should be 0 for SupplyX containers and WeaponHolders + // Use originalMass in case we're checking weight for a carried object + _weight = _weight + ((_object getVariable [QGVAR(originalMass), getMass _object])); +}; -// Contents of backpacks get counted twice (see https://github.com/acemod/ACE3/pull/8457#issuecomment-1062522447) +// Contents of backpacks get counted twice (https://github.com/acemod/ACE3/pull/8457#issuecomment-1062522447 and https://feedback.bistudio.com/T167469) // This is a workaround until that is fixed on BI's end { _x params ["", "_container"]; diff --git a/addons/dragging/functions/fnc_setCarryable.sqf b/addons/dragging/functions/fnc_setCarryable.sqf index 6ec0abb466..ab909e58b4 100644 --- a/addons/dragging/functions/fnc_setCarryable.sqf +++ b/addons/dragging/functions/fnc_setCarryable.sqf @@ -46,6 +46,15 @@ if (_type in _initializedClasses) exitWith {}; _initializedClasses pushBack _type; GVAR(initializedClasses_carry) = _initializedClasses; +[_type, "ContainerClosed", { + params ["_object"]; + private _owner = _object getVariable [QEGVAR(common,owner), objNull]; + TRACE_2("ContainerClosed-carry",_object,_owner); + if (isNull _owner) exitWith {}; + if (_object isNotEqualTo (_owner getVariable [QGVAR(carriedObject), objNull])) exitWith {}; + [QGVAR(carryingContainerClosed), [_object, _owner], _owner] call CBA_fnc_targetEvent; +}, false] call CBA_fnc_addClassEventHandler; + private _icon = [QUOTE(PATHTOF(UI\icons\box_carry.paa)), QUOTE(PATHTOF(UI\icons\person_carry.paa))] select (_object isKindOf "Man"); private _carryAction = [QGVAR(carry), localize LSTRING(Carry), _icon, {[_player, _target] call FUNC(startCarry)}, {[_player, _target] call FUNC(canCarry)}] call EFUNC(interact_menu,createAction); diff --git a/addons/dragging/functions/fnc_setDraggable.sqf b/addons/dragging/functions/fnc_setDraggable.sqf index 99729ebd63..84e966562a 100644 --- a/addons/dragging/functions/fnc_setDraggable.sqf +++ b/addons/dragging/functions/fnc_setDraggable.sqf @@ -46,6 +46,16 @@ if (_type in _initializedClasses) exitWith {}; _initializedClasses pushBack _type; GVAR(initializedClasses) = _initializedClasses; +[_type, "ContainerClosed", { + params ["_object"]; + private _owner = _object getVariable [QEGVAR(common,owner), objNull]; + TRACE_2("ContainerClosed-drag",_object,_owner); + if (isNull _owner) exitWith {}; + if (_object isNotEqualTo (_owner getVariable [QGVAR(draggedObject), objNull])) exitWith {}; + [QGVAR(draggingContainerClosed), [_object, _owner], _owner] call CBA_fnc_targetEvent; +}, false] call CBA_fnc_addClassEventHandler; + + private _icon = [QUOTE(PATHTOF(UI\icons\box_drag.paa)), QUOTE(PATHTOF(UI\icons\person_drag.paa))] select (_object isKindOf "Man"); private _dragAction = [QGVAR(drag), localize LSTRING(Drag), _icon, {[_player, _target] call FUNC(startDrag)}, {[_player, _target] call FUNC(canDrag)}] call EFUNC(interact_menu,createAction); diff --git a/addons/dragging/functions/fnc_startCarry.sqf b/addons/dragging/functions/fnc_startCarry.sqf index ded6df45d3..747cb16d00 100644 --- a/addons/dragging/functions/fnc_startCarry.sqf +++ b/addons/dragging/functions/fnc_startCarry.sqf @@ -22,10 +22,13 @@ TRACE_2("params",_unit,_target); private _weight = [_target] call FUNC(getWeight); // exempt from weight check if object has override variable set -if (!GETVAR(_target,GVAR(ignoreWeightCarry),false) && { - _weight > GETMVAR(ACE_maxWeightCarry,1E11) -}) exitWith { - // exit if object weight is over global var value +private _weight = 0; +if !(_target getVariable [QGVAR(ignoreWeightCarry), false]) then { + _weight = [_target] call FUNC(getWeight); +}; + +// exit if object weight is over global var value +if (_weight > GETMVAR(ACE_maxWeightCarry,1E11)) exitWith { [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); }; @@ -58,23 +61,18 @@ if (_target isKindOf "CAManBase") then { _unit action ["SwitchWeapon", _unit, _unit, 299]; [_unit, "AmovPercMstpSnonWnonDnon", 0] call EFUNC(common,doAnimation); - // objects other than containers have calculated weight == 0 so we use getMass - if (-1 == ["ReammoBox_F", "WeaponHolder", "WeaponHolderSimulated"] findIf {_target isKindOf _x}) then { - _weight = getMass _target; - }; - if (_weight > GVAR(maxWeightCarryRun)) then { - [_unit, "forceWalk", "ACE_dragging", true] call EFUNC(common,statusEffect_set); - } else { - [_unit, "blockSprint", "ACE_dragging", true] call EFUNC(common,statusEffect_set); - }; + private _canRun = [_weight] call FUNC(canRun_carry); + // only force walking if we're overweight + [_unit, "forceWalk", QUOTE(ADDON), !_canRun] call EFUNC(common,statusEffect_set); + [_unit, "blockSprint", QUOTE(ADDON), _canRun] call EFUNC(common,statusEffect_set); + }; -[_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set); +[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); // prevent multiple players from accessing the same object [_unit, _target, true] call EFUNC(common,claim); - // prevents draging and carrying at the same time _unit setVariable [QGVAR(isCarrying), true, true]; diff --git a/addons/dragging/functions/fnc_startDrag.sqf b/addons/dragging/functions/fnc_startDrag.sqf index 31159a2b62..d8db0258fc 100644 --- a/addons/dragging/functions/fnc_startDrag.sqf +++ b/addons/dragging/functions/fnc_startDrag.sqf @@ -20,11 +20,13 @@ params ["_unit", "_target"]; TRACE_2("params",_unit,_target); // exempt from weight check if object has override variable set -if (!GETVAR(_target,GVAR(ignoreWeightDrag),false) && { - private _weight = [_target] call FUNC(getWeight); - _weight > GETMVAR(ACE_maxWeightDrag,1E11) -}) exitWith { - // exit if object weight is over global var value +private _weight = 0; +if !(_target getVariable [QGVAR(ignoreWeightDrag), false]) then { + _weight = [_target] call FUNC(getWeight); +}; + +// exit if object weight is over global var value +if (_weight > GETMVAR(ACE_maxWeightDrag,1E11)) exitWith { [localize LSTRING(UnableToDrag)] call EFUNC(common,displayTextStructured); }; @@ -57,7 +59,7 @@ if !(GVAR(dragAndFire)) then { // Save the weapon so we can monitor if it changes _unit setVariable [QGVAR(currentWeapon), currentWeapon _unit]; -[_unit, "blockThrow", "ACE_dragging", true] call EFUNC(common,statusEffect_set); +[_unit, "blockThrow", QUOTE(ADDON), true] call EFUNC(common,statusEffect_set); // prevent multiple players from accessing the same object [_unit, _target, true] call EFUNC(common,claim); diff --git a/addons/dragging/initSettings.sqf b/addons/dragging/initSettings.sqf index b33dbab3f7..ef537d8bce 100644 --- a/addons/dragging/initSettings.sqf +++ b/addons/dragging/initSettings.sqf @@ -6,3 +6,21 @@ true, false ] call CBA_fnc_addSetting; + +[ + QGVAR(allowRunWithLightweight), + "CHECKBOX", + [LSTRING(allowRunWithLightweight_DisplayName), LSTRING(allowRunWithLightweight_Description)], + localize LSTRING(SettingsName), + true, + true +] call CBA_fnc_addSetting; + +[ + QGVAR(skipContainerWeight), + "CHECKBOX", + [LSTRING(skipContainerWeight_DisplayName), LSTRING(skipContainerWeight_Description)], + localize LSTRING(SettingsName), + false, + true +] call CBA_fnc_addSetting; diff --git a/addons/dragging/stringtable.xml b/addons/dragging/stringtable.xml index b8b86f2464..2c5b39d9f3 100644 --- a/addons/dragging/stringtable.xml +++ b/addons/dragging/stringtable.xml @@ -147,5 +147,17 @@ 允许玩家在拖动时开火。 플레이어가 무기를 끄는 동안에 무기를 사용할 수 있게합니다. + + Allow Running with Lightweight Objects + + + Allow the player to run when carrying lightweight objects. + + + Skip Object Weight + + + Determines whether object's weight is added onto weight calculations. +