From 9432e5140334dc6745f000865595537b673a63f3 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Tue, 29 Oct 2019 09:06:12 +0100 Subject: [PATCH 01/24] Update fn_advancedSlingLoadingInit.sqf - Added a max lift able mass for a single cargo to be able to be lifted. Set to 8 times of the total lift capability of a helicopter - ASL_Rope_Set_Mass & ASL_Rope_Adjust_Mass changed definitions of private variables for performance --- .../functions/fn_advancedSlingLoadingInit.sqf | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 52ca116..aff917a 100644 --- a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -113,28 +113,26 @@ ASL_Get_Sling_Load_Points = { }; ASL_Rope_Set_Mass = { - private ["_obj","_mass"]; - _obj = [_this,0] call BIS_fnc_param; - _mass = [_this,1] call BIS_fnc_param; + private _obj = [_this,0] call BIS_fnc_param; + private _mass = [_this,1] call BIS_fnc_param; _obj setMass _mass; }; ASL_Rope_Adjust_Mass = { params ["_obj","_heli",["_ropes",[]]]; - private ["_mass","_lift","_originalMass","_heavyLiftMinLift"]; - _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - _originalMass = getMass _obj; - _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE",5000]; - if( _originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift ) then { - private ["_originalMassSet","_ends","_endDistance","_ropeLength"]; - _originalMassSet = (getMass _obj) == _originalMass; + private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + private _maxLiftableMass = _lift * 8; + private _originalMass = getMass _obj; + private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE",5000]; + if( _originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + private _originalMassSet = (getMass _obj) == _originalMass; while { _obj in (ropeAttachedObjects _heli) && _originalMassSet } do { { - _ends = ropeEndPosition _x; - _endDistance = (_ends select 0) distance (_ends select 1); - _ropeLength = ropeLength _x; + private _ends = ropeEndPosition _x; + private _endDistance = (_ends select 0) distance (_ends select 1); + private _ropeLength = ropeLength _x; if((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { - [[_obj, ((_lift)*0.8)],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; _originalMassSet = false; }; } forEach _ropes; @@ -147,7 +145,6 @@ ASL_Rope_Adjust_Mass = { }; }; - /* Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) for a specified vehicle From 8ba3ec54e645fa6dc257d67e5d90d7f4de32a66e Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 14 Feb 2020 11:28:38 +0100 Subject: [PATCH 02/24] Update fn_advancedSlingLoadingInit.sqf - Added a max lift able mass for a single cargo to be able to be lifted. Set to 8 times of the total lift capability of a helicopter - ASL_Rope_Set_Mass & ASL_Rope_Adjust_Mass changed definitions of private variables for performance - tried to clean up the code --- .../functions/fn_advancedSlingLoadingInit.sqf | 1889 ++++++++--------- 1 file changed, 914 insertions(+), 975 deletions(-) diff --git a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index aff917a..8015f69 100644 --- a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -12,1158 +12,1097 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ASL_Advanced_Sling_Loading_Install = { -// Prevent advanced sling loading from installing twice -if(!isNil "ASL_ROPE_INIT") exitWith {}; -ASL_ROPE_INIT = true; - -diag_log "Advanced Sling Loading Loading..."; - -ASL_Rope_Get_Lift_Capability = { - params ["_vehicle"]; - private ["_slingLoadMaxCargoMass"]; - _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); - if(_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = 4000; + // Prevent advanced sling loading from installing twice + if(!isNil "ASL_ROPE_INIT") exitWith {}; + ASL_ROPE_INIT = true; + + diag_log "Advanced Sling Loading Loading..."; + + ASL_Rope_Get_Lift_Capability = { + params ["_vehicle"]; + private ["_slingLoadMaxCargoMass"]; + _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + if (_slingLoadMaxCargoMass <= 0) then { + _slingLoadMaxCargoMass = 4000; + }; + _slingLoadMaxCargoMass; }; - _slingLoadMaxCargoMass; -}; -ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ - ["All", [-0.05, -0.05, -0.05]], - ["CUP_CH47F_base", [-0.05, -2, -0.05]], - ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], - ["RHS_CH_47F", [-0.75, -2.6, -0.75]], - ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], - ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] -]; - -ASL_Get_Sling_Load_Points = { - params ["_vehicle"]; - private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"]; - private ["_slingLoadPoints","_modelPoint","_modelPointASL","_surfaceIntersectStartASL","_surfaceIntersectEndASL","_surfaces","_intersectionASL","_intersectionObject"]; - _slingLoadPointsArray = []; - _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); - _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; - _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; - _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; - _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - - _slingLoadPointHeightOffset = 0; - { - if(_vehicle isKindOf (_x select 0)) then { - _slingLoadPointHeightOffset = (_x select 1); - }; - } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - - _slingLoadPoints = []; - { - _modelPoint = _x; - _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); - _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); - _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); - - // Determine if the surface intersection line crosses below ground level - // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces - // doesn't work if starting below ground level for some reason - // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection - - _la = ASLToAGL _surfaceIntersectStartASL; - _lb = ASLToAGL _surfaceIntersectEndASL; + ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ + ["All", [-0.05, -0.05, -0.05]], + ["CUP_CH47F_base", [-0.05, -2, -0.05]], + ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], + ["RHS_CH_47F", [-0.75, -2.6, -0.75]], + ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], + ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] + ]; + + ASL_Get_Sling_Load_Points = { + params ["_vehicle"]; + private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"]; + private ["_slingLoadPoints","_modelPoint","_modelPointASL","_surfaceIntersectStartASL","_surfaceIntersectEndASL","_surfaces","_intersectionASL","_intersectionObject"]; + _slingLoadPointsArray = []; + _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; + _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); + _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; + _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; + _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; + _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - if(_la select 2 < 0 && _lb select 2 > 0) then { - _n = [0,0,1]; - _p0 = [0,0,0.1]; - _l = (_la vectorFromTo _lb); - if((_l vectorDotProduct _n) != 0) then { - _d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n); - _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + _slingLoadPointHeightOffset = 0; + { + if (_vehicle isKindOf (_x select 0)) then { + _slingLoadPointHeightOffset = (_x select 1); }; - }; + } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; - _intersectionASL = []; + _slingLoadPoints = []; { - _intersectionObject = _x select 2; - if(_intersectionObject == _vehicle) exitWith { - _intersectionASL = _x select 0; + _modelPoint = _x; + _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); + _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); + _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); + + // Determine if the surface intersection line crosses below ground level + // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces + // doesn't work if starting below ground level for some reason + // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection + + _la = ASLToAGL _surfaceIntersectStartASL; + _lb = ASLToAGL _surfaceIntersectEndASL; + + if (_la select 2 < 0 && _lb select 2 > 0) then { + _n = [0, 0, 1]; + _p0 = [0, 0, 0.1]; + _l = (_la vectorFromTo _lb); + if ((_l vectorDotProduct _n) != 0) then { + _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n ) / (_l vectorDotProduct _n); + _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + }; }; - } forEach _surfaces; - if(count _intersectionASL > 0) then { - _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); - _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); - } else { - _slingLoadPoints pushBack []; - }; - } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - - if(count (_slingLoadPoints select 1) > 0) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if(count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0 ) then { - if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3 ) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; - if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3 ) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 1,_slingLoadPoints select 2]; + + _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; + _intersectionASL = []; + { + _intersectionObject = _x select 2; + if (_intersectionObject == _vehicle) exitWith { + _intersectionASL = _x select 0; + }; + } forEach _surfaces; + if (count _intersectionASL > 0) then { + _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); + _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); + } else { + _slingLoadPoints pushBack []; + }; + } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; + + if(count (_slingLoadPoints select 1) > 0) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; + if(count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { + if(((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 1, _slingLoadPoints select 2]; + }; }; - }; + }; }; + _slingLoadPointsArray; }; - _slingLoadPointsArray; -}; - -ASL_Rope_Set_Mass = { - private _obj = [_this,0] call BIS_fnc_param; - private _mass = [_this,1] call BIS_fnc_param; - _obj setMass _mass; -}; -ASL_Rope_Adjust_Mass = { - params ["_obj","_heli",["_ropes",[]]]; - private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - private _maxLiftableMass = _lift * 8; - private _originalMass = getMass _obj; - private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE",5000]; - if( _originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { - private _originalMassSet = (getMass _obj) == _originalMass; - while { _obj in (ropeAttachedObjects _heli) && _originalMassSet } do { - { - private _ends = ropeEndPosition _x; - private _endDistance = (_ends select 0) distance (_ends select 1); - private _ropeLength = ropeLength _x; - if((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { - [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - _originalMassSet = false; - }; - } forEach _ropes; - sleep 0.1; - }; - while { _obj in (ropeAttachedObjects _heli) } do { - sleep 0.5; - }; - [[_obj, _originalMass],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - }; -}; + ASL_Rope_Set_Mass = { + private _obj = [_this,0] call BIS_fnc_param; + private _mass = [_this,1] call BIS_fnc_param; + _obj setMass _mass; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Set_Mass) _obj: ", _obj, " _mass: ", _mass]; + }; -/* - Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Active_Ropes = { - params ["_vehicle"]; - private ["_activeRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; - _activeRopes = []; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; - _ropeIndex = 0; - _totalExistingRopes = count _existingRopes; - { - if(count _x > 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _activeRopes; -}; + ASL_Rope_Adjust_Mass = { + params ["_obj", "_heli", ["_ropes", []]]; + private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + private _maxLiftableMass = _lift * 8; // define a maximum mass, which can be lifted + private _originalMass = getMass _obj; + private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; + if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + private _originalMassSet = (getMass _obj) == _originalMass; + while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { + { + private _ends = ropeEndPosition _x; + private _endDistance = (_ends select 0) distance (_ends select 1); + private _ropeLength = ropeLength _x; + if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { + [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + _originalMassSet = false; + }; + } forEach _ropes; + sleep 0.1; + }; + while {_obj in (ropeAttachedObjects _heli)} do { + sleep 0.5; + }; + [[_obj, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + }; + }; -/* - Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Inactive_Ropes = { - params ["_vehicle"]; - private ["_inactiveRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; - _inactiveRopes = []; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; - _ropeIndex = 0; - _totalExistingRopes = count _existingRopes; - { - if(count _x == 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _inactiveRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _inactiveRopes; -}; + /* + Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle + */ + ASL_Get_Active_Ropes = { + params ["_vehicle"]; + private _activeRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front","Rear"], ["Front", "Center", "Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + { + if(count _x > 0) then { + private _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _activeRopes + }; -ASL_Get_Active_Ropes_With_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(!isNull _cargo) then { - _activeRopesWithCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithCargo; -}; + /* + Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle + */ + ASL_Get_Inactive_Ropes = { + params ["_vehicle"]; + private _inactiveRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front","Rear"], ["Front","Center","Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + { + if (count _x == 0) then { + private _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _inactiveRopes + }; -ASL_Get_Active_Ropes_Without_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithoutCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithoutCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(isNull _cargo) then { - _activeRopesWithoutCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithoutCargo; -}; + ASL_Get_Active_Ropes_With_Cargo = { + params ["_vehicle"]; + private _activeRopesWithCargo = []; + private _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + private _activeRopes = _this call ASL_Get_Active_Ropes; + { + private _cargo = _existingCargo select (_x select 0); + if(!isNull _cargo) then { + _activeRopesWithCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithCargo + }; -ASL_Get_Ropes = { - params ["_vehicle","_ropeIndex"]; - private ["_allRopes","_selectedRopes"]; - _selectedRopes = []; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _allRopes > _ropeIndex) then { - _selectedRopes = _allRopes select _ropeIndex; + ASL_Get_Active_Ropes_Without_Cargo = { + params ["_vehicle"]; + private _activeRopesWithoutCargo = []; + private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; + private _activeRopes = _this call ASL_Get_Active_Ropes; + { + private _cargo = _existingCargo select (_x select 0); + if (isNull _cargo) then { + _activeRopesWithoutCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithoutCargo }; - _selectedRopes; -}; + ASL_Get_Ropes = { + params ["_vehicle", "_ropeIndex"]; + private _selectedRopes = []; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + if(count _allRopes > _ropeIndex) then { + _selectedRopes = _allRopes select _ropeIndex; + }; + _selectedRopes + }; -ASL_Get_Ropes_Count = { - params ["_vehicle"]; - count (_vehicle getVariable ["ASL_Ropes",[]]); -}; + ASL_Get_Ropes_Count = { + params ["_vehicle"]; + count (_vehicle getVariable ["ASL_Ropes",[]]); + }; -ASL_Get_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_allCargo","_selectedCargo"]; - _selectedCargo = objNull; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - if(count _allCargo > _ropeIndex) then { - _selectedCargo = _allCargo select _ropeIndex; + ASL_Get_Cargo = { + params ["_vehicle", "_ropeIndex"]; + private _selectedCargo = objNull; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + if (count _allCargo > _ropeIndex) then { + _selectedCargo = _allCargo select _ropeIndex; + }; + _selectedCargo + }; + + ASL_Get_Ropes_And_Cargo = { + params ["_vehicle", "_ropeIndex"]; + private _selectedCargo = (_this call ASL_Get_Cargo); + private _selectedRopes = (_this call ASL_Get_Ropes); + [_selectedRopes, _selectedCargo]; }; - _selectedCargo; -}; - -ASL_Get_Ropes_And_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_selectedCargo","_selectedRopes"]; - _selectedCargo = (_this call ASL_Get_Cargo); - _selectedRopes = (_this call ASL_Get_Ropes); - [_selectedRopes, _selectedCargo]; -}; -ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName","_ropesIndexAndLabelArray",["_ropesLabel","Ropes"]]; - ASL_Show_Select_Ropes_Menu_Array = [[_title,false]]; - { - ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; - } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; -}; - -ASL_Extend_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 100 ) then { - { - ropeUnwind [_x, 3, 5, true]; - } forEach _existingRopes; + ASL_Show_Select_Ropes_Menu = { + params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", "Ropes"]]; + ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; + { + ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + } forEach _ropesIndexAndLabelArray; + ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; + }; + + ASL_Extend_Ropes = { + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + if (local _vehicle) then { + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= 100) then { + { + ropeUnwind [_x, 3, 5, true]; + } forEach _existingRopes; + }; }; + } else { + [_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Extend_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Extend_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Extend_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + ASL_Extend_Ropes_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Extend_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; + ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + }; }; }; }; -}; -ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + ASL_Extend_Ropes_Index_Action = { + params ["_ropeIndex"]; + private ["_vehicle","_canDeployRopes"]; + _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + }; }; -}; -ASL_Extend_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Extend_Ropes; -}; + ASL_Extend_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Extend_Ropes; + }; -ASL_Can_Extend_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; + ASL_Can_Extend_Ropes = { + params ["_vehicle"]; + // private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; + }; -ASL_Shorten_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 2 ) then { - _this call ASL_Release_Cargo; - } else { - { - if(_ropeLength >= 10) then { - ropeUnwind [_x, 3, -5, true]; - } else { - ropeUnwind [_x, 3, -1, true]; - }; - } forEach _existingRopes; + ASL_Shorten_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + // private ["_existingRopes"]; + private _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + _ropeLength = ropeLength (_existingRopes select 0); + if(_ropeLength <= 2 ) then { + _this call ASL_Release_Cargo; + } else { + { + if(_ropeLength >= 10) then { + ropeUnwind [_x, 3, -5, true]; + } else { + ropeUnwind [_x, 3, -1, true]; + }; + } forEach _existingRopes; + }; }; + } else { + [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Shorten_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Shorten_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + ASL_Shorten_Ropes_Action = { + // private ["_vehicle"]; + private _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Shorten_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; + ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + }; }; }; }; -}; -ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; + ASL_Shorten_Ropes_Index_Action = { + params ["_ropeIndex"]; + // private ["_vehicle"]; + private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; + }; }; -}; -ASL_Shorten_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Shorten_Ropes; -}; + ASL_Shorten_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Shorten_Ropes; + }; -ASL_Can_Shorten_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Release_Cargo = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropeIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - _this call ASL_Retract_Ropes; - } else { - [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + ASL_Can_Shorten_Ropes = { + params ["_vehicle"]; + // private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; }; -}; - -ASL_Release_Cargo_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Release_Cargo) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; + + ASL_Release_Cargo = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + // private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; + private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + private _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [_ropeIndex,objNull]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + _this call ASL_Retract_Ropes; } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; + [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + }; + }; + + ASL_Release_Cargo_Action = { + // private ["_vehicle"]; + private _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Release_Cargo) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; + ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; + }; }; }; }; -}; -ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + ASL_Release_Cargo_Index_Action = { + params ["_ropesIndex"]; + // private ["_vehicle"]; + private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + }; }; -}; -ASL_Release_Cargo_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Release_Cargo; -}; + ASL_Release_Cargo_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Release_Cargo; + }; -ASL_Can_Release_Cargo = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; + ASL_Can_Release_Cargo = { + params ["_vehicle"]; + // private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if((count _activeRopes) == 0) exitWith { false }; + true; + }; -ASL_Retract_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(isNull _existingCargo) then { - _this call ASL_Drop_Ropes; - { - [_x,_vehicle] spawn { - params ["_rope","_vehicle"]; - private ["_count"]; - _count = 0; - ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; + ASL_Retract_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + // private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; + private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + if(isNull _existingCargo) then { + _this call ASL_Drop_Ropes; + { + [_x,_vehicle] spawn { + params ["_rope","_vehicle"]; + private ["_count"]; + _count = 0; + ropeUnwind [_rope, 3, 0]; + while {(!ropeUnwound _rope) && _count < 20} do { + sleep 1; + _count = _count + 1; + }; + ropeDestroy _rope; }; - ropeDestroy _rope; - }; - } forEach _existingRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropeIndex,[]]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; - }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes",nil,true]; + } forEach _existingRopes; + private _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _allRopes set [_ropeIndex,[]]; + _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes",nil,true]; + }; + } else { + [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Retract_Ropes_Action = { - private ["_vehicle","_canRetractRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Retract_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + ASL_Retract_Ropes_Action = { + // private ["_vehicle","_canRetractRopes"]; + private ["_vehicle"]; + if(vehicle player == player) then { + _vehicle = cursorTarget; } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; + _vehicle = vehicle player; + }; + if([_vehicle] call ASL_Can_Retract_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; + ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; + }; }; }; }; -}; -ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Retract_Ropes; + ASL_Retract_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + [_vehicle, player, _ropesIndex] call ASL_Retract_Ropes; + }; }; -}; -ASL_Retract_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Retract_Ropes; - } else { - [vehicle player] call ASL_Can_Retract_Ropes; + ASL_Retract_Ropes_Action_Check = { + if (vehicle player == player) then { + [cursorTarget] call ASL_Can_Retract_Ropes; + } else { + [vehicle player] call ASL_Can_Retract_Ropes; + }; }; -}; -ASL_Can_Retract_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 30) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; + ASL_Can_Retract_Ropes = { + params ["_vehicle"]; + if (player distance _vehicle > 30) exitWith {false}; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if ((count _existingRopes) == 0) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if ((count _activeRopes) == 0) exitWith {false}; + true + }; -ASL_Deploy_Ropes = { - params ["_vehicle","_player",["_cargoCount",1],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_cargoRopes","_startLength","_slingLoadPoints"]; - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _existingRopes == 0) then { - if(count _slingLoadPoints == 0) exitWith { - [["Vehicle doesn't support cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - if(count _slingLoadPoints < _cargoCount) exitWith { - [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - _cargoRopes = []; - _cargo = []; - for "_i" from 0 to (_cargoCount-1) do - { - _cargoRopes pushBack []; - _cargo pushBack objNull; - }; - _vehicle setVariable ["ASL_Ropes",_cargoRopes,true]; - _vehicle setVariable ["ASL_Cargo",_cargo,true]; - for "_i" from 0 to (_cargoCount-1) do - { - [_vehicle,_player,_i] call ASL_Deploy_Ropes_Index; + ASL_Deploy_Ropes = { + params ["_vehicle", "_player", ["_cargoCount", 1], ["_ropeLength", 15]]; + if (local _vehicle) then { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) then { + if (count _slingLoadPoints == 0) exitWith { + [["Vehicle doesn't support cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; + }; + if (count _slingLoadPoints < _cargoCount) exitWith { + [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; + }; + private _cargoRopes = []; + private _cargo = []; + for "_i" from 0 to (_cargoCount-1) do { + _cargoRopes pushBack []; + _cargo pushBack objNull; + }; + _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; + _vehicle setVariable ["ASL_Cargo", _cargo, true]; + for "_i" from 0 to (_cargoCount-1) do { + [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; + }; + } else { + [["Vehicle already has cargo ropes deployed", false], "ASL_Hint", _player] call ASL_RemoteExec; }; } else { - [["Vehicle already has cargo ropes deployed", false],"ASL_Hint",_player] call ASL_RemoteExec; + [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Deploy_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Deploy_Ropes_Index = { - params ["_vehicle","_player",["_ropesIndex",0],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_existingRopesCount","_allRopes"]; - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if(count _existingRopes == 0) then { - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - { - ropeUnwind [_x, 5, _ropeLength]; - } forEach _cargoRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropesIndex,_cargoRopes]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + ASL_Deploy_Ropes_Index = { + params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; + if (local _vehicle) then { + private _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + if(count _existingRopes == 0) then { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + private _cargoRopes = []; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + { + ropeUnwind [_x, 5, _ropeLength]; + } forEach _cargoRopes; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropesIndex, _cargoRopes]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + }; + } else { + [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Deploy_Ropes_Index",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Deploy_Ropes_Action = { - private ["_vehicle","_canDeployRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Deploy_Ropes) then { - - _canDeployRopes = true; - - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _vehicle > 1 ) then { - ["Cannot deploy cargo ropes from locked vehicle",false] call ASL_Hint; - _canDeployRopes = false; - }; + ASL_Deploy_Ropes_Action = { + private ["_vehicle"]; + if (vehicle player == player) then { + _vehicle = cursorTarget; + } else { + _vehicle = vehicle player; }; - - if(_canDeployRopes) then { - - _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; - - if(count _inactiveRopes > 0) then { - - if(count _inactiveRopes > 1) then { - player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - ["Deploy Cargo Ropes","ASL_Deploy_Ropes_Index_Action",_inactiveRopes] call ASL_Show_Select_Ropes_Menu; - } else { - [_vehicle,player,(_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + if ([_vehicle] call ASL_Can_Deploy_Ropes) then { + private _canDeployRopes = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + if (locked _vehicle > 1) then { + ["Cannot deploy cargo ropes from locked vehicle", false] call ASL_Hint; + _canDeployRopes = false; }; - - } else { - - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if(count _slingLoadPoints > 1) then { - player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [ - ["Deploy Ropes",false] - ]; - ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if((count _slingLoadPoints) > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if (_canDeployRopes) then { + private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + if (count _inactiveRopes > 0) then { + + if (count _inactiveRopes > 1) then { + player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; + ["Deploy Cargo Ropes", "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; + } else { + [_vehicle, player, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; }; - if((count _slingLoadPoints) > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + } else { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + if (count _slingLoadPoints > 1) then { + player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [["Deploy Ropes", false]]; + ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if ((count _slingLoadPoints) > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if ((count _slingLoadPoints) > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; + } else { + [_vehicle, player] call ASL_Deploy_Ropes; }; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; - } else { - [_vehicle,player] call ASL_Deploy_Ropes; }; - }; - }; - }; -}; -ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Deploy_Ropes_Index; + ASL_Deploy_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; + }; }; -}; -ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - if(_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_count] call ASL_Deploy_Ropes; + ASL_Deploy_Ropes_Count_Action = { + params ["_count"]; + private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + if (_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _count] call ASL_Deploy_Ropes; + }; }; -}; -ASL_Deploy_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Deploy_Ropes; - } else { - [vehicle player] call ASL_Can_Deploy_Ropes; + ASL_Deploy_Ropes_Action_Check = { + if(vehicle player == player) then { + [cursorTarget] call ASL_Can_Deploy_Ropes; + } else { + [vehicle player] call ASL_Can_Deploy_Ropes; + }; }; -}; -ASL_Can_Deploy_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _existingVehicle > 0) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { true }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { false }; - true; -}; - -ASL_Get_Corner_Points = { - params ["_vehicle"]; - private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; - private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor","_maxHeight","_heightOffset"]; - - // Correct width and length factor for air - _widthFactor = 0.5; - _lengthFactor = 0.5; - if(_vehicle isKindOf "Air") then { - _widthFactor = 0.3; + ASL_Can_Deploy_Ropes = { + params ["_vehicle"]; + if (player distance _vehicle > 10) exitWith {false}; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; + private _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; + if (count _existingVehicle > 0) exitWith {false}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if ((count _existingRopes) == 0) exitWith {true}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if ((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith {false}; + true }; - if(_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; - }; - - _centerOfMass = getCenterOfMass _vehicle; - _bbr = boundingBoxReal _vehicle; - _p1 = _bbr select 0; - _p2 = _bbr select 1; - _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; - _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; - _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - _heightOffset = _maxHeight/6; - - _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - - [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; -}; + ASL_Get_Corner_Points = { + params ["_vehicle"]; -ASL_Attach_Ropes = { - params ["_cargo","_player"]; - _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _vehicle = _vehicleWithIndex select 0; - if(!isNull _vehicle) then { - if(local _vehicle) then { - private ["_ropes","_attachmentPoints","_objDistance","_ropeLength","_allCargo"]; - _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; - if(count _ropes == 4) then { - _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - _ropeLength = (ropeLength (_ropes select 0)); - _objDistance = (_cargo distance _vehicle) + 2; - if( _objDistance > _ropeLength ) then { - [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; - } else { - [_vehicle,_player] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0,0,-1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0,0,-1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0,0,-1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0,0,-1]] ropeAttachTo (_ropes select 3); - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [(_vehicleWithIndex select 1),_cargo]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - }; - }; - }; - } else { - [_this,"ASL_Attach_Ropes",_vehicle,true] call ASL_RemoteExec; + private _widthFactor = 0.5; // Correct width and length factor for air + private _lengthFactor = 0.5; + if (_vehicle isKindOf "Air") then { + _widthFactor = 0.3; + }; + if (_vehicle isKindOf "Helicopter") then { + _widthFactor = 0.2; + _lengthFactor = 0.45; }; + private _centerOfMass = getCenterOfMass _vehicle; + private _bbr = boundingBoxReal _vehicle; + private _p1 = _bbr select 0; + private _p2 = _bbr select 1; + private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; + private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; + private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _heightOffset = _maxHeight / 6; + private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; -}; -ASL_Attach_Ropes_Action = { - private ["_vehicle","_cargo","_canBeAttached"]; - _cargo = cursorTarget; - _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; - if([_vehicle,_cargo] call ASL_Can_Attach_Ropes) then { - - _canBeAttached = true; - - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _cargo > 1 ) then { - ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; - _canBeAttached = false; + ASL_Attach_Ropes = { + params ["_cargo", "_player"]; + private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + private _vehicle = _vehicleWithIndex select 0; + if (!isNull _vehicle) then { + if (local _vehicle) then { + private _ropes = [_vehicle, (_vehicleWithIndex select 1)] call ASL_Get_Ropes; + if (count _ropes == 4) then { + private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + private _ropeLength = (ropeLength (_ropes select 0)); + private _objDistance = (_cargo distance _vehicle) + 2; + if( _objDistance > _ropeLength ) then { + [["The cargo ropes are too short. Move vehicle closer.", false], "ASL_Hint", _player] call ASL_RemoteExec; + } else { + [_vehicle,_player] call ASL_Drop_Ropes; + [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); + [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); + [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); + [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [(_vehicleWithIndex select 1), _cargo]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { + [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + }; + }; + }; + } else { + [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; }; }; - - if!(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { - if(!isNil "ExilePlayerInSafezone") then { - if( ExilePlayerInSafezone ) then { - ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; + }; + + ASL_Attach_Ropes_Action = { + private _cargo = cursorTarget; + private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; + if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { + private _canBeAttached = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + if (locked _cargo > 1) then { + ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; _canBeAttached = false; }; }; + if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { + if (!isNil "ExilePlayerInSafezone") then { + if ( ExilePlayerInSafezone ) then { + ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; + _canBeAttached = false; + }; + }; + }; + if (_canBeAttached) then { + [_cargo, player] call ASL_Attach_Ropes; + }; }; - - if(_canBeAttached) then { - [_cargo,player] call ASL_Attach_Ropes; - }; - }; -}; -ASL_Attach_Ropes_Action_Check = { - private ["_vehicleWithIndex","_cargo"]; - _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _cargo = cursorTarget; - [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; -}; + ASL_Attach_Ropes_Action_Check = { + private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; + private _cargo = cursorTarget; + [_vehicleWithIndex select 0, _cargo] call ASL_Can_Attach_Ropes; + }; -ASL_Can_Attach_Ropes = { - params ["_vehicle","_cargo"]; - if(!isNull _vehicle && !isNull _cargo) then { - [_vehicle,_cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - } else { - false; + ASL_Can_Attach_Ropes = { + params ["_vehicle", "_cargo"]; + if (!isNull _vehicle && !isNull _cargo) then { + [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; + } else { + false; + }; }; -}; -ASL_Drop_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_helper","_existingRopes"]; - _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - if(!isNull _helper) then { - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - { - _helper ropeDetach _x; - } forEach _existingRopes; - detach _helper; - deleteVehicle _helper; + ASL_Drop_Ropes = { + params ["_vehicle", "_player", ["_ropesIndex", 0]]; + if (local _vehicle) then { + private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + if (!isNull _helper) then { + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + { + _helper ropeDetach _x; + } forEach _existingRopes; + detach _helper; + deleteVehicle _helper; + }; + _player setVariable ["ASL_Ropes_Vehicle", nil, true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; + } else { + [_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec; }; - _player setVariable ["ASL_Ropes_Vehicle", nil,true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; - } else { - [_this,"ASL_Drop_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Drop_Ropes_Action = { - private ["_vehicleAndIndex"]; - if([] call ASL_Can_Drop_Ropes) then { - _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + ASL_Drop_Ropes_Action = { + if ([] call ASL_Can_Drop_Ropes) then { + private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; + if (count _vehicleAndIndex == 2) then { + [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + }; }; }; -}; -ASL_Drop_Ropes_Action_Check = { - [] call ASL_Can_Drop_Ropes; -}; + ASL_Drop_Ropes_Action_Check = { + [] call ASL_Can_Drop_Ropes; + }; -ASL_Can_Drop_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; -}; + ASL_Can_Drop_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; + }; -ASL_Get_Closest_Rope = { - private ["_nearbyVehicles","_closestVehicle","_closestRopeIndex","_closestDistance"]; - private ["_vehicle","_activeRope","_ropes","_ends"]; - private ["_end1","_end2","_minEndDistance"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - _closestVehicle = objNull; - _closestRopeIndex = 0; - _closestDistance = -1; - { - _vehicle = _x; + ASL_Get_Closest_Rope = { + private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; + private _closestVehicle = objNull; + private _closestRopeIndex = 0; + private _closestDistance = -1; { - _activeRope = _x; - _ropes = [_vehicle,(_activeRope select 0)] call ASL_Get_Ropes; + private _vehicle = _x; { - _ends = ropeEndPosition _x; - if(count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); - if(_closestDistance == -1 || _closestDistance > _minEndDistance) then { - _closestDistance = _minEndDistance; - _closestRopeIndex = (_activeRope select 0); - _closestVehicle = _vehicle; + private _activeRope = _x; + private _ropes = [_vehicle, (_activeRope select 0)] call ASL_Get_Ropes; + { + private _ends = ropeEndPosition _x; + if (count _ends == 2) then { + private _end1 = _ends select 0; + private _end2 = _ends select 1; + private _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); + if (_closestDistance == -1 || _closestDistance > _minEndDistance) then { + _closestDistance = _minEndDistance; + _closestRopeIndex = (_activeRope select 0); + _closestVehicle = _vehicle; + }; }; - }; - } forEach _ropes; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearbyVehicles; - [_closestVehicle,_closestRopeIndex]; -}; + } forEach _ropes; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearbyVehicles; + [_closestVehicle, _closestRopeIndex]; + }; -ASL_Pickup_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_helper","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(!isNull _existingCargo) then { + ASL_Pickup_Ropes = { + params ["_vehicle", "_player", ["_ropesIndex", 0]]; + if (local _vehicle) then { + private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + if (!isNull _existingCargo) then { + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropesIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + }; + private _helper = "Land_Can_V2_F" createVehicle position _player; { - _existingCargo ropeDetach _x; + [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; + _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropesIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + hideObject _helper; + [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; + } else { + [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; }; - _helper = "Land_Can_V2_F" createVehicle position _player; - { - [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; - _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - } forEach _existingRopes; - hideObject _helper; - [[_helper],"ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - _player setVariable ["ASL_Ropes_Vehicle", [_vehicle,_ropesIndex],true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper,true]; - } else { - [_this,"ASL_Pickup_Ropes",_vehicle,true] call ASL_RemoteExec; }; -}; -ASL_Pickup_Ropes_Action = { - private ["_nearbyVehicles","_canPickupRopes","_closestRope"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - if([] call ASL_Can_Pickup_Ropes) then { - _closestRope = [] call ASL_Get_Closest_Rope; - if(!isNull (_closestRope select 0)) then { - _canPickupRopes = true; - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked (_closestRope select 0) > 1 ) then { - ["Cannot pick up cargo ropes from locked vehicle",false] call ASL_Hint; - _canPickupRopes = false; + ASL_Pickup_Ropes_Action = { + if ([] call ASL_Can_Pickup_Ropes) then { + private _closestRope = [] call ASL_Get_Closest_Rope; + if (!isNull (_closestRope select 0)) then { + private _canPickupRopes = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if (locked (_closestRope select 0) > 1) then { + ["Cannot pick up cargo ropes from locked vehicle", false] call ASL_Hint; + _canPickupRopes = false; + }; }; + if (_canPickupRopes) then { + [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; + }; }; - if(_canPickupRopes) then { - [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - }; }; }; -}; -ASL_Pickup_Ropes_Action_Check = { - [] call ASL_Can_Pickup_Ropes; -}; + ASL_Pickup_Ropes_Action_Check = { + [] call ASL_Can_Pickup_Ropes; + }; -ASL_Can_Pickup_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; -}; + ASL_Can_Pickup_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles", []]) > 0 && vehicle player == player; + }; -ASL_SUPPORTED_VEHICLES = [ - "Helicopter", - "VTOL_Base_F" -]; + ASL_SUPPORTED_VEHICLES = [ + "Helicopter", + "VTOL_Base_F" + ]; -ASL_Is_Supported_Vehicle = { - params ["_vehicle","_isSupported"]; - _isSupported = false; - if(not isNull _vehicle) then { - { - if(_vehicle isKindOf _x) then { - _isSupported = true; - }; - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); + ASL_Is_Supported_Vehicle = { + params ["_vehicle", "_isSupported"]; + _isSupported = false; + if (not isNull _vehicle) then { + { + if (_vehicle isKindOf _x) then { + _isSupported = true; + }; + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); + }; + _isSupported }; - _isSupported; -}; -ASL_SLING_RULES = [ - ["All","CAN_SLING","All"] -]; + ASL_SLING_RULES = [ + ["All", "CAN_SLING","All"] + ]; -ASL_Is_Supported_Cargo = { - params ["_vehicle","_cargo"]; - private ["_canSling"]; - _canSling = false; - if(not isNull _vehicle && not isNull _cargo) then { - { - if(_vehicle isKindOf (_x select 0)) then { - if(_cargo isKindOf (_x select 2)) then { - if( (toUpper (_x select 1)) == "CAN_SLING" ) then { - _canSling = true; - } else { - _canSling = false; + ASL_Is_Supported_Cargo = { + params ["_vehicle", "_cargo"]; + private _canSling = false; + if (not isNull _vehicle && not isNull _cargo) then { + { + if (_vehicle isKindOf (_x select 0)) then { + if (_cargo isKindOf (_x select 2)) then { + if ((toUpper (_x select 1)) == "CAN_SLING") then { + _canSling = true; + } else { + _canSling = false; + }; }; }; - }; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); + }; + _canSling }; - _canSling; -}; -ASL_Hint = { - params ["_msg",["_isSuccess",true]]; - if(!isNil "ExileClient_gui_notification_event_addNotification") then { - if(_isSuccess) then { - ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + ASL_Hint = { + params ["_msg", ["_isSuccess", true]]; + if (!isNil "ExileClient_gui_notification_event_addNotification") then { + if (_isSuccess) then { + ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + } else { + ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + }; } else { - ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + hint _msg; }; - } else { - hint _msg; - }; -}; + }; -ASL_Hide_Object_Global = { - params ["_obj"]; - if( _obj isKindOf "Land_Can_V2_F" ) then { - hideObjectGlobal _obj; + ASL_Hide_Object_Global = { + params ["_obj"]; + if( _obj isKindOf "Land_Can_V2_F" ) then { + hideObjectGlobal _obj; + }; }; -}; -ASL_Find_Nearby_Vehicles = { - private ["_nearVehicles","_nearVehiclesWithRopes","_vehicle","_ends","_end1","_end2","_playerPosAGL"]; - _nearVehicles = []; - { - _nearVehicles append (player nearObjects [_x, 30]); - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); - _nearVehiclesWithRopes = []; - { - _vehicle = _x; + ASL_Find_Nearby_Vehicles = { + private _nearVehicles = []; { - _ropes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _ropes > (_x select 0)) then { - _ropes = _ropes select (_x select 0); - { - _ends = ropeEndPosition _x; - if(count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _playerPosAGL = ASLtoAGL getPosASL player; - if((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { - _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - } - }; - } forEach _ropes; - }; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearVehicles; - _nearVehiclesWithRopes; -}; - -ASL_Add_Player_Actions = { + _nearVehicles append (player nearObjects [_x, 30]); + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); + private _nearVehiclesWithRopes = []; + { + private _vehicle = _x; + { + private _ropes = _vehicle getVariable ["ASL_Ropes", []]; + if(count _ropes > (_x select 0)) then { + _ropes = _ropes select (_x select 0); + { + private _ends = ropeEndPosition _x; + if (count _ends == 2) then { + private _end1 = _ends select 0; + private _end2 = _ends select 1; + private _playerPosAGL = ASLtoAGL getPosASL player; + if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { + _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; + } + }; + } forEach _ropes; + }; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearVehicles; + _nearVehiclesWithRopes + }; - player addAction ["Extend Cargo Ropes", { - [] call ASL_Extend_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; - - player addAction ["Shorten Cargo Ropes", { - [] call ASL_Shorten_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; + ASL_Add_Player_Actions = { + player addAction ["Extend Cargo Ropes", { + [] call ASL_Extend_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; - player addAction ["Release Cargo", { - [] call ASL_Release_Cargo_Action; - }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; + player addAction ["Shorten Cargo Ropes", { + [] call ASL_Shorten_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; + + player addAction ["Release Cargo", { + [] call ASL_Release_Cargo_Action; + }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; + + player addAction ["Retract Cargo Ropes", { + [] call ASL_Retract_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; - player addAction ["Retract Cargo Ropes", { - [] call ASL_Retract_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; - - player addAction ["Deploy Cargo Ropes", { - [] call ASL_Deploy_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; + player addAction ["Deploy Cargo Ropes", { + [] call ASL_Deploy_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; - player addAction ["Attach To Cargo Ropes", { - [] call ASL_Attach_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; + player addAction ["Attach To Cargo Ropes", { + [] call ASL_Attach_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - player addAction ["Drop Cargo Ropes", { - [] call ASL_Drop_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; + player addAction ["Drop Cargo Ropes", { + [] call ASL_Drop_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - player addAction ["Pickup Cargo Ropes", { - [] call ASL_Pickup_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; + player addAction ["Pickup Cargo Ropes", { + [] call ASL_Pickup_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - player addEventHandler ["Respawn", { - player setVariable ["ASL_Actions_Loaded",false]; - }]; - -}; + player addEventHandler ["Respawn", { + player setVariable ["ASL_Actions_Loaded", false]; + }]; + }; -if(!isDedicated) then { - [] spawn { - while {true} do { - if(!isNull player && isPlayer player) then { - if!( player getVariable ["ASL_Actions_Loaded",false] ) then { - [] call ASL_Add_Player_Actions; - player setVariable ["ASL_Actions_Loaded",true]; + if (!isDedicated) then { + [] spawn { + while {true} do { + if (!isNull player && isPlayer player) then { + if !(player getVariable ["ASL_Actions_Loaded", false]) then { + [] call ASL_Add_Player_Actions; + player setVariable ["ASL_Actions_Loaded", true]; + }; }; + missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; + sleep 2; }; - missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - sleep 2; }; }; -}; -ASL_RemoteExec = { - params ["_params","_functionName","_target",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, _target]; + ASL_RemoteExec = { + params ["_params", "_functionName", "_target", ["_isCall", false]]; + if (!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecClient", [_params, _functionName, _target, _isCall]] call ExileClient_system_network_send; } else { - _params remoteExec [_functionName, _target]; + if (_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; }; }; -}; -ASL_RemoteExecServer = { - params ["_params","_functionName",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, 2]; + ASL_RemoteExecServer = { + params ["_params", "_functionName", ["_isCall", false]]; + if (!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; } else { - _params remoteExec [_functionName, 2]; + if(_isCall) then { + _params remoteExecCall [_functionName, 2]; + } else { + _params remoteExec [_functionName, 2]; + }; }; }; -}; -if(isServer) then { - - // Adds support for exile network calls (Only used when running exile) // - - ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; + if (isServer) then { // Adds support for exile network calls (Only used when running exile) + ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { - params ["_sessionId", "_messageParameters",["_isCall",false]]; - _messageParameters params ["_params","_functionName"]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { - if(_isCall) then { - _params call (missionNamespace getVariable [_functionName,{}]); - } else { - _params spawn (missionNamespace getVariable [_functionName,{}]); + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { + params ["_sessionId", "_messageParameters", ["_isCall", false]]; + _messageParameters params ["_params", "_functionName"]; + if (_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { + if (_isCall) then { + _params call (missionNamespace getVariable [_functionName, {}]); + } else { + _params spawn (missionNamespace getVariable [_functionName, {}]); + }; }; }; - }; - - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; - - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { - params ["_sessionId", "_messageParameters"]; - _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { - if(_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; + + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { + params ["_sessionId", "_messageParameters"]; + _messageParameters params ["_params", "_functionName", "_target", ["_isCall", false]]; + if (_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { + if (_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; }; }; + + publicVariable "ASL_Advanced_Sling_Loading_Install"; // Install Advanced Sling Loading on all clients (plus JIP) + remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; }; - // Install Advanced Sling Loading on all clients (plus JIP) // + // Disable Old Script Version on SA Server + SA_Rope_Action_Check = {false}; + SA_Rope_Pickup_Rope_Action_Check = {false}; + SA_Rope_Drop_Rope_Action_Check = {false}; + SA_Rope_Attach_Rope_Action_Check = {false}; - publicVariable "ASL_Advanced_Sling_Loading_Install"; - remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; - -}; - -// Disable Old Script Version on SA Server -SA_Rope_Action_Check = {false}; -SA_Rope_Pickup_Rope_Action_Check = {false}; -SA_Rope_Drop_Rope_Action_Check = {false}; -SA_Rope_Attach_Rope_Action_Check = {false}; - -diag_log "Advanced Sling Loading Loaded"; - + diag_log "Advanced Sling Loading Loaded"; }; -if(isServer) then { +if (isServer) then { [] call ASL_Advanced_Sling_Loading_Install; }; From e8d0a73864bdcf9a424be011f2bd379fcf658424 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 14 Feb 2020 11:57:30 +0100 Subject: [PATCH 03/24] Update fn_advancedSlingLoadingInit.sqf --- .../functions/fn_advancedSlingLoadingInit.sqf | 266 ++++++++---------- 1 file changed, 118 insertions(+), 148 deletions(-) diff --git a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 8015f69..ed7385f 100644 --- a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -13,7 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ASL_Advanced_Sling_Loading_Install = { // Prevent advanced sling loading from installing twice - if(!isNil "ASL_ROPE_INIT") exitWith {}; + if (!isNil "ASL_ROPE_INIT") exitWith {}; ASL_ROPE_INIT = true; diag_log "Advanced Sling Loading Loading..."; @@ -39,53 +39,50 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Sling_Load_Points = { params ["_vehicle"]; - private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"]; - private ["_slingLoadPoints","_modelPoint","_modelPointASL","_surfaceIntersectStartASL","_surfaceIntersectEndASL","_surfaces","_intersectionASL","_intersectionObject"]; - _slingLoadPointsArray = []; - _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + private _slingLoadPointsArray = []; + private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; + private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); + private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; - _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; - _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - - _slingLoadPointHeightOffset = 0; + private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; + private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); + private _slingLoadPointHeightOffset = 0; { if (_vehicle isKindOf (_x select 0)) then { _slingLoadPointHeightOffset = (_x select 1); }; } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - _slingLoadPoints = []; + private _slingLoadPoints = []; { - _modelPoint = _x; - _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); - _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); - _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); + private _modelPoint = _x; + private _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); + private _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); + private _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); // Determine if the surface intersection line crosses below ground level // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces // doesn't work if starting below ground level for some reason // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection - _la = ASLToAGL _surfaceIntersectStartASL; - _lb = ASLToAGL _surfaceIntersectEndASL; + private _la = ASLToAGL _surfaceIntersectStartASL; + private _lb = ASLToAGL _surfaceIntersectEndASL; if (_la select 2 < 0 && _lb select 2 > 0) then { - _n = [0, 0, 1]; - _p0 = [0, 0, 0.1]; - _l = (_la vectorFromTo _lb); + private _n = [0, 0, 1]; + private _p0 = [0, 0, 0.1]; + private _l = (_la vectorFromTo _lb); if ((_l vectorDotProduct _n) != 0) then { - _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n ) / (_l vectorDotProduct _n); + private _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n ) / (_l vectorDotProduct _n); _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); }; }; - _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; - _intersectionASL = []; + private _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; + private _intersectionASL = []; { - _intersectionObject = _x select 2; + private _intersectionObject = _x select 2; if (_intersectionObject == _vehicle) exitWith { _intersectionASL = _x select 0; }; @@ -98,10 +95,10 @@ ASL_Advanced_Sling_Loading_Install = { }; } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - if(count (_slingLoadPoints select 1) > 0) then { + if (count (_slingLoadPoints select 1) > 0) then { _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if(count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { - if(((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { + if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 1, _slingLoadPoints select 2]; @@ -109,7 +106,7 @@ ASL_Advanced_Sling_Loading_Install = { }; }; }; - _slingLoadPointsArray; + _slingLoadPointsArray }; ASL_Rope_Set_Mass = { @@ -147,11 +144,7 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - /* - Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle - */ - ASL_Get_Active_Ropes = { + ASL_Get_Active_Ropes = { // Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle params ["_vehicle"]; private _activeRopes = []; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; @@ -168,11 +161,7 @@ ASL_Advanced_Sling_Loading_Install = { _activeRopes }; - /* - Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle - */ - ASL_Get_Inactive_Ropes = { + ASL_Get_Inactive_Ropes = { // Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle params ["_vehicle"]; private _inactiveRopes = []; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; @@ -192,11 +181,11 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Active_Ropes_With_Cargo = { params ["_vehicle"]; private _activeRopesWithCargo = []; - private _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; private _activeRopes = _this call ASL_Get_Active_Ropes; { private _cargo = _existingCargo select (_x select 0); - if(!isNull _cargo) then { + if (!isNull _cargo) then { _activeRopesWithCargo pushBack _x; }; } forEach _activeRopes; @@ -221,7 +210,7 @@ ASL_Advanced_Sling_Loading_Install = { params ["_vehicle", "_ropeIndex"]; private _selectedRopes = []; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - if(count _allRopes > _ropeIndex) then { + if (count _allRopes > _ropeIndex) then { _selectedRopes = _allRopes select _ropeIndex; }; _selectedRopes @@ -229,7 +218,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Ropes_Count = { params ["_vehicle"]; - count (_vehicle getVariable ["ASL_Ropes",[]]); + count (_vehicle getVariable ["ASL_Ropes", []]); }; ASL_Get_Cargo = { @@ -253,7 +242,7 @@ ASL_Advanced_Sling_Loading_Install = { params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", "Ropes"]]; ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; { - ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "[" + (str (_x select 0)) + "] call " + _functionName]], "1", "1"]; } forEach _ropesIndexAndLabelArray; ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; showCommandingMenu ""; @@ -278,17 +267,15 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Extend_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Extend_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { + private _vehicle = vehicle player; + if ([_vehicle] call ASL_Can_Extend_Ropes) then { + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes > 1) then { player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; } else { if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; }; }; }; @@ -296,42 +283,39 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Extend_Ropes_Index_Action = { params ["_ropeIndex"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; }; }; ASL_Extend_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; + if (vehicle player == player) exitWith {false}; [vehicle player] call ASL_Can_Extend_Ropes; }; ASL_Can_Extend_Ropes = { params ["_vehicle"]; - // private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + if (player distance _vehicle > 10) exitWith {false}; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; + if ((count _existingRopes) == 0) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; + if ((count _activeRopes) == 0) exitWith {false}; + true }; ASL_Shorten_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - // private ["_existingRopes"]; - private _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 2 ) then { + params ["_vehicle", "_player", ["_ropeIndex",0]]; + if (local _vehicle) then { + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= 2) then { _this call ASL_Release_Cargo; } else { { - if(_ropeLength >= 10) then { + if (_ropeLength >= 10) then { ropeUnwind [_x, 3, -5, true]; } else { ropeUnwind [_x, 3, -1, true]; @@ -340,22 +324,20 @@ ASL_Advanced_Sling_Loading_Install = { }; }; } else { - [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; + [_this, "ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec; }; }; ASL_Shorten_Ropes_Action = { - // private ["_vehicle"]; private _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Shorten_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { + if ([_vehicle] call ASL_Can_Shorten_Ropes) then { + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes > 1) then { player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + ["Shorten Cargo Ropes", "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + if (count _activeRopes == 1) then { + [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; }; }; }; @@ -363,10 +345,9 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Shorten_Ropes_Index_Action = { params ["_ropeIndex"]; - // private ["_vehicle"]; private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; }; }; @@ -377,47 +358,43 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Shorten_Ropes = { params ["_vehicle"]; - // private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + if (player distance _vehicle > 10) exitWith {false}; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; + if ((count _existingRopes) == 0) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; + if ((count _activeRopes) == 0) exitWith {false}; + true }; ASL_Release_Cargo = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - // private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; - private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + if (local _vehicle) then { + private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; private _existingCargo = _existingRopesAndCargo select 1; { _existingCargo ropeDetach _x; } forEach _existingRopes; - private _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropeIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropeIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; _this call ASL_Retract_Ropes; } else { - [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + [_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec; }; }; ASL_Release_Cargo_Action = { - // private ["_vehicle"]; private _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Release_Cargo) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if ([_vehicle] call ASL_Can_Release_Cargo) then { + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; if(count _activeRopes > 1) then { player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; + ["Release Cargo", "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; } else { if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; + [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Release_Cargo; }; }; }; @@ -425,10 +402,9 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo_Index_Action = { params ["_ropesIndex"]; - // private ["_vehicle"]; private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; }; }; @@ -439,30 +415,27 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Release_Cargo = { params ["_vehicle"]; - // private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; + if (player distance _vehicle > 10) exitWith {false}; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if ((count _existingRopes) == 0) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; + if ((count _activeRopes) == 0) exitWith {false}; + true }; ASL_Retract_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - // private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; - private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + if (local _vehicle) then { + private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; private _existingCargo = _existingRopesAndCargo select 1; - if(isNull _existingCargo) then { + if (isNull _existingCargo) then { _this call ASL_Drop_Ropes; { [_x,_vehicle] spawn { - params ["_rope","_vehicle"]; - private ["_count"]; - _count = 0; + params ["_rope", "_vehicle"]; + private _count = 0; ropeUnwind [_rope, 3, 0]; while {(!ropeUnwound _rope) && _count < 20} do { sleep 1; @@ -471,36 +444,34 @@ ASL_Advanced_Sling_Loading_Install = { ropeDestroy _rope; }; } forEach _existingRopes; - private _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropeIndex,[]]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropeIndex, []]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; }; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes",nil,true]; + if (count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes", nil, true]; }; } else { - [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; + [_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec; }; }; ASL_Retract_Ropes_Action = { - // private ["_vehicle","_canRetractRopes"]; private ["_vehicle"]; - if(vehicle player == player) then { + if (vehicle player == player) then { _vehicle = cursorTarget; } else { _vehicle = vehicle player; }; - if([_vehicle] call ASL_Can_Retract_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if(count _activeRopes > 1) then { + if ([_vehicle] call ASL_Can_Retract_Ropes) then { + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if (count _activeRopes > 1) then { player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + ["Retract Cargo Ropes", "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; + if (count _activeRopes == 1) then { + [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; }; }; }; @@ -569,7 +540,7 @@ ASL_Advanced_Sling_Loading_Install = { if (local _vehicle) then { private _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if(count _existingRopes == 0) then { + if (count _existingRopes == 0) then { private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; private _cargoRopes = []; _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; @@ -665,7 +636,7 @@ ASL_Advanced_Sling_Loading_Install = { if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; private _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; if (count _existingVehicle > 0) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; if ((count _existingRopes) == 0) exitWith {true}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; if ((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith {false}; @@ -674,7 +645,6 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Corner_Points = { params ["_vehicle"]; - private _widthFactor = 0.5; // Correct width and length factor for air private _lengthFactor = 0.5; if (_vehicle isKindOf "Air") then { @@ -712,7 +682,7 @@ ASL_Advanced_Sling_Loading_Install = { private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; private _ropeLength = (ropeLength (_ropes select 0)); private _objDistance = (_cargo distance _vehicle) + 2; - if( _objDistance > _ropeLength ) then { + if ( _objDistance > _ropeLength ) then { [["The cargo ropes are too short. Move vehicle closer.", false], "ASL_Hint", _player] call ASL_RemoteExec; } else { [_vehicle,_player] call ASL_Drop_Ropes; @@ -723,7 +693,7 @@ ASL_Advanced_Sling_Loading_Install = { private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [(_vehicleWithIndex select 1), _cargo]; _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { + if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; }; }; @@ -736,19 +706,19 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Attach_Ropes_Action = { private _cargo = cursorTarget; - private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; + private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { private _canBeAttached = true; if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { if (locked _cargo > 1) then { - ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; + ["Cannot attach cargo ropes to locked vehicle", false] call ASL_Hint; _canBeAttached = false; }; }; if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { if (!isNil "ExilePlayerInSafezone") then { if ( ExilePlayerInSafezone ) then { - ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; + ["Cannot attach cargo ropes in safe zone", false] call ASL_Hint; _canBeAttached = false; }; }; @@ -948,7 +918,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Hide_Object_Global = { params ["_obj"]; - if( _obj isKindOf "Land_Can_V2_F" ) then { + if (_obj isKindOf "Land_Can_V2_F") then { hideObjectGlobal _obj; }; }; @@ -963,7 +933,7 @@ ASL_Advanced_Sling_Loading_Install = { private _vehicle = _x; { private _ropes = _vehicle getVariable ["ASL_Ropes", []]; - if(count _ropes > (_x select 0)) then { + if (count _ropes > (_x select 0)) then { _ropes = _ropes select (_x select 0); { private _ends = ropeEndPosition _x; @@ -971,7 +941,7 @@ ASL_Advanced_Sling_Loading_Install = { private _end1 = _ends select 0; private _end2 = _ends select 1; private _playerPosAGL = ASLtoAGL getPosASL player; - if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { + if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; } }; @@ -1053,7 +1023,7 @@ ASL_Advanced_Sling_Loading_Install = { if (!isNil "ExileClient_system_network_send") then { ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; } else { - if(_isCall) then { + if (_isCall) then { _params remoteExecCall [_functionName, 2]; } else { _params remoteExec [_functionName, 2]; @@ -1076,7 +1046,7 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes", "ASL_Deploy_Ropes_Index", "ASL_Rope_Set_Mass", "ASL_Extend_Ropes", "ASL_Shorten_Ropes", "ASL_Release_Cargo", "ASL_Retract_Ropes", "ASL_Deploy_Ropes", "ASL_Hint", "ASL_Attach_Ropes", "ASL_Drop_Ropes"]; ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { params ["_sessionId", "_messageParameters"]; From b2c3ee8cab805f562a90cf0d933511b580fad3de Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 14 Feb 2020 13:38:19 +0100 Subject: [PATCH 04/24] Update fn_advancedSlingLoadingInit.sqf - code cleaning --- .../functions/fn_advancedSlingLoadingInit.sqf | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index ed7385f..7783971 100644 --- a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -20,12 +20,11 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Rope_Get_Lift_Capability = { params ["_vehicle"]; - private ["_slingLoadMaxCargoMass"]; - _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); if (_slingLoadMaxCargoMass <= 0) then { _slingLoadMaxCargoMass = 4000; }; - _slingLoadMaxCargoMass; + _slingLoadMaxCargoMass }; ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ @@ -74,7 +73,7 @@ ASL_Advanced_Sling_Loading_Install = { private _p0 = [0, 0, 0.1]; private _l = (_la vectorFromTo _lb); if ((_l vectorDotProduct _n) != 0) then { - private _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n ) / (_l vectorDotProduct _n); + private _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n) / (_l vectorDotProduct _n); _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); }; }; @@ -123,7 +122,7 @@ ASL_Advanced_Sling_Loading_Install = { private _originalMass = getMass _obj; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; - if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + if (_originalMass >= ((_lift) * 0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { private _originalMassSet = (getMass _obj) == _originalMass; while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { { @@ -274,7 +273,7 @@ ASL_Advanced_Sling_Loading_Install = { player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; } else { - if(count _activeRopes == 1) then { + if (count _activeRopes == 1) then { [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; }; }; @@ -389,11 +388,11 @@ ASL_Advanced_Sling_Loading_Install = { private _vehicle = vehicle player; if ([_vehicle] call ASL_Can_Release_Cargo) then { private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if(count _activeRopes > 1) then { + if (count _activeRopes > 1) then { player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; ["Release Cargo", "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; } else { - if(count _activeRopes == 1) then { + if (count _activeRopes == 1) then { [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Release_Cargo; }; }; @@ -403,7 +402,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo_Index_Action = { params ["_ropesIndex"]; private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; }; }; @@ -433,7 +432,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _existingCargo) then { _this call ASL_Drop_Ropes; { - [_x,_vehicle] spawn { + [_x, _vehicle] spawn { params ["_rope", "_vehicle"]; private _count = 0; ropeUnwind [_rope, 3, 0]; @@ -538,7 +537,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Deploy_Ropes_Index = { params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; if (local _vehicle) then { - private _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; if (count _existingRopes == 0) then { private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; @@ -658,11 +657,11 @@ ASL_Advanced_Sling_Loading_Install = { private _bbr = boundingBoxReal _vehicle; private _p1 = _bbr select 0; private _p2 = _bbr select 1; - private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; - private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; - private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _maxWidth = abs((_p2 select 0) - (_p1 select 0)); + private _widthOffset = ((_maxWidth / 2) - abs(_centerOfMass select 0)) * _widthFactor; + private _maxLength = abs((_p2 select 1) - (_p1 select 1)); + private _lengthOffset = ((_maxLength / 2) - abs(_centerOfMass select 1)) * _lengthFactor; + private _maxHeight = abs((_p2 select 2) - (_p1 select 2)); private _heightOffset = _maxHeight / 6; private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; @@ -673,7 +672,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Attach_Ropes = { params ["_cargo", "_player"]; - private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; private _vehicle = _vehicleWithIndex select 0; if (!isNull _vehicle) then { if (local _vehicle) then { @@ -715,7 +714,7 @@ ASL_Advanced_Sling_Loading_Install = { _canBeAttached = false; }; }; - if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { + if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { if (!isNil "ExilePlayerInSafezone") then { if ( ExilePlayerInSafezone ) then { ["Cannot attach cargo ropes in safe zone", false] call ASL_Hint; @@ -841,7 +840,7 @@ ASL_Advanced_Sling_Loading_Install = { private _closestRope = [] call ASL_Get_Closest_Rope; if (!isNull (_closestRope select 0)) then { private _canPickupRopes = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { if (locked (_closestRope select 0) > 1) then { ["Cannot pick up cargo ropes from locked vehicle", false] call ASL_Hint; _canPickupRopes = false; @@ -868,13 +867,11 @@ ASL_Advanced_Sling_Loading_Install = { ]; ASL_Is_Supported_Vehicle = { - params ["_vehicle", "_isSupported"]; - _isSupported = false; + params ["_vehicle"]; + private _isSupported = false; if (not isNull _vehicle) then { { - if (_vehicle isKindOf _x) then { - _isSupported = true; - }; + if (_vehicle isKindOf _x) exitWith {_isSupported = true}; } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); }; _isSupported @@ -926,7 +923,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Find_Nearby_Vehicles = { private _nearVehicles = []; { - _nearVehicles append (player nearObjects [_x, 30]); + _nearVehicles append (player nearObjects [_x, 30]); } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); private _nearVehiclesWithRopes = []; { From 2d42ff6136c351e4c16f176019d386d3a80c410d Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Tue, 9 Mar 2021 23:05:47 +0100 Subject: [PATCH 05/24] Code cleaning - code cleaning - renamed pbo folder --- .../$PBOPREFIX$ => $PREFIX$ | 0 addons/NIC_AdvancedSlingLoading/$PREFIX$ | 1 + addons/NIC_AdvancedSlingLoading/config.cpp | 58 + .../functions/fn_advancedSlingLoadingInit.sqf | 1172 +++++++++++++++++ addons/SA_AdvancedSlingLoading/config.cpp | 38 - .../functions/fn_advancedSlingLoadingInit.sqf | 1075 --------------- config.bin | Bin 0 -> 664 bytes functions/fn_advancedSlingLoadingInit.sqf | 1166 ++++++++++++++++ meta.cpp | 4 + mod.cpp | 2 +- 10 files changed, 2402 insertions(+), 1114 deletions(-) rename addons/SA_AdvancedSlingLoading/$PBOPREFIX$ => $PREFIX$ (100%) create mode 100644 addons/NIC_AdvancedSlingLoading/$PREFIX$ create mode 100644 addons/NIC_AdvancedSlingLoading/config.cpp create mode 100644 addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf delete mode 100644 addons/SA_AdvancedSlingLoading/config.cpp delete mode 100644 addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf create mode 100644 config.bin create mode 100644 functions/fn_advancedSlingLoadingInit.sqf create mode 100644 meta.cpp diff --git a/addons/SA_AdvancedSlingLoading/$PBOPREFIX$ b/$PREFIX$ similarity index 100% rename from addons/SA_AdvancedSlingLoading/$PBOPREFIX$ rename to $PREFIX$ diff --git a/addons/NIC_AdvancedSlingLoading/$PREFIX$ b/addons/NIC_AdvancedSlingLoading/$PREFIX$ new file mode 100644 index 0000000..a04b576 --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/$PREFIX$ @@ -0,0 +1 @@ +SA_AdvancedSlingLoading \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp new file mode 100644 index 0000000..6992887 --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -0,0 +1,58 @@ +class CfgPatches +{ + class SA_AdvancedSlingLoading + { + units[]= + { + "SA_AdvancedSlingLoading" + }; + requiredVersion=1; + requiredAddons[]= + { + "A3_Modules_F" + }; + }; +}; +class CfgNetworkMessages +{ + class AdvancedSlingLoadingRemoteExecClient + { + module="AdvancedSlingLoading"; + parameters[]= + { + "ARRAY", + "STRING", + "OBJECT", + "BOOL" + }; + }; + class AdvancedSlingLoadingRemoteExecServer + { + module="AdvancedSlingLoading"; + parameters[]= + { + "ARRAY", + "STRING", + "BOOL" + }; + }; +}; +class CfgFunctions +{ + class SA + { + class AdvancedSlingLoading + { + file="\SA_AdvancedSlingLoading\functions"; + class advancedSlingLoadingInit + { + postInit=1; + }; + }; + }; +}; +class cfgMods +{ + author="76561198131707990"; + timepacked="1473204282"; +}; diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf new file mode 100644 index 0000000..eb165da --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -0,0 +1,1172 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Seth Duda + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +ASL_Advanced_Sling_Loading_Install = { + +// Prevent advanced sling loading from installing twice +if(!isNil "ASL_ROPE_INIT") exitWith {}; +ASL_ROPE_INIT = true; + +diag_log "Advanced Sling Loading Loading..."; + +ASL_Rope_Get_Lift_Capability = { + params ["_vehicle"]; + private ["_slingLoadMaxCargoMass"]; + _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + if(_slingLoadMaxCargoMass <= 0) then { + _slingLoadMaxCargoMass = 4000; + }; + _slingLoadMaxCargoMass; +}; + +ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ + ["All", [-0.05, -0.05, -0.05]], + ["CUP_CH47F_base", [-0.05, -2, -0.05]], + ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], + ["RHS_CH_47F", [-0.75, -2.6, -0.75]], + ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], + ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] +]; + +ASL_Get_Sling_Load_Points = { + params ["_vehicle"]; + private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"]; + private ["_slingLoadPoints","_modelPoint","_modelPointASL","_surfaceIntersectStartASL","_surfaceIntersectEndASL","_surfaces","_intersectionASL","_intersectionObject"]; + _slingLoadPointsArray = []; + _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; + _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); + _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; + _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; + _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; + _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); + + _slingLoadPointHeightOffset = 0; + { + if(_vehicle isKindOf (_x select 0)) then { + _slingLoadPointHeightOffset = (_x select 1); + }; + } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; + + _slingLoadPoints = []; + { + _modelPoint = _x; + _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); + _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); + _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); + + // Determine if the surface intersection line crosses below ground level + // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces + // doesn't work if starting below ground level for some reason + // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection + + _la = ASLToAGL _surfaceIntersectStartASL; + _lb = ASLToAGL _surfaceIntersectEndASL; + + if(_la select 2 < 0 && _lb select 2 > 0) then { + _n = [0,0,1]; + _p0 = [0,0,0.1]; + _l = (_la vectorFromTo _lb); + if((_l vectorDotProduct _n) != 0) then { + _d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n); + _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + }; + }; + + _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; + _intersectionASL = []; + { + _intersectionObject = _x select 2; + if(_intersectionObject == _vehicle) exitWith { + _intersectionASL = _x select 0; + }; + } forEach _surfaces; + if(count _intersectionASL > 0) then { + _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); + _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); + } else { + _slingLoadPoints pushBack []; + }; + } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; + + if(count (_slingLoadPoints select 1) > 0) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; + if(count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0 ) then { + if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3 ) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; + if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3 ) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 1,_slingLoadPoints select 2]; + }; + }; + }; + }; + _slingLoadPointsArray; +}; + +ASL_Rope_Set_Mass = { + private ["_obj","_mass"]; + _obj = [_this,0] call BIS_fnc_param; + _mass = [_this,1] call BIS_fnc_param; + _obj setMass _mass; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Set_Mass) _obj: ", _obj, " _mass: ", _mass]; +}; + +ASL_Rope_Adjust_Mass = { + params ["_obj","_heli",["_ropes",[]]]; + private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + private _maxLiftableMass = _lift * 8; + private _originalMass = getMass _obj; + private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE",5000]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; + if( _originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + private _originalMassSet = (getMass _obj) == _originalMass; + while { _obj in (ropeAttachedObjects _heli) && _originalMassSet } do { + { + private _ends = ropeEndPosition _x; + private _endDistance = (_ends select 0) distance (_ends select 1); + private _ropeLength = ropeLength _x; + if((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { + [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + _originalMassSet = false; + }; + } forEach _ropes; + sleep 0.1; + }; + while { _obj in (ropeAttachedObjects _heli) } do { + sleep 0.5; + }; + [[_obj, _originalMass],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + }; +}; + +/* + Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle +*/ +ASL_Get_Active_Ropes = { + params ["_vehicle"]; + private ["_activeRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; + _activeRopes = []; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; + _ropeIndex = 0; + _totalExistingRopes = count _existingRopes; + { + if(count _x > 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _activeRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _activeRopes; +}; + +/* + Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle +*/ +ASL_Get_Inactive_Ropes = { + params ["_vehicle"]; + private ["_inactiveRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; + _inactiveRopes = []; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; + _ropeIndex = 0; + _totalExistingRopes = count _existingRopes; + { + if(count _x == 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _inactiveRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _inactiveRopes; +}; + +ASL_Get_Active_Ropes_With_Cargo = { + params ["_vehicle"]; + private ["_activeRopesWithCargo","_existingCargo","_activeRopes","_cargo"]; + _activeRopesWithCargo = []; + _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _activeRopes = _this call ASL_Get_Active_Ropes; + { + _cargo = _existingCargo select (_x select 0); + if(!isNull _cargo) then { + _activeRopesWithCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithCargo; +}; + +ASL_Get_Active_Ropes_Without_Cargo = { + params ["_vehicle"]; + private ["_activeRopesWithoutCargo","_existingCargo","_activeRopes","_cargo"]; + _activeRopesWithoutCargo = []; + _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _activeRopes = _this call ASL_Get_Active_Ropes; + { + _cargo = _existingCargo select (_x select 0); + if(isNull _cargo) then { + _activeRopesWithoutCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithoutCargo; +}; + +ASL_Get_Ropes = { + params ["_vehicle","_ropeIndex"]; + private ["_allRopes","_selectedRopes"]; + _selectedRopes = []; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _allRopes > _ropeIndex) then { + _selectedRopes = _allRopes select _ropeIndex; + }; + _selectedRopes; +}; + + +ASL_Get_Ropes_Count = { + params ["_vehicle"]; + count (_vehicle getVariable ["ASL_Ropes",[]]); +}; + +ASL_Get_Cargo = { + params ["_vehicle","_ropeIndex"]; + private ["_allCargo","_selectedCargo"]; + _selectedCargo = objNull; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + if(count _allCargo > _ropeIndex) then { + _selectedCargo = _allCargo select _ropeIndex; + }; + _selectedCargo; +}; + +ASL_Get_Ropes_And_Cargo = { + params ["_vehicle","_ropeIndex"]; + private ["_selectedCargo","_selectedRopes"]; + _selectedCargo = (_this call ASL_Get_Cargo); + _selectedRopes = (_this call ASL_Get_Ropes); + [_selectedRopes, _selectedCargo]; +}; + +ASL_Show_Select_Ropes_Menu = { + params ["_title", "_functionName","_ropesIndexAndLabelArray",["_ropesLabel","Ropes"]]; + ASL_Show_Select_Ropes_Menu_Array = [[_title,false]]; + { + ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + } forEach _ropesIndexAndLabelArray; + ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; +}; + +ASL_Extend_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopes"]; + _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + _ropeLength = ropeLength (_existingRopes select 0); + if(_ropeLength <= 100 ) then { + { + ropeUnwind [_x, 3, 5, true]; + } forEach _existingRopes; + }; + }; + } else { + [_this,"ASL_Extend_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Extend_Ropes_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Extend_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; + ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + }; + }; + }; +}; + +ASL_Extend_Ropes_Index_Action = { + params ["_ropeIndex"]; + private ["_vehicle","_canDeployRopes"]; + _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + }; +}; + +ASL_Extend_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Extend_Ropes; +}; + +ASL_Can_Extend_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Shorten_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopes"]; + _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + _ropeLength = ropeLength (_existingRopes select 0); + if(_ropeLength <= 2 ) then { + _this call ASL_Release_Cargo; + } else { + { + if(_ropeLength >= 10) then { + ropeUnwind [_x, 3, -5, true]; + } else { + ropeUnwind [_x, 3, -1, true]; + }; + } forEach _existingRopes; + }; + }; + } else { + [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Shorten_Ropes_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Shorten_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; + ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + }; + }; + }; +}; + +ASL_Shorten_Ropes_Index_Action = { + params ["_ropeIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; + }; +}; + +ASL_Shorten_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Shorten_Ropes; +}; + +ASL_Can_Shorten_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Release_Cargo = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; + _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [_ropeIndex,objNull]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + _this call ASL_Retract_Ropes; + } else { + [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Release_Cargo_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Release_Cargo) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; + ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; + }; + }; + }; +}; + +ASL_Release_Cargo_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + }; +}; + +ASL_Release_Cargo_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Release_Cargo; +}; + +ASL_Can_Release_Cargo = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Retract_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; + _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + if(isNull _existingCargo) then { + _this call ASL_Drop_Ropes; + { + [_x,_vehicle] spawn { + params ["_rope","_vehicle"]; + private ["_count"]; + _count = 0; + ropeUnwind [_rope, 3, 0]; + while {(!ropeUnwound _rope) && _count < 20} do { + sleep 1; + _count = _count + 1; + }; + ropeDestroy _rope; + }; + } forEach _existingRopes; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _allRopes set [_ropeIndex,[]]; + _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes",nil,true]; + }; + } else { + [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Retract_Ropes_Action = { + private ["_vehicle","_canRetractRopes"]; + if(vehicle player == player) then { + _vehicle = cursorTarget; + } else { + _vehicle = vehicle player; + }; + if([_vehicle] call ASL_Can_Retract_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; + ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; + }; + }; + }; +}; + +ASL_Retract_Ropes_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + [_vehicle,player,_ropesIndex] call ASL_Retract_Ropes; + }; +}; + +ASL_Retract_Ropes_Action_Check = { + if(vehicle player == player) then { + [cursorTarget] call ASL_Can_Retract_Ropes; + } else { + [vehicle player] call ASL_Can_Retract_Ropes; + }; +}; + +ASL_Can_Retract_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 30) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Deploy_Ropes = { + params ["_vehicle","_player",["_cargoCount",1],["_ropeLength",15]]; + if(local _vehicle) then { + private ["_existingRopes","_cargoRopes","_startLength","_slingLoadPoints"]; + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _existingRopes == 0) then { + if(count _slingLoadPoints == 0) exitWith { + [["Vehicle doesn't support cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + if(count _slingLoadPoints < _cargoCount) exitWith { + [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + _cargoRopes = []; + _cargo = []; + for "_i" from 0 to (_cargoCount-1) do + { + _cargoRopes pushBack []; + _cargo pushBack objNull; + }; + _vehicle setVariable ["ASL_Ropes",_cargoRopes,true]; + _vehicle setVariable ["ASL_Cargo",_cargo,true]; + for "_i" from 0 to (_cargoCount-1) do + { + [_vehicle,_player,_i] call ASL_Deploy_Ropes_Index; + }; + } else { + [["Vehicle already has cargo ropes deployed", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + } else { + [_this,"ASL_Deploy_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Deploy_Ropes_Index = { + params ["_vehicle","_player",["_ropesIndex",0],["_ropeLength",15]]; + if(local _vehicle) then { + private ["_existingRopes","_existingRopesCount","_allRopes"]; + _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + if(count _existingRopes == 0) then { + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + _cargoRopes = []; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + { + ropeUnwind [_x, 5, _ropeLength]; + } forEach _cargoRopes; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _allRopes set [_ropesIndex,_cargoRopes]; + _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + }; + } else { + [_this,"ASL_Deploy_Ropes_Index",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Deploy_Ropes_Action = { + private ["_vehicle","_canDeployRopes"]; + if(vehicle player == player) then { + _vehicle = cursorTarget; + } else { + _vehicle = vehicle player; + }; + if([_vehicle] call ASL_Can_Deploy_Ropes) then { + + _canDeployRopes = true; + + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked _vehicle > 1 ) then { + ["Cannot deploy cargo ropes from locked vehicle",false] call ASL_Hint; + _canDeployRopes = false; + }; + }; + + if(_canDeployRopes) then { + + _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + + if(count _inactiveRopes > 0) then { + + if(count _inactiveRopes > 1) then { + player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; + ["Deploy Cargo Ropes","ASL_Deploy_Ropes_Index_Action",_inactiveRopes] call ASL_Show_Select_Ropes_Menu; + } else { + [_vehicle,player,(_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + }; + + } else { + + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + if(count _slingLoadPoints > 1) then { + player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [ + ["Deploy Ropes",false] + ]; + ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if((count _slingLoadPoints) > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if((count _slingLoadPoints) > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; + } else { + [_vehicle,player] call ASL_Deploy_Ropes; + }; + + }; + + }; + + }; +}; + +ASL_Deploy_Ropes_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle,player,_ropesIndex] call ASL_Deploy_Ropes_Index; + }; +}; + +ASL_Deploy_Ropes_Count_Action = { + params ["_count"]; + private ["_vehicle","_canDeployRopes"]; + _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + if(_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle,player,_count] call ASL_Deploy_Ropes; + }; +}; + +ASL_Deploy_Ropes_Action_Check = { + if(vehicle player == player) then { + [cursorTarget] call ASL_Can_Deploy_Ropes; + } else { + [vehicle player] call ASL_Can_Deploy_Ropes; + }; +}; + +ASL_Can_Deploy_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; + if(count _existingVehicle > 0) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { true }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { false }; + true; +}; + +ASL_Get_Corner_Points = { + params ["_vehicle"]; + private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; + private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor","_maxHeight","_heightOffset"]; + + // Correct width and length factor for air + _widthFactor = 0.5; + _lengthFactor = 0.5; + if(_vehicle isKindOf "Air") then { + _widthFactor = 0.3; + }; + if(_vehicle isKindOf "Helicopter") then { + _widthFactor = 0.2; + _lengthFactor = 0.45; + }; + + _centerOfMass = getCenterOfMass _vehicle; + _bbr = boundingBoxReal _vehicle; + _p1 = _bbr select 0; + _p2 = _bbr select 1; + _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; + _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; + _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + _heightOffset = _maxHeight/6; + + _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + + [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; +}; + + +ASL_Attach_Ropes = { + params ["_cargo","_player"]; + _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + _vehicle = _vehicleWithIndex select 0; + if(!isNull _vehicle) then { + if(local _vehicle) then { + private ["_ropes","_attachmentPoints","_objDistance","_ropeLength","_allCargo"]; + _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; + if(count _ropes == 4) then { + _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + _ropeLength = (ropeLength (_ropes select 0)); + _objDistance = (_cargo distance _vehicle) + 2; + if( _objDistance > _ropeLength ) then { + [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; + } else { + [_vehicle,_player] call ASL_Drop_Ropes; + [_cargo, _attachmentPoints select 0, [0,0,-1]] ropeAttachTo (_ropes select 0); + [_cargo, _attachmentPoints select 1, [0,0,-1]] ropeAttachTo (_ropes select 1); + [_cargo, _attachmentPoints select 2, [0,0,-1]] ropeAttachTo (_ropes select 2); + [_cargo, _attachmentPoints select 3, [0,0,-1]] ropeAttachTo (_ropes select 3); + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [(_vehicleWithIndex select 1),_cargo]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { + [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + }; + }; + }; + } else { + [_this,"ASL_Attach_Ropes",_vehicle,true] call ASL_RemoteExec; + }; + }; +}; + +ASL_Attach_Ropes_Action = { + private ["_vehicle","_cargo","_canBeAttached"]; + _cargo = cursorTarget; + _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; + if([_vehicle,_cargo] call ASL_Can_Attach_Ropes) then { + + _canBeAttached = true; + + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked _cargo > 1 ) then { + ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; + _canBeAttached = false; + }; + }; + + if!(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { + if(!isNil "ExilePlayerInSafezone") then { + if( ExilePlayerInSafezone ) then { + ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; + _canBeAttached = false; + }; + }; + }; + + if(_canBeAttached) then { + [_cargo,player] call ASL_Attach_Ropes; + }; + + }; +}; + +ASL_Attach_Ropes_Action_Check = { + private ["_vehicleWithIndex","_cargo"]; + _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + _cargo = cursorTarget; + [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; +}; + +ASL_Can_Attach_Ropes = { + params ["_vehicle","_cargo"]; + if(!isNull _vehicle && !isNull _cargo) then { + [_vehicle,_cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; + } else { + false; + }; +}; + +ASL_Drop_Ropes = { + params ["_vehicle","_player",["_ropesIndex",0]]; + if(local _vehicle) then { + private ["_helper","_existingRopes"]; + _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + if(!isNull _helper) then { + _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + { + _helper ropeDetach _x; + } forEach _existingRopes; + detach _helper; + deleteVehicle _helper; + }; + _player setVariable ["ASL_Ropes_Vehicle", nil,true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; + } else { + [_this,"ASL_Drop_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Drop_Ropes_Action = { + private ["_vehicleAndIndex"]; + if([] call ASL_Can_Drop_Ropes) then { + _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; + if(count _vehicleAndIndex == 2) then { + [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + }; + }; +}; + +ASL_Drop_Ropes_Action_Check = { + [] call ASL_Can_Drop_Ropes; +}; + +ASL_Can_Drop_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; +}; + +ASL_Get_Closest_Rope = { + private ["_nearbyVehicles","_closestVehicle","_closestRopeIndex","_closestDistance"]; + private ["_vehicle","_activeRope","_ropes","_ends"]; + private ["_end1","_end2","_minEndDistance"]; + _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; + _closestVehicle = objNull; + _closestRopeIndex = 0; + _closestDistance = -1; + { + _vehicle = _x; + { + _activeRope = _x; + _ropes = [_vehicle,(_activeRope select 0)] call ASL_Get_Ropes; + { + _ends = ropeEndPosition _x; + if(count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); + if(_closestDistance == -1 || _closestDistance > _minEndDistance) then { + _closestDistance = _minEndDistance; + _closestRopeIndex = (_activeRope select 0); + _closestVehicle = _vehicle; + }; + }; + } forEach _ropes; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearbyVehicles; + [_closestVehicle,_closestRopeIndex]; +}; + +ASL_Pickup_Ropes = { + params ["_vehicle","_player",["_ropesIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_helper","_allCargo"]; + _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + if(!isNull _existingCargo) then { + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [_ropesIndex,objNull]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + }; + _helper = "Land_Can_V2_F" createVehicle position _player; + { + [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; + _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; + } forEach _existingRopes; + hideObject _helper; + [[_helper],"ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + _player setVariable ["ASL_Ropes_Vehicle", [_vehicle,_ropesIndex],true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper,true]; + } else { + [_this,"ASL_Pickup_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Pickup_Ropes_Action = { + private ["_nearbyVehicles","_canPickupRopes","_closestRope"]; + _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; + if([] call ASL_Can_Pickup_Ropes) then { + _closestRope = [] call ASL_Get_Closest_Rope; + if(!isNull (_closestRope select 0)) then { + _canPickupRopes = true; + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked (_closestRope select 0) > 1 ) then { + ["Cannot pick up cargo ropes from locked vehicle",false] call ASL_Hint; + _canPickupRopes = false; + }; + }; + if(_canPickupRopes) then { + [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; + }; + }; + }; +}; + +ASL_Pickup_Ropes_Action_Check = { + [] call ASL_Can_Pickup_Ropes; +}; + +ASL_Can_Pickup_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; +}; + +ASL_SUPPORTED_VEHICLES = [ + "Helicopter", + "VTOL_Base_F" +]; + +ASL_Is_Supported_Vehicle = { + params ["_vehicle","_isSupported"]; + _isSupported = false; + if(not isNull _vehicle) then { + { + if(_vehicle isKindOf _x) then { + _isSupported = true; + }; + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); + }; + _isSupported; +}; + +ASL_SLING_RULES = [ + ["All","CAN_SLING","All"] +]; + +ASL_Is_Supported_Cargo = { + params ["_vehicle","_cargo"]; + private ["_canSling"]; + _canSling = false; + if(not isNull _vehicle && not isNull _cargo) then { + { + if(_vehicle isKindOf (_x select 0)) then { + if(_cargo isKindOf (_x select 2)) then { + if( (toUpper (_x select 1)) == "CAN_SLING" ) then { + _canSling = true; + } else { + _canSling = false; + }; + }; + }; + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); + }; + _canSling; +}; + +ASL_Hint = { + params ["_msg",["_isSuccess",true]]; + if(!isNil "ExileClient_gui_notification_event_addNotification") then { + if(_isSuccess) then { + ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + } else { + ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + }; + } else { + hint _msg; + }; +}; + +ASL_Hide_Object_Global = { + params ["_obj"]; + if( _obj isKindOf "Land_Can_V2_F" ) then { + hideObjectGlobal _obj; + }; +}; + +ASL_Find_Nearby_Vehicles = { + private ["_nearVehicles","_nearVehiclesWithRopes","_vehicle","_ends","_end1","_end2","_playerPosAGL"]; + _nearVehicles = []; + { + _nearVehicles append (player nearObjects [_x, 30]); + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); + _nearVehiclesWithRopes = []; + { + _vehicle = _x; + { + _ropes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _ropes > (_x select 0)) then { + _ropes = _ropes select (_x select 0); + { + _ends = ropeEndPosition _x; + if(count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + _playerPosAGL = ASLtoAGL getPosASL player; + if((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { + _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; + } + }; + } forEach _ropes; + }; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearVehicles; + _nearVehiclesWithRopes; +}; + +ASL_Add_Player_Actions = { + + player addAction ["Extend Cargo Ropes", { + [] call ASL_Extend_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; + + player addAction ["Shorten Cargo Ropes", { + [] call ASL_Shorten_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; + + player addAction ["Release Cargo", { + [] call ASL_Release_Cargo_Action; + }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; + + player addAction ["Retract Cargo Ropes", { + [] call ASL_Retract_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; + + player addAction ["Deploy Cargo Ropes", { + [] call ASL_Deploy_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; + + player addAction ["Attach To Cargo Ropes", { + [] call ASL_Attach_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; + + player addAction ["Drop Cargo Ropes", { + [] call ASL_Drop_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; + + player addAction ["Pickup Cargo Ropes", { + [] call ASL_Pickup_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player setVariable ["ASL_Actions_Loaded",false]; + }]; + +}; + +if(!isDedicated) then { + [] spawn { + while {true} do { + if(!isNull player && isPlayer player) then { + if!( player getVariable ["ASL_Actions_Loaded",false] ) then { + [] call ASL_Add_Player_Actions; + player setVariable ["ASL_Actions_Loaded",true]; + }; + }; + missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; + sleep 2; + }; + }; +}; + +ASL_RemoteExec = { + params ["_params","_functionName","_target",["_isCall",false]]; + if(!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; + } else { + if(_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; + }; +}; + +ASL_RemoteExecServer = { + params ["_params","_functionName",["_isCall",false]]; + if(!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; + } else { + if(_isCall) then { + _params remoteExecCall [_functionName, 2]; + } else { + _params remoteExec [_functionName, 2]; + }; + }; +}; + +if(isServer) then { + + // Adds support for exile network calls (Only used when running exile) // + + ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { + params ["_sessionId", "_messageParameters",["_isCall",false]]; + _messageParameters params ["_params","_functionName"]; + if(_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { + if(_isCall) then { + _params call (missionNamespace getVariable [_functionName,{}]); + } else { + _params spawn (missionNamespace getVariable [_functionName,{}]); + }; + }; + }; + + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { + params ["_sessionId", "_messageParameters"]; + _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; + if(_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { + if(_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; + }; + }; + + // Install Advanced Sling Loading on all clients (plus JIP) // + + publicVariable "ASL_Advanced_Sling_Loading_Install"; + remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; + +}; + +// Disable Old Script Version on SA Server +SA_Rope_Action_Check = {false}; +SA_Rope_Pickup_Rope_Action_Check = {false}; +SA_Rope_Drop_Rope_Action_Check = {false}; +SA_Rope_Attach_Rope_Action_Check = {false}; + +diag_log "Advanced Sling Loading Loaded"; + +}; + +if(isServer) then { + [] call ASL_Advanced_Sling_Loading_Install; +}; diff --git a/addons/SA_AdvancedSlingLoading/config.cpp b/addons/SA_AdvancedSlingLoading/config.cpp deleted file mode 100644 index 16ad1ee..0000000 --- a/addons/SA_AdvancedSlingLoading/config.cpp +++ /dev/null @@ -1,38 +0,0 @@ -class CfgPatches -{ - class SA_AdvancedSlingLoading - { - units[] = {"SA_AdvancedSlingLoading"}; - requiredVersion = 1.0; - requiredAddons[] = {"A3_Modules_F"}; - }; -}; - -class CfgNetworkMessages -{ - - class AdvancedSlingLoadingRemoteExecClient - { - module = "AdvancedSlingLoading"; - parameters[] = {"ARRAY","STRING","OBJECT","BOOL"}; - }; - - class AdvancedSlingLoadingRemoteExecServer - { - module = "AdvancedSlingLoading"; - parameters[] = {"ARRAY","STRING","BOOL"}; - }; - -}; - -class CfgFunctions -{ - class SA - { - class AdvancedSlingLoading - { - file = "\SA_AdvancedSlingLoading\functions"; - class advancedSlingLoadingInit{postInit=1;}; - }; - }; -}; diff --git a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf deleted file mode 100644 index 7783971..0000000 --- a/addons/SA_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ /dev/null @@ -1,1075 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2016 Seth Duda - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -ASL_Advanced_Sling_Loading_Install = { - - // Prevent advanced sling loading from installing twice - if (!isNil "ASL_ROPE_INIT") exitWith {}; - ASL_ROPE_INIT = true; - - diag_log "Advanced Sling Loading Loading..."; - - ASL_Rope_Get_Lift_Capability = { - params ["_vehicle"]; - private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); - if (_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = 4000; - }; - _slingLoadMaxCargoMass - }; - - ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ - ["All", [-0.05, -0.05, -0.05]], - ["CUP_CH47F_base", [-0.05, -2, -0.05]], - ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], - ["RHS_CH_47F", [-0.75, -2.6, -0.75]], - ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], - ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] - ]; - - ASL_Get_Sling_Load_Points = { - params ["_vehicle"]; - private _slingLoadPointsArray = []; - private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); - _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; - _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; - private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; - private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - private _slingLoadPointHeightOffset = 0; - { - if (_vehicle isKindOf (_x select 0)) then { - _slingLoadPointHeightOffset = (_x select 1); - }; - } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - - private _slingLoadPoints = []; - { - private _modelPoint = _x; - private _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); - private _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); - private _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); - - // Determine if the surface intersection line crosses below ground level - // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces - // doesn't work if starting below ground level for some reason - // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection - - private _la = ASLToAGL _surfaceIntersectStartASL; - private _lb = ASLToAGL _surfaceIntersectEndASL; - - if (_la select 2 < 0 && _lb select 2 > 0) then { - private _n = [0, 0, 1]; - private _p0 = [0, 0, 0.1]; - private _l = (_la vectorFromTo _lb); - if ((_l vectorDotProduct _n) != 0) then { - private _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n) / (_l vectorDotProduct _n); - _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); - }; - }; - - private _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; - private _intersectionASL = []; - { - private _intersectionObject = _x select 2; - if (_intersectionObject == _vehicle) exitWith { - _intersectionASL = _x select 0; - }; - } forEach _surfaces; - if (count _intersectionASL > 0) then { - _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); - _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); - } else { - _slingLoadPoints pushBack []; - }; - } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - - if (count (_slingLoadPoints select 1) > 0) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 1, _slingLoadPoints select 2]; - }; - }; - }; - }; - _slingLoadPointsArray - }; - - ASL_Rope_Set_Mass = { - private _obj = [_this,0] call BIS_fnc_param; - private _mass = [_this,1] call BIS_fnc_param; - _obj setMass _mass; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Set_Mass) _obj: ", _obj, " _mass: ", _mass]; - }; - - ASL_Rope_Adjust_Mass = { - params ["_obj", "_heli", ["_ropes", []]]; - private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - private _maxLiftableMass = _lift * 8; // define a maximum mass, which can be lifted - private _originalMass = getMass _obj; - private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; - if (_originalMass >= ((_lift) * 0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { - private _originalMassSet = (getMass _obj) == _originalMass; - while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { - { - private _ends = ropeEndPosition _x; - private _endDistance = (_ends select 0) distance (_ends select 1); - private _ropeLength = ropeLength _x; - if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { - [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; - _originalMassSet = false; - }; - } forEach _ropes; - sleep 0.1; - }; - while {_obj in (ropeAttachedObjects _heli)} do { - sleep 0.5; - }; - [[_obj, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; - }; - }; - - ASL_Get_Active_Ropes = { // Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle - params ["_vehicle"]; - private _activeRopes = []; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front","Rear"], ["Front", "Center", "Rear"]]; - private _ropeIndex = 0; - private _totalExistingRopes = count _existingRopes; - { - if(count _x > 0) then { - private _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _activeRopes - }; - - ASL_Get_Inactive_Ropes = { // Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle - params ["_vehicle"]; - private _inactiveRopes = []; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front","Rear"], ["Front","Center","Rear"]]; - private _ropeIndex = 0; - private _totalExistingRopes = count _existingRopes; - { - if (count _x == 0) then { - private _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _inactiveRopes - }; - - ASL_Get_Active_Ropes_With_Cargo = { - params ["_vehicle"]; - private _activeRopesWithCargo = []; - private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - private _activeRopes = _this call ASL_Get_Active_Ropes; - { - private _cargo = _existingCargo select (_x select 0); - if (!isNull _cargo) then { - _activeRopesWithCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithCargo - }; - - ASL_Get_Active_Ropes_Without_Cargo = { - params ["_vehicle"]; - private _activeRopesWithoutCargo = []; - private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - private _activeRopes = _this call ASL_Get_Active_Ropes; - { - private _cargo = _existingCargo select (_x select 0); - if (isNull _cargo) then { - _activeRopesWithoutCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithoutCargo - }; - - ASL_Get_Ropes = { - params ["_vehicle", "_ropeIndex"]; - private _selectedRopes = []; - private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _allRopes > _ropeIndex) then { - _selectedRopes = _allRopes select _ropeIndex; - }; - _selectedRopes - }; - - ASL_Get_Ropes_Count = { - params ["_vehicle"]; - count (_vehicle getVariable ["ASL_Ropes", []]); - }; - - ASL_Get_Cargo = { - params ["_vehicle", "_ropeIndex"]; - private _selectedCargo = objNull; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - if (count _allCargo > _ropeIndex) then { - _selectedCargo = _allCargo select _ropeIndex; - }; - _selectedCargo - }; - - ASL_Get_Ropes_And_Cargo = { - params ["_vehicle", "_ropeIndex"]; - private _selectedCargo = (_this call ASL_Get_Cargo); - private _selectedRopes = (_this call ASL_Get_Ropes); - [_selectedRopes, _selectedCargo]; - }; - - ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", "Ropes"]]; - ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; - { - ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "[" + (str (_x select 0)) + "] call " + _functionName]], "1", "1"]; - } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; - }; - - ASL_Extend_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; - if (local _vehicle) then { - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= 100) then { - { - ropeUnwind [_x, 3, 5, true]; - } forEach _existingRopes; - }; - }; - } else { - [_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Extend_Ropes_Action = { - private _vehicle = vehicle player; - if ([_vehicle] call ASL_Can_Extend_Ropes) then { - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes > 1) then { - player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if (count _activeRopes == 1) then { - [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; - }; - }; - }; - }; - - ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; - }; - }; - - ASL_Extend_Ropes_Action_Check = { - if (vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Extend_Ropes; - }; - - ASL_Can_Extend_Ropes = { - params ["_vehicle"]; - if (player distance _vehicle > 10) exitWith {false}; - if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if ((count _existingRopes) == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if ((count _activeRopes) == 0) exitWith {false}; - true - }; - - ASL_Shorten_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex",0]]; - if (local _vehicle) then { - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; - if (count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= 2) then { - _this call ASL_Release_Cargo; - } else { - { - if (_ropeLength >= 10) then { - ropeUnwind [_x, 3, -5, true]; - } else { - ropeUnwind [_x, 3, -1, true]; - }; - } forEach _existingRopes; - }; - }; - } else { - [_this, "ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Shorten_Ropes_Action = { - private _vehicle = vehicle player; - if ([_vehicle] call ASL_Can_Shorten_Ropes) then { - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes > 1) then { - player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes", "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if (count _activeRopes == 1) then { - [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; - }; - }; - }; - }; - - ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; - }; - }; - - ASL_Shorten_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Shorten_Ropes; - }; - - ASL_Can_Shorten_Ropes = { - params ["_vehicle"]; - if (player distance _vehicle > 10) exitWith {false}; - if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if ((count _existingRopes) == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if ((count _activeRopes) == 0) exitWith {false}; - true - }; - - ASL_Release_Cargo = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; - if (local _vehicle) then { - private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [_ropeIndex, objNull]; - _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - _this call ASL_Retract_Ropes; - } else { - [_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Release_Cargo_Action = { - private _vehicle = vehicle player; - if ([_vehicle] call ASL_Can_Release_Cargo) then { - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if (count _activeRopes > 1) then { - player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo", "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; - } else { - if (count _activeRopes == 1) then { - [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Release_Cargo; - }; - }; - }; - }; - - ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; - }; - }; - - ASL_Release_Cargo_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Release_Cargo; - }; - - ASL_Can_Release_Cargo = { - params ["_vehicle"]; - if (player distance _vehicle > 10) exitWith {false}; - if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if ((count _existingRopes) == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if ((count _activeRopes) == 0) exitWith {false}; - true - }; - - ASL_Retract_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; - if (local _vehicle) then { - private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - if (isNull _existingCargo) then { - _this call ASL_Drop_Ropes; - { - [_x, _vehicle] spawn { - params ["_rope", "_vehicle"]; - private _count = 0; - ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; - }; - ropeDestroy _rope; - }; - } forEach _existingRopes; - private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - _allRopes set [_ropeIndex, []]; - _vehicle setVariable ["ASL_Ropes", _allRopes, true]; - }; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes", nil, true]; - }; - } else { - [_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Retract_Ropes_Action = { - private ["_vehicle"]; - if (vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if ([_vehicle] call ASL_Can_Retract_Ropes) then { - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if (count _activeRopes > 1) then { - player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes", "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if (count _activeRopes == 1) then { - [_vehicle, player, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; - }; - }; - }; - }; - - ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { - [_vehicle, player, _ropesIndex] call ASL_Retract_Ropes; - }; - }; - - ASL_Retract_Ropes_Action_Check = { - if (vehicle player == player) then { - [cursorTarget] call ASL_Can_Retract_Ropes; - } else { - [vehicle player] call ASL_Can_Retract_Ropes; - }; - }; - - ASL_Can_Retract_Ropes = { - params ["_vehicle"]; - if (player distance _vehicle > 30) exitWith {false}; - if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if ((count _existingRopes) == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if ((count _activeRopes) == 0) exitWith {false}; - true - }; - - ASL_Deploy_Ropes = { - params ["_vehicle", "_player", ["_cargoCount", 1], ["_ropeLength", 15]]; - if (local _vehicle) then { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _existingRopes == 0) then { - if (count _slingLoadPoints == 0) exitWith { - [["Vehicle doesn't support cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - if (count _slingLoadPoints < _cargoCount) exitWith { - [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - private _cargoRopes = []; - private _cargo = []; - for "_i" from 0 to (_cargoCount-1) do { - _cargoRopes pushBack []; - _cargo pushBack objNull; - }; - _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; - _vehicle setVariable ["ASL_Cargo", _cargo, true]; - for "_i" from 0 to (_cargoCount-1) do { - [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; - }; - } else { - [["Vehicle already has cargo ropes deployed", false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - } else { - [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Deploy_Ropes_Index = { - params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; - if (local _vehicle) then { - private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if (count _existingRopes == 0) then { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - private _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - { - ropeUnwind [_x, 5, _ropeLength]; - } forEach _cargoRopes; - private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - _allRopes set [_ropesIndex, _cargoRopes]; - _vehicle setVariable ["ASL_Ropes", _allRopes, true]; - }; - } else { - [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Deploy_Ropes_Action = { - private ["_vehicle"]; - if (vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if ([_vehicle] call ASL_Can_Deploy_Ropes) then { - private _canDeployRopes = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked _vehicle > 1) then { - ["Cannot deploy cargo ropes from locked vehicle", false] call ASL_Hint; - _canDeployRopes = false; - }; - }; - if (_canDeployRopes) then { - private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; - if (count _inactiveRopes > 0) then { - - if (count _inactiveRopes > 1) then { - player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - ["Deploy Cargo Ropes", "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; - } else { - [_vehicle, player, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; - }; - } else { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if (count _slingLoadPoints > 1) then { - player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [["Deploy Ropes", false]]; - ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if ((count _slingLoadPoints) > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - if ((count _slingLoadPoints) > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; - } else { - [_vehicle, player] call ASL_Deploy_Ropes; - }; - }; - }; - }; - }; - - ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; - }; - }; - - ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; - private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - if (_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _count] call ASL_Deploy_Ropes; - }; - }; - - ASL_Deploy_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Deploy_Ropes; - } else { - [vehicle player] call ASL_Can_Deploy_Ropes; - }; - }; - - ASL_Can_Deploy_Ropes = { - params ["_vehicle"]; - if (player distance _vehicle > 10) exitWith {false}; - if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; - if (count _existingVehicle > 0) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if ((count _existingRopes) == 0) exitWith {true}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if ((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith {false}; - true - }; - - ASL_Get_Corner_Points = { - params ["_vehicle"]; - private _widthFactor = 0.5; // Correct width and length factor for air - private _lengthFactor = 0.5; - if (_vehicle isKindOf "Air") then { - _widthFactor = 0.3; - }; - if (_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; - }; - private _centerOfMass = getCenterOfMass _vehicle; - private _bbr = boundingBoxReal _vehicle; - private _p1 = _bbr select 0; - private _p2 = _bbr select 1; - private _maxWidth = abs((_p2 select 0) - (_p1 select 0)); - private _widthOffset = ((_maxWidth / 2) - abs(_centerOfMass select 0)) * _widthFactor; - private _maxLength = abs((_p2 select 1) - (_p1 select 1)); - private _lengthOffset = ((_maxLength / 2) - abs(_centerOfMass select 1)) * _lengthFactor; - private _maxHeight = abs((_p2 select 2) - (_p1 select 2)); - private _heightOffset = _maxHeight / 6; - private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; - }; - - ASL_Attach_Ropes = { - params ["_cargo", "_player"]; - private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - private _vehicle = _vehicleWithIndex select 0; - if (!isNull _vehicle) then { - if (local _vehicle) then { - private _ropes = [_vehicle, (_vehicleWithIndex select 1)] call ASL_Get_Ropes; - if (count _ropes == 4) then { - private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - private _ropeLength = (ropeLength (_ropes select 0)); - private _objDistance = (_cargo distance _vehicle) + 2; - if ( _objDistance > _ropeLength ) then { - [["The cargo ropes are too short. Move vehicle closer.", false], "ASL_Hint", _player] call ASL_RemoteExec; - } else { - [_vehicle,_player] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [(_vehicleWithIndex select 1), _cargo]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - }; - }; - }; - } else { - [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - }; - - ASL_Attach_Ropes_Action = { - private _cargo = cursorTarget; - private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; - if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { - private _canBeAttached = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked _cargo > 1) then { - ["Cannot attach cargo ropes to locked vehicle", false] call ASL_Hint; - _canBeAttached = false; - }; - }; - if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { - if (!isNil "ExilePlayerInSafezone") then { - if ( ExilePlayerInSafezone ) then { - ["Cannot attach cargo ropes in safe zone", false] call ASL_Hint; - _canBeAttached = false; - }; - }; - }; - if (_canBeAttached) then { - [_cargo, player] call ASL_Attach_Ropes; - }; - }; - }; - - ASL_Attach_Ropes_Action_Check = { - private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - private _cargo = cursorTarget; - [_vehicleWithIndex select 0, _cargo] call ASL_Can_Attach_Ropes; - }; - - ASL_Can_Attach_Ropes = { - params ["_vehicle", "_cargo"]; - if (!isNull _vehicle && !isNull _cargo) then { - [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - } else { - false; - }; - }; - - ASL_Drop_Ropes = { - params ["_vehicle", "_player", ["_ropesIndex", 0]]; - if (local _vehicle) then { - private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - if (!isNull _helper) then { - private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - { - _helper ropeDetach _x; - } forEach _existingRopes; - detach _helper; - deleteVehicle _helper; - }; - _player setVariable ["ASL_Ropes_Vehicle", nil, true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; - } else { - [_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Drop_Ropes_Action = { - if ([] call ASL_Can_Drop_Ropes) then { - private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - if (count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; - }; - }; - }; - - ASL_Drop_Ropes_Action_Check = { - [] call ASL_Can_Drop_Ropes; - }; - - ASL_Can_Drop_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; - }; - - ASL_Get_Closest_Rope = { - private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; - private _closestVehicle = objNull; - private _closestRopeIndex = 0; - private _closestDistance = -1; - { - private _vehicle = _x; - { - private _activeRope = _x; - private _ropes = [_vehicle, (_activeRope select 0)] call ASL_Get_Ropes; - { - private _ends = ropeEndPosition _x; - if (count _ends == 2) then { - private _end1 = _ends select 0; - private _end2 = _ends select 1; - private _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); - if (_closestDistance == -1 || _closestDistance > _minEndDistance) then { - _closestDistance = _minEndDistance; - _closestRopeIndex = (_activeRope select 0); - _closestVehicle = _vehicle; - }; - }; - } forEach _ropes; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearbyVehicles; - [_closestVehicle, _closestRopeIndex]; - }; - - ASL_Pickup_Ropes = { - params ["_vehicle", "_player", ["_ropesIndex", 0]]; - if (local _vehicle) then { - private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - if (!isNull _existingCargo) then { - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [_ropesIndex, objNull]; - _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - }; - private _helper = "Land_Can_V2_F" createVehicle position _player; - { - [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; - _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - } forEach _existingRopes; - hideObject _helper; - [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - } else { - [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Pickup_Ropes_Action = { - if ([] call ASL_Can_Pickup_Ropes) then { - private _closestRope = [] call ASL_Get_Closest_Rope; - if (!isNull (_closestRope select 0)) then { - private _canPickupRopes = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked (_closestRope select 0) > 1) then { - ["Cannot pick up cargo ropes from locked vehicle", false] call ASL_Hint; - _canPickupRopes = false; - }; - }; - if (_canPickupRopes) then { - [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - }; - }; - }; - }; - - ASL_Pickup_Ropes_Action_Check = { - [] call ASL_Can_Pickup_Ropes; - }; - - ASL_Can_Pickup_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles", []]) > 0 && vehicle player == player; - }; - - ASL_SUPPORTED_VEHICLES = [ - "Helicopter", - "VTOL_Base_F" - ]; - - ASL_Is_Supported_Vehicle = { - params ["_vehicle"]; - private _isSupported = false; - if (not isNull _vehicle) then { - { - if (_vehicle isKindOf _x) exitWith {_isSupported = true}; - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); - }; - _isSupported - }; - - ASL_SLING_RULES = [ - ["All", "CAN_SLING","All"] - ]; - - ASL_Is_Supported_Cargo = { - params ["_vehicle", "_cargo"]; - private _canSling = false; - if (not isNull _vehicle && not isNull _cargo) then { - { - if (_vehicle isKindOf (_x select 0)) then { - if (_cargo isKindOf (_x select 2)) then { - if ((toUpper (_x select 1)) == "CAN_SLING") then { - _canSling = true; - } else { - _canSling = false; - }; - }; - }; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); - }; - _canSling - }; - - ASL_Hint = { - params ["_msg", ["_isSuccess", true]]; - if (!isNil "ExileClient_gui_notification_event_addNotification") then { - if (_isSuccess) then { - ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; - } else { - ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; - }; - } else { - hint _msg; - }; - }; - - ASL_Hide_Object_Global = { - params ["_obj"]; - if (_obj isKindOf "Land_Can_V2_F") then { - hideObjectGlobal _obj; - }; - }; - - ASL_Find_Nearby_Vehicles = { - private _nearVehicles = []; - { - _nearVehicles append (player nearObjects [_x, 30]); - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); - private _nearVehiclesWithRopes = []; - { - private _vehicle = _x; - { - private _ropes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _ropes > (_x select 0)) then { - _ropes = _ropes select (_x select 0); - { - private _ends = ropeEndPosition _x; - if (count _ends == 2) then { - private _end1 = _ends select 0; - private _end2 = _ends select 1; - private _playerPosAGL = ASLtoAGL getPosASL player; - if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { - _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - } - }; - } forEach _ropes; - }; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearVehicles; - _nearVehiclesWithRopes - }; - - ASL_Add_Player_Actions = { - player addAction ["Extend Cargo Ropes", { - [] call ASL_Extend_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; - - player addAction ["Shorten Cargo Ropes", { - [] call ASL_Shorten_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; - - player addAction ["Release Cargo", { - [] call ASL_Release_Cargo_Action; - }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; - - player addAction ["Retract Cargo Ropes", { - [] call ASL_Retract_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; - - player addAction ["Deploy Cargo Ropes", { - [] call ASL_Deploy_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; - - player addAction ["Attach To Cargo Ropes", { - [] call ASL_Attach_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - - player addAction ["Drop Cargo Ropes", { - [] call ASL_Drop_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - - player addAction ["Pickup Cargo Ropes", { - [] call ASL_Pickup_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - - player addEventHandler ["Respawn", { - player setVariable ["ASL_Actions_Loaded", false]; - }]; - }; - - if (!isDedicated) then { - [] spawn { - while {true} do { - if (!isNull player && isPlayer player) then { - if !(player getVariable ["ASL_Actions_Loaded", false]) then { - [] call ASL_Add_Player_Actions; - player setVariable ["ASL_Actions_Loaded", true]; - }; - }; - missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - sleep 2; - }; - }; - }; - - ASL_RemoteExec = { - params ["_params", "_functionName", "_target", ["_isCall", false]]; - if (!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecClient", [_params, _functionName, _target, _isCall]] call ExileClient_system_network_send; - } else { - if (_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; - }; - }; - }; - - ASL_RemoteExecServer = { - params ["_params", "_functionName", ["_isCall", false]]; - if (!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; - } else { - if (_isCall) then { - _params remoteExecCall [_functionName, 2]; - } else { - _params remoteExec [_functionName, 2]; - }; - }; - }; - - if (isServer) then { // Adds support for exile network calls (Only used when running exile) - ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; - - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { - params ["_sessionId", "_messageParameters", ["_isCall", false]]; - _messageParameters params ["_params", "_functionName"]; - if (_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { - if (_isCall) then { - _params call (missionNamespace getVariable [_functionName, {}]); - } else { - _params spawn (missionNamespace getVariable [_functionName, {}]); - }; - }; - }; - - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes", "ASL_Deploy_Ropes_Index", "ASL_Rope_Set_Mass", "ASL_Extend_Ropes", "ASL_Shorten_Ropes", "ASL_Release_Cargo", "ASL_Retract_Ropes", "ASL_Deploy_Ropes", "ASL_Hint", "ASL_Attach_Ropes", "ASL_Drop_Ropes"]; - - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { - params ["_sessionId", "_messageParameters"]; - _messageParameters params ["_params", "_functionName", "_target", ["_isCall", false]]; - if (_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { - if (_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; - }; - }; - }; - - publicVariable "ASL_Advanced_Sling_Loading_Install"; // Install Advanced Sling Loading on all clients (plus JIP) - remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; - }; - - // Disable Old Script Version on SA Server - SA_Rope_Action_Check = {false}; - SA_Rope_Pickup_Rope_Action_Check = {false}; - SA_Rope_Drop_Rope_Action_Check = {false}; - SA_Rope_Attach_Rope_Action_Check = {false}; - - diag_log "Advanced Sling Loading Loaded"; -}; - -if (isServer) then { - [] call ASL_Advanced_Sling_Loading_Install; -}; diff --git a/config.bin b/config.bin new file mode 100644 index 0000000000000000000000000000000000000000..9f9de7a9f21cf01b7190d9ad857b0fc1ae3f34da GIT binary patch literal 664 zcmb7?&rZTX5XPs)gO5W2sT>OdgW+FVVq(OQO?O%v+Ai*H(W3_+!Kd;GJoq3Uon4fJ zDJC}AHvM+``)0o>NVWjF&S|~6bUTAVk}jBzH>lv=Y|;A+^`ns6DJsQM(m%fSQB}q| z6QzPThom@3r-CcEBanqT5C!Xi?^zimkMgWcCxUT$z%!LwO2e(nOe;8D>bMdgs!Srk zL8-`%Y5|U7z`1F_fuOx6_bNxV9v#>&)Om+k2#v!hj0bs!rG~EI{aqQM+@pjSsX!ly!Z5f6h?e1ab_Fo+Uk?XMfc|_wu|)U>t?`>?DYhq*AiPtD zCVrDgUGASh`{bEqIl}71gjUIMw!msgW11R_$m!tbxI3Y=6-}B}BnwvQjga7XFS?%B jyY$+g-}HOECbg%t0(UIlA_uSIw_D9l>#}wDZ3yrM+UmJc literal 0 HcmV?d00001 diff --git a/functions/fn_advancedSlingLoadingInit.sqf b/functions/fn_advancedSlingLoadingInit.sqf new file mode 100644 index 0000000..478de4f --- /dev/null +++ b/functions/fn_advancedSlingLoadingInit.sqf @@ -0,0 +1,1166 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Seth Duda + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +ASL_Advanced_Sling_Loading_Install = { + +// Prevent advanced sling loading from installing twice +if(!isNil "ASL_ROPE_INIT") exitWith {}; +ASL_ROPE_INIT = true; + +diag_log "Advanced Sling Loading Loading..."; + +ASL_Rope_Get_Lift_Capability = { + params ["_vehicle"]; + private ["_slingLoadMaxCargoMass"]; + _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + if(_slingLoadMaxCargoMass <= 0) then { + _slingLoadMaxCargoMass = 4000; + }; + _slingLoadMaxCargoMass; +}; + +ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ + ["All", [-0.05, -0.05, -0.05]], + ["CUP_CH47F_base", [-0.05, -2, -0.05]], + ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], + ["RHS_CH_47F", [-0.75, -2.6, -0.75]], + ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], + ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] +]; + +ASL_Get_Sling_Load_Points = { + params ["_vehicle"]; + private ["_modelPoint", "_modelPointASL", "_surfaceIntersectStartASL", "_surfaceIntersectEndASL", "_la", "_lb", "_n", "_p0", "_l", "_d", "_surfaces","_intersectionASL", "_intersectionObject"]; + private _slingLoadPointsArray = []; + private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; + private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); + private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; + _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; + private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; + private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); + + private _slingLoadPointHeightOffset = 0; + { + if (_vehicle isKindOf (_x select 0)) then { + _slingLoadPointHeightOffset = (_x select 1); + }; + } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; + + private _slingLoadPoints = []; + { + _modelPoint = _x; + _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); + _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); + _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); + + // Determine if the surface intersection line crosses below ground level + // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces + // doesn't work if starting below ground level for some reason + // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection + + _la = ASLToAGL _surfaceIntersectStartASL; + _lb = ASLToAGL _surfaceIntersectEndASL; + + if (_la select 2 < 0 && _lb select 2 > 0) then { + _n = [0, 0, 1]; + _p0 = [0, 0, 0.1]; + _l = (_la vectorFromTo _lb); + if((_l vectorDotProduct _n) != 0) then { + _d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n); + _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + }; + }; + + _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; + _intersectionASL = []; + { + _intersectionObject = _x select 2; + if(_intersectionObject == _vehicle) exitWith { + _intersectionASL = _x select 0; + }; + } forEach _surfaces; + if (count _intersectionASL > 0) then { + _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); + _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); + } else { + _slingLoadPoints pushBack []; + }; + } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; + + if (count (_slingLoadPoints select 1) > 0) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; + if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 1,_slingLoadPoints select 2]; + }; + }; + }; + }; + _slingLoadPointsArray; +}; + +ASL_Rope_Set_Mass = { + private _obj = [_this,0] call BIS_fnc_param; + private _mass = [_this,1] call BIS_fnc_param; + _obj setMass _mass; +}; + +ASL_Rope_Adjust_Mass = { + params ["_obj","_heli",["_ropes",[]]]; + private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + private _originalMass = getMass _obj; + private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; + if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift) then { + private _originalMassSet = (getMass _obj) == _originalMass; + private ["_ends", "_endDistance", "_ropeLength"]; + while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { + { + _ends = ropeEndPosition _x; + _endDistance = (_ends select 0) distance (_ends select 1); + _ropeLength = ropeLength _x; + if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0) then { + [[_obj, ((_lift)*0.8)],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + _originalMassSet = false; + }; + } forEach _ropes; + sleep 0.1; + }; + while {_obj in (ropeAttachedObjects _heli)} do { + sleep 0.5; + }; + [[_obj, _originalMass],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + }; +}; + +/* + Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle +*/ +ASL_Get_Active_Ropes = { + params ["_vehicle"]; + private _activeRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + private ["_ropeLabels"]; + { + if (count _x > 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _activeRopes; +}; + +/* + Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle +*/ +ASL_Get_Inactive_Ropes = { + params ["_vehicle"]; + private _inactiveRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + private ["_ropeLabels"]; + { + if (count _x == 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _inactiveRopes; +}; + +ASL_Get_Active_Ropes_With_Cargo = { + params ["_vehicle"]; + private ["_activeRopesWithCargo","_existingCargo","_activeRopes","_cargo"]; + _activeRopesWithCargo = []; + _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _activeRopes = _this call ASL_Get_Active_Ropes; + { + _cargo = _existingCargo select (_x select 0); + if(!isNull _cargo) then { + _activeRopesWithCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithCargo; +}; + +ASL_Get_Active_Ropes_Without_Cargo = { + params ["_vehicle"]; + private ["_activeRopesWithoutCargo","_existingCargo","_activeRopes","_cargo"]; + _activeRopesWithoutCargo = []; + _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _activeRopes = _this call ASL_Get_Active_Ropes; + { + _cargo = _existingCargo select (_x select 0); + if(isNull _cargo) then { + _activeRopesWithoutCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithoutCargo; +}; + +ASL_Get_Ropes = { + params ["_vehicle","_ropeIndex"]; + private ["_allRopes","_selectedRopes"]; + _selectedRopes = []; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _allRopes > _ropeIndex) then { + _selectedRopes = _allRopes select _ropeIndex; + }; + _selectedRopes; +}; + + +ASL_Get_Ropes_Count = { + params ["_vehicle"]; + count (_vehicle getVariable ["ASL_Ropes",[]]); +}; + +ASL_Get_Cargo = { + params ["_vehicle","_ropeIndex"]; + private ["_allCargo","_selectedCargo"]; + _selectedCargo = objNull; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + if(count _allCargo > _ropeIndex) then { + _selectedCargo = _allCargo select _ropeIndex; + }; + _selectedCargo; +}; + +ASL_Get_Ropes_And_Cargo = { + params ["_vehicle","_ropeIndex"]; + private ["_selectedCargo","_selectedRopes"]; + _selectedCargo = (_this call ASL_Get_Cargo); + _selectedRopes = (_this call ASL_Get_Ropes); + [_selectedRopes, _selectedCargo]; +}; + +ASL_Show_Select_Ropes_Menu = { + params ["_title", "_functionName","_ropesIndexAndLabelArray",["_ropesLabel","Ropes"]]; + ASL_Show_Select_Ropes_Menu_Array = [[_title,false]]; + { + ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + } forEach _ropesIndexAndLabelArray; + ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; +}; + +ASL_Extend_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopes"]; + _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + _ropeLength = ropeLength (_existingRopes select 0); + if(_ropeLength <= 100 ) then { + { + ropeUnwind [_x, 3, 5, true]; + } forEach _existingRopes; + }; + }; + } else { + [_this,"ASL_Extend_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Extend_Ropes_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Extend_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; + ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + }; + }; + }; +}; + +ASL_Extend_Ropes_Index_Action = { + params ["_ropeIndex"]; + private ["_vehicle","_canDeployRopes"]; + _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + }; +}; + +ASL_Extend_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Extend_Ropes; +}; + +ASL_Can_Extend_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Shorten_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopes"]; + _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; + if(count _existingRopes > 0) then { + _ropeLength = ropeLength (_existingRopes select 0); + if(_ropeLength <= 2 ) then { + _this call ASL_Release_Cargo; + } else { + { + if(_ropeLength >= 10) then { + ropeUnwind [_x, 3, -5, true]; + } else { + ropeUnwind [_x, 3, -1, true]; + }; + } forEach _existingRopes; + }; + }; + } else { + [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Shorten_Ropes_Action = { + private ["_vehicle"]; + _vehicle = vehicle player; + if([_vehicle] call ASL_Can_Shorten_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; + ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + }; + }; + }; +}; + +ASL_Shorten_Ropes_Index_Action = { + params ["_ropeIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; + }; +}; + +ASL_Shorten_Ropes_Action_Check = { + if(vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Shorten_Ropes; +}; + +ASL_Can_Shorten_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Release_Cargo = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; + _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [_ropeIndex,objNull]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + _this call ASL_Retract_Ropes; + } else { + [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Release_Cargo_Action = { + private _vehicle = vehicle player; + if ([_vehicle] call ASL_Can_Release_Cargo) then { + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; + ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; + }; + }; + }; +}; + +ASL_Release_Cargo_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + }; +}; + +ASL_Release_Cargo_Action_Check = { + if (vehicle player == player) exitWith {false}; + [vehicle player] call ASL_Can_Release_Cargo; +}; + +ASL_Can_Release_Cargo = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Retract_Ropes = { + params ["_vehicle","_player",["_ropeIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; + _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + if(isNull _existingCargo) then { + _this call ASL_Drop_Ropes; + { + [_x,_vehicle] spawn { + params ["_rope","_vehicle"]; + private ["_count"]; + _count = 0; + ropeUnwind [_rope, 3, 0]; + while {(!ropeUnwound _rope) && _count < 20} do { + sleep 1; + _count = _count + 1; + }; + ropeDestroy _rope; + }; + } forEach _existingRopes; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _allRopes set [_ropeIndex,[]]; + _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if(count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes",nil,true]; + }; + } else { + [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Retract_Ropes_Action = { + private ["_vehicle","_canRetractRopes"]; + if(vehicle player == player) then { + _vehicle = cursorTarget; + } else { + _vehicle = vehicle player; + }; + if([_vehicle] call ASL_Can_Retract_Ropes) then { + private ["_activeRopes"]; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if(count _activeRopes > 1) then { + player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; + ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; + } else { + if(count _activeRopes == 1) then { + [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; + }; + }; + }; +}; + +ASL_Retract_Ropes_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + [_vehicle,player,_ropesIndex] call ASL_Retract_Ropes; + }; +}; + +ASL_Retract_Ropes_Action_Check = { + if(vehicle player == player) then { + [cursorTarget] call ASL_Can_Retract_Ropes; + } else { + [vehicle player] call ASL_Can_Retract_Ropes; + }; +}; + +ASL_Can_Retract_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 30) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { false }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if((count _activeRopes) == 0) exitWith { false }; + true; +}; + +ASL_Deploy_Ropes = { + params ["_vehicle","_player",["_cargoCount",1],["_ropeLength",15]]; + if(local _vehicle) then { + private ["_existingRopes","_cargoRopes","_startLength","_slingLoadPoints"]; + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _existingRopes == 0) then { + if(count _slingLoadPoints == 0) exitWith { + [["Vehicle doesn't support cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + if(count _slingLoadPoints < _cargoCount) exitWith { + [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + _cargoRopes = []; + _cargo = []; + for "_i" from 0 to (_cargoCount-1) do + { + _cargoRopes pushBack []; + _cargo pushBack objNull; + }; + _vehicle setVariable ["ASL_Ropes",_cargoRopes,true]; + _vehicle setVariable ["ASL_Cargo",_cargo,true]; + for "_i" from 0 to (_cargoCount-1) do + { + [_vehicle,_player,_i] call ASL_Deploy_Ropes_Index; + }; + } else { + [["Vehicle already has cargo ropes deployed", false],"ASL_Hint",_player] call ASL_RemoteExec; + }; + } else { + [_this,"ASL_Deploy_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Deploy_Ropes_Index = { + params ["_vehicle","_player",["_ropesIndex",0],["_ropeLength",15]]; + if(local _vehicle) then { + private ["_existingRopes","_existingRopesCount","_allRopes"]; + _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + if(count _existingRopes == 0) then { + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + _cargoRopes = []; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + { + ropeUnwind [_x, 5, _ropeLength]; + } forEach _cargoRopes; + _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; + _allRopes set [_ropesIndex,_cargoRopes]; + _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + }; + } else { + [_this,"ASL_Deploy_Ropes_Index",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Deploy_Ropes_Action = { + private ["_vehicle","_canDeployRopes"]; + if(vehicle player == player) then { + _vehicle = cursorTarget; + } else { + _vehicle = vehicle player; + }; + if([_vehicle] call ASL_Can_Deploy_Ropes) then { + + _canDeployRopes = true; + + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked _vehicle > 1 ) then { + ["Cannot deploy cargo ropes from locked vehicle",false] call ASL_Hint; + _canDeployRopes = false; + }; + }; + + if(_canDeployRopes) then { + + _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + + if(count _inactiveRopes > 0) then { + + if(count _inactiveRopes > 1) then { + player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; + ["Deploy Cargo Ropes","ASL_Deploy_Ropes_Index_Action",_inactiveRopes] call ASL_Show_Select_Ropes_Menu; + } else { + [_vehicle,player,(_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + }; + + } else { + + _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + if(count _slingLoadPoints > 1) then { + player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [ + ["Deploy Ropes",false] + ]; + ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if((count _slingLoadPoints) > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if((count _slingLoadPoints) > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; + } else { + [_vehicle,player] call ASL_Deploy_Ropes; + }; + + }; + + }; + + }; +}; + +ASL_Deploy_Ropes_Index_Action = { + params ["_ropesIndex"]; + private ["_vehicle"]; + _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle,player,_ropesIndex] call ASL_Deploy_Ropes_Index; + }; +}; + +ASL_Deploy_Ropes_Count_Action = { + params ["_count"]; + private ["_vehicle","_canDeployRopes"]; + _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + if(_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + [_vehicle,player,_count] call ASL_Deploy_Ropes; + }; +}; + +ASL_Deploy_Ropes_Action_Check = { + if(vehicle player == player) then { + [cursorTarget] call ASL_Can_Deploy_Ropes; + } else { + [vehicle player] call ASL_Can_Deploy_Ropes; + }; +}; + +ASL_Can_Deploy_Ropes = { + params ["_vehicle"]; + private ["_existingRopes","_activeRopes"]; + if(player distance _vehicle > 10) exitWith { false }; + if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; + _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; + if(count _existingVehicle > 0) exitWith { false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if((count _existingRopes) == 0) exitWith { true }; + _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { false }; + true; +}; + +ASL_Get_Corner_Points = { + params ["_vehicle"]; + private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; + private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor","_maxHeight","_heightOffset"]; + + // Correct width and length factor for air + _widthFactor = 0.5; + _lengthFactor = 0.5; + if(_vehicle isKindOf "Air") then { + _widthFactor = 0.3; + }; + if(_vehicle isKindOf "Helicopter") then { + _widthFactor = 0.2; + _lengthFactor = 0.45; + }; + + _centerOfMass = getCenterOfMass _vehicle; + _bbr = boundingBoxReal _vehicle; + _p1 = _bbr select 0; + _p2 = _bbr select 1; + _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; + _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; + _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + _heightOffset = _maxHeight/6; + + _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + + [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; +}; + + +ASL_Attach_Ropes = { + params ["_cargo","_player"]; + _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + _vehicle = _vehicleWithIndex select 0; + if(!isNull _vehicle) then { + if(local _vehicle) then { + private ["_ropes","_attachmentPoints","_objDistance","_ropeLength","_allCargo"]; + _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; + if(count _ropes == 4) then { + _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + _ropeLength = (ropeLength (_ropes select 0)); + _objDistance = (_cargo distance _vehicle) + 2; + if( _objDistance > _ropeLength ) then { + [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; + } else { + [_vehicle,_player] call ASL_Drop_Ropes; + [_cargo, _attachmentPoints select 0, [0,0,-1]] ropeAttachTo (_ropes select 0); + [_cargo, _attachmentPoints select 1, [0,0,-1]] ropeAttachTo (_ropes select 1); + [_cargo, _attachmentPoints select 2, [0,0,-1]] ropeAttachTo (_ropes select 2); + [_cargo, _attachmentPoints select 3, [0,0,-1]] ropeAttachTo (_ropes select 3); + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [(_vehicleWithIndex select 1),_cargo]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { + [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + }; + }; + }; + } else { + [_this,"ASL_Attach_Ropes",_vehicle,true] call ASL_RemoteExec; + }; + }; +}; + +ASL_Attach_Ropes_Action = { + private ["_vehicle","_cargo","_canBeAttached"]; + _cargo = cursorTarget; + _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; + if([_vehicle,_cargo] call ASL_Can_Attach_Ropes) then { + + _canBeAttached = true; + + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked _cargo > 1 ) then { + ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; + _canBeAttached = false; + }; + }; + + if!(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { + if(!isNil "ExilePlayerInSafezone") then { + if( ExilePlayerInSafezone ) then { + ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; + _canBeAttached = false; + }; + }; + }; + + if(_canBeAttached) then { + [_cargo,player] call ASL_Attach_Ropes; + }; + + }; +}; + +ASL_Attach_Ropes_Action_Check = { + private ["_vehicleWithIndex","_cargo"]; + _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + _cargo = cursorTarget; + [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; +}; + +ASL_Can_Attach_Ropes = { + params ["_vehicle","_cargo"]; + if(!isNull _vehicle && !isNull _cargo) then { + [_vehicle,_cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; + } else { + false; + }; +}; + +ASL_Drop_Ropes = { + params ["_vehicle","_player",["_ropesIndex",0]]; + if(local _vehicle) then { + private ["_helper","_existingRopes"]; + _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + if(!isNull _helper) then { + _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + { + _helper ropeDetach _x; + } forEach _existingRopes; + detach _helper; + deleteVehicle _helper; + }; + _player setVariable ["ASL_Ropes_Vehicle", nil,true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; + } else { + [_this,"ASL_Drop_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Drop_Ropes_Action = { + private ["_vehicleAndIndex"]; + if([] call ASL_Can_Drop_Ropes) then { + _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; + if(count _vehicleAndIndex == 2) then { + [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + }; + }; +}; + +ASL_Drop_Ropes_Action_Check = { + [] call ASL_Can_Drop_Ropes; +}; + +ASL_Can_Drop_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; +}; + +ASL_Get_Closest_Rope = { + private ["_nearbyVehicles","_closestVehicle","_closestRopeIndex","_closestDistance"]; + private ["_vehicle","_activeRope","_ropes","_ends"]; + private ["_end1","_end2","_minEndDistance"]; + _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; + _closestVehicle = objNull; + _closestRopeIndex = 0; + _closestDistance = -1; + { + _vehicle = _x; + { + _activeRope = _x; + _ropes = [_vehicle,(_activeRope select 0)] call ASL_Get_Ropes; + { + _ends = ropeEndPosition _x; + if(count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); + if(_closestDistance == -1 || _closestDistance > _minEndDistance) then { + _closestDistance = _minEndDistance; + _closestRopeIndex = (_activeRope select 0); + _closestVehicle = _vehicle; + }; + }; + } forEach _ropes; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearbyVehicles; + [_closestVehicle,_closestRopeIndex]; +}; + +ASL_Pickup_Ropes = { + params ["_vehicle","_player",["_ropesIndex",0]]; + if(local _vehicle) then { + private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_helper","_allCargo"]; + _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; + _existingRopes = _existingRopesAndCargo select 0; + _existingCargo = _existingRopesAndCargo select 1; + if(!isNull _existingCargo) then { + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; + _allCargo set [_ropesIndex,objNull]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + }; + _helper = "Land_Can_V2_F" createVehicle position _player; + { + [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; + _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; + } forEach _existingRopes; + hideObject _helper; + [[_helper],"ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + _player setVariable ["ASL_Ropes_Vehicle", [_vehicle,_ropesIndex],true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper,true]; + } else { + [_this,"ASL_Pickup_Ropes",_vehicle,true] call ASL_RemoteExec; + }; +}; + +ASL_Pickup_Ropes_Action = { + private ["_nearbyVehicles","_canPickupRopes","_closestRope"]; + _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; + if([] call ASL_Can_Pickup_Ropes) then { + _closestRope = [] call ASL_Get_Closest_Rope; + if(!isNull (_closestRope select 0)) then { + _canPickupRopes = true; + if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { + if( locked (_closestRope select 0) > 1 ) then { + ["Cannot pick up cargo ropes from locked vehicle",false] call ASL_Hint; + _canPickupRopes = false; + }; + }; + if(_canPickupRopes) then { + [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; + }; + }; + }; +}; + +ASL_Pickup_Ropes_Action_Check = { + [] call ASL_Can_Pickup_Ropes; +}; + +ASL_Can_Pickup_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; +}; + +ASL_SUPPORTED_VEHICLES = [ + "Helicopter", + "VTOL_Base_F" +]; + +ASL_Is_Supported_Vehicle = { + params ["_vehicle","_isSupported"]; + _isSupported = false; + if(not isNull _vehicle) then { + { + if(_vehicle isKindOf _x) then { + _isSupported = true; + }; + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); + }; + _isSupported; +}; + +ASL_SLING_RULES = [ + ["All","CAN_SLING","All"] +]; + +ASL_Is_Supported_Cargo = { + params ["_vehicle","_cargo"]; + private ["_canSling"]; + _canSling = false; + if(not isNull _vehicle && not isNull _cargo) then { + { + if(_vehicle isKindOf (_x select 0)) then { + if(_cargo isKindOf (_x select 2)) then { + if( (toUpper (_x select 1)) == "CAN_SLING" ) then { + _canSling = true; + } else { + _canSling = false; + }; + }; + }; + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); + }; + _canSling; +}; + +ASL_Hint = { + params ["_msg",["_isSuccess",true]]; + if(!isNil "ExileClient_gui_notification_event_addNotification") then { + if(_isSuccess) then { + ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + } else { + ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + }; + } else { + hint _msg; + }; +}; + +ASL_Hide_Object_Global = { + params ["_obj"]; + if( _obj isKindOf "Land_Can_V2_F" ) then { + hideObjectGlobal _obj; + }; +}; + +ASL_Find_Nearby_Vehicles = { + private ["_nearVehicles","_nearVehiclesWithRopes","_vehicle","_ends","_end1","_end2","_playerPosAGL"]; + _nearVehicles = []; + { + _nearVehicles append (player nearObjects [_x, 30]); + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); + _nearVehiclesWithRopes = []; + { + _vehicle = _x; + { + _ropes = _vehicle getVariable ["ASL_Ropes",[]]; + if(count _ropes > (_x select 0)) then { + _ropes = _ropes select (_x select 0); + { + _ends = ropeEndPosition _x; + if(count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + _playerPosAGL = ASLtoAGL getPosASL player; + if((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { + _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; + } + }; + } forEach _ropes; + }; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearVehicles; + _nearVehiclesWithRopes; +}; + +ASL_Add_Player_Actions = { + + player addAction ["Extend Cargo Ropes", { + [] call ASL_Extend_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; + + player addAction ["Shorten Cargo Ropes", { + [] call ASL_Shorten_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; + + player addAction ["Release Cargo", { + [] call ASL_Release_Cargo_Action; + }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; + + player addAction ["Retract Cargo Ropes", { + [] call ASL_Retract_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; + + player addAction ["Deploy Cargo Ropes", { + [] call ASL_Deploy_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; + + player addAction ["Attach To Cargo Ropes", { + [] call ASL_Attach_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; + + player addAction ["Drop Cargo Ropes", { + [] call ASL_Drop_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; + + player addAction ["Pickup Cargo Ropes", { + [] call ASL_Pickup_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player setVariable ["ASL_Actions_Loaded",false]; + }]; + +}; + +if(!isDedicated) then { + [] spawn { + while {true} do { + if(!isNull player && isPlayer player) then { + if!( player getVariable ["ASL_Actions_Loaded",false] ) then { + [] call ASL_Add_Player_Actions; + player setVariable ["ASL_Actions_Loaded",true]; + }; + }; + missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; + sleep 2; + }; + }; +}; + +ASL_RemoteExec = { + params ["_params","_functionName","_target",["_isCall",false]]; + if(!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; + } else { + if(_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; + }; +}; + +ASL_RemoteExecServer = { + params ["_params","_functionName",["_isCall",false]]; + if(!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; + } else { + if(_isCall) then { + _params remoteExecCall [_functionName, 2]; + } else { + _params remoteExec [_functionName, 2]; + }; + }; +}; + +if(isServer) then { + + // Adds support for exile network calls (Only used when running exile) // + + ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { + params ["_sessionId", "_messageParameters",["_isCall",false]]; + _messageParameters params ["_params","_functionName"]; + if(_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { + if(_isCall) then { + _params call (missionNamespace getVariable [_functionName,{}]); + } else { + _params spawn (missionNamespace getVariable [_functionName,{}]); + }; + }; + }; + + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { + params ["_sessionId", "_messageParameters"]; + _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; + if(_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { + if(_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; + }; + }; + + // Install Advanced Sling Loading on all clients (plus JIP) // + + publicVariable "ASL_Advanced_Sling_Loading_Install"; + remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; + +}; + +// Disable Old Script Version on SA Server +SA_Rope_Action_Check = {false}; +SA_Rope_Pickup_Rope_Action_Check = {false}; +SA_Rope_Drop_Rope_Action_Check = {false}; +SA_Rope_Attach_Rope_Action_Check = {false}; + +diag_log "Advanced Sling Loading Loaded"; + +}; + +if(isServer) then { + [] call ASL_Advanced_Sling_Loading_Install; +}; diff --git a/meta.cpp b/meta.cpp new file mode 100644 index 0000000..da14732 --- /dev/null +++ b/meta.cpp @@ -0,0 +1,4 @@ +protocol = 1; +publishedid = 615007497; +name = "Advanced Sling Loading"; +timestamp = 5247774176389108621; diff --git a/mod.cpp b/mod.cpp index 211cc21..b1bdb0f 100644 --- a/mod.cpp +++ b/mod.cpp @@ -3,7 +3,7 @@ picture = "logo.paa"; description = "Advanced Sling Loading"; logo = "logo.paa"; logoOver = "logo.paa"; -tooltip = "Advanced Sling Loading"; +tooltip = "Advanced Sling Loading v2.1.1b"; tooltipOwned = "Advanced Sling Loading Owned"; overview = "Advanced Sling Loading"; author = "[SA] Duda"; From abc4bb17f8408549ef883a010bd8b2492b5c6f06 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Tue, 9 Mar 2021 23:13:37 +0100 Subject: [PATCH 06/24] Begin implementation drone release action --- functions/fn_advancedSlingLoadingInit.sqf | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/functions/fn_advancedSlingLoadingInit.sqf b/functions/fn_advancedSlingLoadingInit.sqf index 478de4f..730b817 100644 --- a/functions/fn_advancedSlingLoadingInit.sqf +++ b/functions/fn_advancedSlingLoadingInit.sqf @@ -436,9 +436,17 @@ ASL_Release_Cargo_Index_Action = { }; }; +// ASL_Release_Cargo_Action_Check = { + // if (vehicle player == player) exitWith {false}; + // [vehicle player] call ASL_Can_Release_Cargo; +// }; + ASL_Release_Cargo_Action_Check = { - if (vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Release_Cargo; + params ["_parThis", "_parTarget"]; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _parThis: ", _parThis, " _parTarget: ", _parTarget]; + // if (vehicle player == player) exitWith {false}; + // [vehicle player] call ASL_Can_Release_Cargo; + false }; ASL_Can_Release_Cargo = { @@ -1041,10 +1049,14 @@ ASL_Add_Player_Actions = { [] call ASL_Shorten_Ropes_Action; }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; + // player addAction ["Release Cargo", { + // [] call ASL_Release_Cargo_Action; + // }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; + player addAction ["Release Cargo", { [] call ASL_Release_Cargo_Action; - }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; - + }, nil, 0, false, true, "", "[_target, _this] call ASL_Release_Cargo_Action_Check"]; + player addAction ["Retract Cargo Ropes", { [] call ASL_Retract_Ropes_Action; }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; From 150b141c75684ef96d19b38d39c0fd87c8b80034 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 19 Mar 2021 16:08:22 +0100 Subject: [PATCH 07/24] Moved all actions to vehicles instead of player actions - instead of player addActions, most actions are now vehicle based - code optimisation - added multilingual support - added CBA options --- $PREFIX$ | 1 - addons/NIC_AdvancedSlingLoading/config.cpp | 65 +- .../functions/fn_advancedSlingLoadingInit.sqf | 2168 +++++++++-------- .../scripts/XEH_preInit.sqf | 53 + .../NIC_AdvancedSlingLoading/stringtable.xml | 57 + config.bin | Bin 664 -> 0 bytes functions/fn_advancedSlingLoadingInit.sqf | 1178 --------- keys/AdvancedSlingLoading.bikey | Bin 173 -> 0 bytes mod.cpp | 24 +- 9 files changed, 1294 insertions(+), 2252 deletions(-) delete mode 100644 $PREFIX$ create mode 100644 addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf create mode 100644 addons/NIC_AdvancedSlingLoading/stringtable.xml delete mode 100644 config.bin delete mode 100644 functions/fn_advancedSlingLoadingInit.sqf delete mode 100644 keys/AdvancedSlingLoading.bikey diff --git a/$PREFIX$ b/$PREFIX$ deleted file mode 100644 index a04b576..0000000 --- a/$PREFIX$ +++ /dev/null @@ -1 +0,0 @@ -SA_AdvancedSlingLoading \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp index 6992887..b69682b 100644 --- a/addons/NIC_AdvancedSlingLoading/config.cpp +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -1,58 +1,53 @@ -class CfgPatches -{ - class SA_AdvancedSlingLoading - { - units[]= - { +class CfgPatches { + class SA_AdvancedSlingLoading { + units[] = { "SA_AdvancedSlingLoading" }; - requiredVersion=1; - requiredAddons[]= - { + requiredVersion = 1; + requiredAddons[] = { "A3_Modules_F" }; }; }; -class CfgNetworkMessages -{ - class AdvancedSlingLoadingRemoteExecClient - { - module="AdvancedSlingLoading"; - parameters[]= - { +class CfgNetworkMessages { + class AdvancedSlingLoadingRemoteExecClient { + module = "AdvancedSlingLoading"; + parameters[] = { "ARRAY", "STRING", "OBJECT", "BOOL" }; }; - class AdvancedSlingLoadingRemoteExecServer - { - module="AdvancedSlingLoading"; - parameters[]= - { + class AdvancedSlingLoadingRemoteExecServer { + module = "AdvancedSlingLoading"; + parameters[] = { "ARRAY", "STRING", "BOOL" }; }; }; -class CfgFunctions -{ - class SA - { - class AdvancedSlingLoading - { - file="\SA_AdvancedSlingLoading\functions"; - class advancedSlingLoadingInit - { - postInit=1; +class CfgFunctions { + class SA { + class AdvancedSlingLoading { + file = "\SA_AdvancedSlingLoading\functions"; + // class ASLaddActions { + // preInit = 1; + // }; + class advancedSlingLoadingInit { + // postInit = 1; + preInit = 1; }; }; }; }; -class cfgMods -{ - author="76561198131707990"; - timepacked="1473204282"; +class Extended_PreInit_EventHandlers { + class SA { + init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration + }; +}; +class cfgMods { + author = "76561198131707990"; + timepacked = "1473204282"; }; diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index eb165da..22a42e3 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -11,337 +11,411 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ ASL_Advanced_Sling_Loading_Install = { - -// Prevent advanced sling loading from installing twice -if(!isNil "ASL_ROPE_INIT") exitWith {}; -ASL_ROPE_INIT = true; - -diag_log "Advanced Sling Loading Loading..."; - -ASL_Rope_Get_Lift_Capability = { - params ["_vehicle"]; - private ["_slingLoadMaxCargoMass"]; - _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); - if(_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = 4000; - }; - _slingLoadMaxCargoMass; -}; - -ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ - ["All", [-0.05, -0.05, -0.05]], - ["CUP_CH47F_base", [-0.05, -2, -0.05]], - ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], - ["RHS_CH_47F", [-0.75, -2.6, -0.75]], - ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], - ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] -]; - -ASL_Get_Sling_Load_Points = { - params ["_vehicle"]; - private ["_slingLoadPointsArray","_cornerPoints","_rearCenterPoint","_vehicleUnitVectorUp"]; - private ["_slingLoadPoints","_modelPoint","_modelPointASL","_surfaceIntersectStartASL","_surfaceIntersectEndASL","_surfaces","_intersectionASL","_intersectionObject"]; - _slingLoadPointsArray = []; - _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); - _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; - _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; - _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; - _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - - _slingLoadPointHeightOffset = 0; - { - if(_vehicle isKindOf (_x select 0)) then { - _slingLoadPointHeightOffset = (_x select 1); - }; - } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - - _slingLoadPoints = []; - { - _modelPoint = _x; - _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); - _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); - _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); + + // Prevent advanced sling loading from installing twice + if (!isNil "ASL_ROPE_INIT") exitWith {}; + ASL_ROPE_INIT = true; + + diag_log "Advanced Sling Loading Loading..."; + + ASL_Rope_Get_Lift_Capability = { + params ["_vehicle"]; + private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + if (_slingLoadMaxCargoMass <= 0) then { + _slingLoadMaxCargoMass = 4000; + }; + _slingLoadMaxCargoMass; + }; + + ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ + ["All", [-0.05, -0.05, -0.05]], + ["CUP_CH47F_base", [-0.05, -2, -0.05]], + ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], + ["RHS_CH_47F", [-0.75, -2.6, -0.75]], + ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], + ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] + ]; + + ASL_Get_Sling_Load_Points = { + params ["_vehicle"]; + private _slingLoadPointsArray = []; + private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; + private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); + private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; + _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; + private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; + private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - // Determine if the surface intersection line crosses below ground level - // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces - // doesn't work if starting below ground level for some reason - // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection + private _slingLoadPointHeightOffset = 0; + { + if (_vehicle isKindOf (_x select 0)) then { + _slingLoadPointHeightOffset = (_x select 1); + }; + } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - _la = ASLToAGL _surfaceIntersectStartASL; - _lb = ASLToAGL _surfaceIntersectEndASL; + private _slingLoadPoints = []; + private ["_modelPoint", + "_modelPointASL", + "_surfaceIntersectStartASL", + "_surfaceIntersectEndASL", + "_la", + "_lb", + "_n", + "_p0", + "_l", + "_d", + "_surfaces", + "_intersectionASL", + "_intersectionObject" + ]; + { + _modelPoint = _x; + _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); + _surfaceIntersectStartASL = _modelPointASL vectorAdd (_vehicleUnitVectorUp vectorMultiply -5); + _surfaceIntersectEndASL = _modelPointASL vectorAdd (_vehicleUnitVectorUp vectorMultiply 5); + + // Determine if the surface intersection line crosses below ground level + // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces + // doesn't work if starting below ground level for some reason + // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection + + _la = ASLToAGL _surfaceIntersectStartASL; + _lb = ASLToAGL _surfaceIntersectEndASL; + + if (_la select 2 < 0 && _lb select 2 > 0) then { + _n = [0, 0, 1]; + _p0 = [0, 0, 0.1]; + _l = (_la vectorFromTo _lb); + if ((_l vectorDotProduct _n) != 0) then { + _d = ((_p0 vectorAdd (_la vectorMultiply -1)) vectorDotProduct _n) / (_l vectorDotProduct _n); + _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + }; + }; + + _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; + _intersectionASL = []; + { + _intersectionObject = _x select 2; + if (_intersectionObject == _vehicle) exitWith { + _intersectionASL = _x select 0; + }; + } forEach _surfaces; + if (count _intersectionASL > 0) then { + _intersectionASL = _intersectionASL vectorAdd ((_surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); + _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); + } else { + _slingLoadPoints pushBack []; + }; + } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - if(_la select 2 < 0 && _lb select 2 > 0) then { - _n = [0,0,1]; - _p0 = [0,0,0.1]; - _l = (_la vectorFromTo _lb); - if((_l vectorDotProduct _n) != 0) then { - _d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n); - _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); + if (count (_slingLoadPoints select 1) > 0) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; + if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 2]; + if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 1, _slingLoadPoints select 2]; + }; + }; }; }; - - _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; - _intersectionASL = []; + _slingLoadPointsArray; + }; + + ASL_Rope_Set_Mass = { + private _obj = [_this, 0] call BIS_fnc_param; + private _mass = [_this, 1] call BIS_fnc_param; + _obj setMass _mass; + }; + + ASL_Rope_Adjust_Mass = { + params ["_obj", "_heli", ["_ropes", []]]; + private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + private _maxLiftableMass = _lift * 8; + private _originalMass = getMass _obj; + private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; + if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + private _originalMassSet = (getMass _obj) == _originalMass; + private ["_ends", "_endDistance", "_ropeLength"]; + while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { + { + _ends = ropeEndPosition _x; + _endDistance = (_ends select 0) distance (_ends select 1); + _ropeLength = ropeLength _x; + if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0) then { + [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + _originalMassSet = false; + }; + } forEach _ropes; + sleep 0.1; + }; + while {_obj in (ropeAttachedObjects _heli)} do { + sleep 0.5; + }; + [[_obj, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + }; + }; + + /* + Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle + */ + ASL_Get_Active_Ropes = { + params ["_vehicle"]; + private _activeRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + private ["_ropeLabels"]; { - _intersectionObject = _x select 2; - if(_intersectionObject == _vehicle) exitWith { - _intersectionASL = _x select 0; + if (count _x > 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; }; - } forEach _surfaces; - if(count _intersectionASL > 0) then { - _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); - _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); - } else { - _slingLoadPoints pushBack []; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _activeRopes; + }; + + /* + Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) + for a specified vehicle + */ + ASL_Get_Inactive_Ropes = { + params ["_vehicle"]; + private _inactiveRopes = []; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeIndex = 0; + private _totalExistingRopes = count _existingRopes; + private ["_ropeLabels"]; + { + if (count _x == 0) then { + _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); + _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + }; + _ropeIndex = _ropeIndex + 1; + } forEach _existingRopes; + _inactiveRopes; + }; + + ASL_Get_Active_Ropes_With_Cargo = { + params ["_vehicle"]; + private _activeRopesWithCargo = []; + private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; + private _activeRopes = _this call ASL_Get_Active_Ropes; + private ["_cargo"]; + { + _cargo = _existingCargo select (_x select 0); + if (!isNull _cargo) then { + _activeRopesWithCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithCargo; + }; + + ASL_Get_Active_Ropes_Without_Cargo = { + params ["_vehicle"]; + private _activeRopesWithoutCargo = []; + private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; + private _activeRopes = _this call ASL_Get_Active_Ropes; + private ["_cargo"]; + { + _cargo = _existingCargo select (_x select 0); + if (isNull _cargo) then { + _activeRopesWithoutCargo pushBack _x; + }; + } forEach _activeRopes; + _activeRopesWithoutCargo; + }; + + ASL_Get_Ropes = { + params ["_vehicle", "_ropeIndex"]; + private _selectedRopes = []; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _allRopes > _ropeIndex) then { + _selectedRopes = _allRopes select _ropeIndex; }; - } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; + _selectedRopes; + }; - if(count (_slingLoadPoints select 1) > 0) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if(count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0 ) then { - if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3 ) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; - if( ((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3 ) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 1,_slingLoadPoints select 2]; - }; - }; + ASL_Get_Ropes_Count = { + params ["_vehicle"]; + count (_vehicle getVariable ["ASL_Ropes", []]); + }; + + ASL_Get_Cargo = { + params ["_vehicle", "_ropeIndex"]; + private _selectedCargo = objNull; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + if (count _allCargo > _ropeIndex) then { + _selectedCargo = _allCargo select _ropeIndex; + }; + _selectedCargo; + }; + + ASL_Get_Ropes_And_Cargo = { + params ["_vehicle", "_ropeIndex"]; + private _selectedCargo = (_this call ASL_Get_Cargo); + private _selectedRopes = (_this call ASL_Get_Ropes); + [_selectedRopes, _selectedCargo]; + }; + + ASL_Show_Select_Ropes_Menu = { + params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", "Ropes"]]; + ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; + { + ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + } forEach _ropesIndexAndLabelArray; + ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; + }; + + ASL_Extend_Ropes_Index_Action = { + params ["_ropeIndex"]; + private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; }; }; - _slingLoadPointsArray; -}; - -ASL_Rope_Set_Mass = { - private ["_obj","_mass"]; - _obj = [_this,0] call BIS_fnc_param; - _mass = [_this,1] call BIS_fnc_param; - _obj setMass _mass; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Set_Mass) _obj: ", _obj, " _mass: ", _mass]; -}; -ASL_Rope_Adjust_Mass = { - params ["_obj","_heli",["_ropes",[]]]; - private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - private _maxLiftableMass = _lift * 8; - private _originalMass = getMass _obj; - private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE",5000]; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; - if( _originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { - private _originalMassSet = (getMass _obj) == _originalMass; - while { _obj in (ropeAttachedObjects _heli) && _originalMassSet } do { - { - private _ends = ropeEndPosition _x; - private _endDistance = (_ends select 0) distance (_ends select 1); - private _ropeLength = ropeLength _x; - if((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0 ) then { - [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - _originalMassSet = false; - }; - } forEach _ropes; - sleep 0.1; + ASL_Extend_Ropes_Action_Check = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; + [getConnectedUAV _unit] call ASL_Can_Extend_Ropes }; - while { _obj in (ropeAttachedObjects _heli) } do { - sleep 0.5; + if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; + [_vehicle] call ASL_Can_Extend_Ropes }; - [[_obj, _originalMass],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - }; -}; - -/* - Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Active_Ropes = { - params ["_vehicle"]; - private ["_activeRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; - _activeRopes = []; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; - _ropeIndex = 0; - _totalExistingRopes = count _existingRopes; - { - if(count _x > 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _activeRopes; -}; - -/* - Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Inactive_Ropes = { - params ["_vehicle"]; - private ["_inactiveRopes","_existingRopes","_ropeLabelSets","_ropeIndex","_totalExistingRopes","_ropeLabels"]; - _inactiveRopes = []; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _ropeLabelSets = [["Center"],["Front","Rear"],["Front","Center","Rear"]]; - _ropeIndex = 0; - _totalExistingRopes = count _existingRopes; - { - if(count _x == 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _inactiveRopes pushBack [_ropeIndex,_ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _inactiveRopes; -}; - -ASL_Get_Active_Ropes_With_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(!isNull _cargo) then { - _activeRopesWithCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithCargo; -}; - -ASL_Get_Active_Ropes_Without_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithoutCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithoutCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(isNull _cargo) then { - _activeRopesWithoutCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithoutCargo; -}; - -ASL_Get_Ropes = { - params ["_vehicle","_ropeIndex"]; - private ["_allRopes","_selectedRopes"]; - _selectedRopes = []; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _allRopes > _ropeIndex) then { - _selectedRopes = _allRopes select _ropeIndex; - }; - _selectedRopes; -}; - - -ASL_Get_Ropes_Count = { - params ["_vehicle"]; - count (_vehicle getVariable ["ASL_Ropes",[]]); -}; - -ASL_Get_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_allCargo","_selectedCargo"]; - _selectedCargo = objNull; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - if(count _allCargo > _ropeIndex) then { - _selectedCargo = _allCargo select _ropeIndex; - }; - _selectedCargo; -}; - -ASL_Get_Ropes_And_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_selectedCargo","_selectedRopes"]; - _selectedCargo = (_this call ASL_Get_Cargo); - _selectedRopes = (_this call ASL_Get_Ropes); - [_selectedRopes, _selectedCargo]; -}; - -ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName","_ropesIndexAndLabelArray",["_ropesLabel","Ropes"]]; - ASL_Show_Select_Ropes_Menu_Array = [[_title,false]]; - { - ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; - } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; -}; + false + }; -ASL_Extend_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 100 ) then { - { - ropeUnwind [_x, 3, 5, true]; - } forEach _existingRopes; + ASL_Is_Unit_Authorized = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Unit_Authorized) _vehicle: ", _vehicle, " _unit: ", _unit]; + // if (driver _vehicle == _unit || gunner _vehicle == _unit || commander _vehicle == _unit) exitWith {true}; + if (driver _vehicle == _unit && ASL_PilotsAuthorized || + gunner _vehicle == _unit && ASL_GunnersAuthorized || + commander _vehicle == _unit && ASL_CommandersAuthorized) exitWith {true}; + if !(ASL_CopilotsAuthorized) exitWith {false}; + private _cfg = configFile >> "CfgVehicles" >> typeOf(_vehicle); + private _trts = _cfg >> "turrets"; + private _isCopilot = false; + for "_i" from 0 to (count _trts - 1) do { + private _trt = _trts select _i; + if (getNumber(_trt >> "iscopilot") == 1) exitWith { + _isCopilot = ((_vehicle turretUnit [_i]) == _unit); // check, if unit is copilot }; }; - } else { - [_this,"ASL_Extend_Ropes",_vehicle,true] call ASL_RemoteExec; + _isCopilot }; -}; - -ASL_Extend_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Extend_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; + + ASL_Can_Extend_Ropes = { + params ["_vehicle"]; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 0) exitWith {false}; + true; + }; + + ASL_Extend_Ropes_Action = { + params [["_vehicle", objNull], "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle) exitWith {false}; + if !([_vehicle] call ASL_Can_Extend_Ropes) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 1) then { + [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; + }; + if (count _activeRopes > 1) then { + _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; + ["Extend Cargo Ropes", "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + }; + }; + + ASL_Extend_Ropes = { + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + if (local _vehicle) exitWith { + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= ASL_MaxRopeLength) then { + { + ropeUnwind [_x, 3, 5, true]; + } forEach _existingRopes; + }; }; }; + [_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec; }; -}; - -ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; + + ASL_Shorten_Ropes_Index_Action = { + params ["_ropeIndex"]; + private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; + }; + }; + + ASL_Shorten_Ropes_Action_Check = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; + [getConnectedUAV _unit] call ASL_Can_Shorten_Ropes + }; + if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; + [_vehicle] call ASL_Can_Shorten_Ropes + }; + false + }; + + ASL_Can_Shorten_Ropes = { + params ["_vehicle"]; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 0) exitWith {false}; + true }; -}; - -ASL_Extend_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Extend_Ropes; -}; -ASL_Can_Extend_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; + ASL_Shorten_Ropes_Action = { + params [["_vehicle", objNull], "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle) exitWith {false}; + if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 1) then { + [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + }; + if (count _activeRopes > 1) then { + _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; + ["Shorten Cargo Ropes", "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + }; + }; -ASL_Shorten_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 2 ) then { - _this call ASL_Release_Cargo; - } else { + ASL_Shorten_Ropes = { + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + if (local _vehicle) exitWith { + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= 2) exitWith { + _this call ASL_Release_Cargo; + }; { - if(_ropeLength >= 10) then { + if (_ropeLength >= 10) then { ropeUnwind [_x, 3, -5, true]; } else { ropeUnwind [_x, 3, -1, true]; @@ -349,824 +423,866 @@ ASL_Shorten_Ropes = { } forEach _existingRopes; }; }; - } else { - [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; + [_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec; }; -}; - -ASL_Shorten_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Shorten_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; - }; + + ASL_Release_Cargo_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; }; }; -}; - -ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; - }; -}; - -ASL_Shorten_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Shorten_Ropes; -}; - -ASL_Can_Shorten_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; -ASL_Release_Cargo = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropeIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - _this call ASL_Retract_Ropes; - } else { - [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; + ASL_Release_Cargo_Action_Check = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; + [getConnectedUAV _unit] call ASL_Can_Release_Cargo + }; + if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; + [_vehicle] call ASL_Can_Release_Cargo + }; + false }; -}; -ASL_Release_Cargo_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Release_Cargo) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; - }; + ASL_Can_Release_Cargo = { + params ["_vehicle"]; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 1"]; + false + }; + _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 2"]; + false }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if (count _activeRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 3"]; + false + }; + + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) _existingRopes: ", _existingRopes]; + true }; -}; - -ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; + + ASL_Release_Cargo_Action = { + params [["_vehicle", objNull], "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle) exitWith {false}; + if !([_vehicle] call ASL_Can_Release_Cargo) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + if (count _activeRopes == 1) then { + [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo; + // [_vehicle, (_activeRopes select 0) select 0] call ASL_Release_Cargo; + }; + if (count _activeRopes > 1) then { + _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; + ["Release Cargo", "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; + }; }; -}; - -ASL_Release_Cargo_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Release_Cargo; -}; - -ASL_Can_Release_Cargo = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Retract_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(isNull _existingCargo) then { - _this call ASL_Drop_Ropes; + + ASL_Release_Cargo = { + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + // params ["_vehicle", ["_ropeIndex", 0]]; + if (local _vehicle) exitWith { + private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; { - [_x,_vehicle] spawn { - params ["_rope","_vehicle"]; - private ["_count"]; - _count = 0; - ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; - }; - ropeDestroy _rope; - }; + _existingCargo ropeDetach _x; } forEach _existingRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropeIndex,[]]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropeIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + _this call ASL_Retract_Ropes; }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes",nil,true]; - }; - } else { - [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; + [_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec; }; -}; - -ASL_Retract_Ropes_Action = { - private ["_vehicle","_canRetractRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Retract_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; - }; + + ASL_Retract_Ropes_Action_Check = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) EXIT 1"]; + [getConnectedUAV _unit, _unit] call ASL_Can_Retract_Ropes + }; + if (vehicle _unit == _unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) EXIT 2"]; + [cursorTarget, _unit, true] call ASL_Can_Retract_Ropes + }; + if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) EXIT 3"]; + [_vehicle, _unit] call ASL_Can_Retract_Ropes }; + false }; -}; -ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Retract_Ropes; + ASL_Can_Retract_Ropes = { + params ["_vehicle", "_unit", ["_distanceCheck", false]]; + if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 1"]; + false + }; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 2"]; + false + }; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 3"]; + false + }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if (count _activeRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 5"]; + false + }; + true; }; -}; - -ASL_Retract_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Retract_Ropes; - } else { - [vehicle player] call ASL_Can_Retract_Ropes; + + ASL_Retract_Ropes_Action = { + params [["_vehicle", objNull], "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle) exitWith {false}; + if !([_vehicle] call ASL_Can_Retract_Ropes) exitWith {false}; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; + if (count _activeRopes == 1) then { + [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; + // [_vehicle, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; + }; + if (count _activeRopes > 1) then { + _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; + ["Retract Cargo Ropes", "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + }; }; -}; - -ASL_Can_Retract_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 30) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Deploy_Ropes = { - params ["_vehicle","_player",["_cargoCount",1],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_cargoRopes","_startLength","_slingLoadPoints"]; - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _existingRopes == 0) then { - if(count _slingLoadPoints == 0) exitWith { - [["Vehicle doesn't support cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - if(count _slingLoadPoints < _cargoCount) exitWith { - [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - _cargoRopes = []; - _cargo = []; - for "_i" from 0 to (_cargoCount-1) do - { - _cargoRopes pushBack []; - _cargo pushBack objNull; + + ASL_Retract_Ropes = { + params ["_vehicle", "_player", ["_ropeIndex", 0]]; + // params ["_vehicle", ["_ropeIndex", 0]]; + if (local _vehicle) exitWith { + private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + if (isNull _existingCargo) then { + _this call ASL_Drop_Ropes; + { + [_x] spawn { + params ["_rope"]; + private _count = 0; + ropeUnwind [_rope, 3, 0]; + while {(!ropeUnwound _rope) && _count < 20} do { + sleep 1; + _count = _count + 1; + }; + ropeDestroy _rope; + }; + } forEach _existingRopes; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropeIndex, []]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; }; - _vehicle setVariable ["ASL_Ropes",_cargoRopes,true]; - _vehicle setVariable ["ASL_Cargo",_cargo,true]; - for "_i" from 0 to (_cargoCount-1) do - { - [_vehicle,_player,_i] call ASL_Deploy_Ropes_Index; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes", nil, true]; }; - } else { - [["Vehicle already has cargo ropes deployed", false],"ASL_Hint",_player] call ASL_RemoteExec; }; - } else { - [_this,"ASL_Deploy_Ropes",_vehicle,true] call ASL_RemoteExec; + [_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec; }; -}; - -ASL_Deploy_Ropes_Index = { - params ["_vehicle","_player",["_ropesIndex",0],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_existingRopesCount","_allRopes"]; - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if(count _existingRopes == 0) then { - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - { - ropeUnwind [_x, 5, _ropeLength]; - } forEach _cargoRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropesIndex,_cargoRopes]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; + + ASL_Retract_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + [_vehicle, player, _ropesIndex] call ASL_Retract_Ropes; + // [_vehicle, _ropesIndex] call ASL_Retract_Ropes; }; - } else { - [_this,"ASL_Deploy_Ropes_Index",_vehicle,true] call ASL_RemoteExec; }; -}; - -ASL_Deploy_Ropes_Action = { - private ["_vehicle","_canDeployRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Deploy_Ropes) then { - _canDeployRopes = true; - - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _vehicle > 1 ) then { - ["Cannot deploy cargo ropes from locked vehicle",false] call ASL_Hint; - _canDeployRopes = false; - }; - }; - - if(_canDeployRopes) then { - - _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; - - if(count _inactiveRopes > 0) then { - - if(count _inactiveRopes > 1) then { - player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - ["Deploy Cargo Ropes","ASL_Deploy_Ropes_Index_Action",_inactiveRopes] call ASL_Show_Select_Ropes_Menu; - } else { - [_vehicle,player,(_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + ASL_Deploy_Ropes = { + params ["_vehicle", "_player", ["_cargoCount", 1]]; + if (local _vehicle) then { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + if (count _existingRopes == 0) then { + if (count _slingLoadPoints == 0) exitWith { + [["Vehicle doesn't support cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; }; - - } else { - - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if(count _slingLoadPoints > 1) then { - player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [ - ["Deploy Ropes",false] - ]; - ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if((count _slingLoadPoints) > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - if((count _slingLoadPoints) > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; - } else { - [_vehicle,player] call ASL_Deploy_Ropes; + if (count _slingLoadPoints < _cargoCount) exitWith { + [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; + }; + private _cargoRopes = []; + private _cargo = []; + for "_i" from 0 to (_cargoCount-1) do { + _cargoRopes pushBack []; + _cargo pushBack objNull; + }; + _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; + _vehicle setVariable ["ASL_Cargo", _cargo, true]; + for "_i" from 0 to (_cargoCount-1) do + { + [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; }; - + } else { + [["Vehicle already has cargo ropes deployed", false], "ASL_Hint", _player] call ASL_RemoteExec; }; - + } else { + [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; + }; + }; + + ASL_Deploy_Ropes_Index = { + params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; + if (local _vehicle) then { + private _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; + private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + if (count _existingRopes == 0) then { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + private _cargoRopes = []; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + { + ropeUnwind [_x, 5, _ropeLength]; + } forEach _cargoRopes; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropesIndex, _cargoRopes]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + }; + } else { + [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; }; + }; + ASL_Deploy_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + // if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; + }; }; -}; - -ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Deploy_Ropes_Index; + + ASL_Deploy_Ropes_Count_Action = { + params ["_count"]; + private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + // if (_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + if (_count > 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _count] call ASL_Deploy_Ropes; + }; }; -}; - -ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - if(_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_count] call ASL_Deploy_Ropes; + + ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit = { + params ["_UAV", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) _UAV: ", _UAV, " _unit: ", _unit]; + if (isNull _UAV) exitWith {false}; + if (UAVControl _UAV select 0 == _unit && (UAVControl _UAV select 1 == "GUNNER" || UAVControl _UAV select 1 == "DRIVER")) exitWith { + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) EXIT 1: unit is UAV gunner or driver"]; + true + }; + false }; -}; - -ASL_Deploy_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Deploy_Ropes; - } else { - [vehicle player] call ASL_Can_Deploy_Ropes; + + ASL_Deploy_Ropes_Action_Check = { + params ["_vehicle", "_unit"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) EXIT 1"]; + [getConnectedUAV _unit, _unit] call ASL_Can_Deploy_Ropes + }; + if (vehicle _unit == _unit) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) EXIT 2"]; + [cursorTarget, _unit, true] call ASL_Can_Deploy_Ropes + }; + if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) EXIT 3"]; + [_vehicle, _unit] call ASL_Can_Deploy_Ropes + }; + false }; -}; - -ASL_Can_Deploy_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _existingVehicle > 0) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { true }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { false }; - true; -}; - -ASL_Get_Corner_Points = { - params ["_vehicle"]; - private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; - private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor","_maxHeight","_heightOffset"]; - - // Correct width and length factor for air - _widthFactor = 0.5; - _lengthFactor = 0.5; - if(_vehicle isKindOf "Air") then { - _widthFactor = 0.3; - }; - if(_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; - }; - - _centerOfMass = getCenterOfMass _vehicle; - _bbr = boundingBoxReal _vehicle; - _p1 = _bbr select 0; - _p2 = _bbr select 1; - _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; - _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; - _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - _heightOffset = _maxHeight/6; - - _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - - [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; -}; - - -ASL_Attach_Ropes = { - params ["_cargo","_player"]; - _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _vehicle = _vehicleWithIndex select 0; - if(!isNull _vehicle) then { - if(local _vehicle) then { - private ["_ropes","_attachmentPoints","_objDistance","_ropeLength","_allCargo"]; - _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; - if(count _ropes == 4) then { - _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - _ropeLength = (ropeLength (_ropes select 0)); - _objDistance = (_cargo distance _vehicle) + 2; - if( _objDistance > _ropeLength ) then { - [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; - } else { - [_vehicle,_player] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0,0,-1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0,0,-1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0,0,-1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0,0,-1]] ropeAttachTo (_ropes select 3); - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [(_vehicleWithIndex select 1),_cargo]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - }; - }; - }; - } else { - [_this,"ASL_Attach_Ropes",_vehicle,true] call ASL_RemoteExec; + + ASL_Can_Deploy_Ropes = { + params ["_vehicle", "_unit", ["_distanceCheck", false]]; + _unit setVariable ["ASL_TargetDeployVehicle", nil]; + // if (_distanceCheck && player distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { + if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 1"]; + false }; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 2"]; + false + }; + // private _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; + private _existingVehicle = _unit getVariable ["ASL_Ropes_Vehicle", []]; + if (count _existingVehicle > 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 3"]; + false + }; + _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 4"]; + _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; + true + }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _existingRopes > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 5"]; + false + }; + _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; + true }; -}; - -ASL_Attach_Ropes_Action = { - private ["_vehicle","_cargo","_canBeAttached"]; - _cargo = cursorTarget; - _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; - if([_vehicle,_cargo] call ASL_Can_Attach_Ropes) then { + + ASL_Deploy_Ropes_Action = { + params [["_vehicle", objNull]]; - _canBeAttached = true; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; + if (isNull _vehicle) exitWith {false}; - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _cargo > 1 ) then { - ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; - _canBeAttached = false; + private _canDeployRopes = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + if (locked _vehicle > 1) then { + ["Cannot deploy cargo ropes from locked vehicle", false] call ASL_Hint; + _canDeployRopes = false; }; }; + if (!_canDeployRopes) exitWith {}; - if!(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { - if(!isNil "ExilePlayerInSafezone") then { - if( ExilePlayerInSafezone ) then { - ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; - _canBeAttached = false; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _canDeployRopes: ", _canDeployRopes]; + + private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + if (count _inactiveRopes > 0) then { + if (count _inactiveRopes > 1) then { + player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; + ["Deploy Cargo Ropes", "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; + } else { + [_vehicle, player, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + }; + } else { + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + if (count _slingLoadPoints > 1) then { + player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [ + ["Deploy Ropes", false] + ]; + ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if ((count _slingLoadPoints) > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if ((count _slingLoadPoints) > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; }; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; + } else { + [_vehicle, player] call ASL_Deploy_Ropes; }; }; + }; - if(_canBeAttached) then { - [_cargo,player] call ASL_Attach_Ropes; - }; + ASL_Get_Corner_Points = { + params ["_vehicle"]; - }; -}; - -ASL_Attach_Ropes_Action_Check = { - private ["_vehicleWithIndex","_cargo"]; - _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _cargo = cursorTarget; - [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; -}; - -ASL_Can_Attach_Ropes = { - params ["_vehicle","_cargo"]; - if(!isNull _vehicle && !isNull _cargo) then { - [_vehicle,_cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - } else { - false; - }; -}; - -ASL_Drop_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_helper","_existingRopes"]; - _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - if(!isNull _helper) then { - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - { - _helper ropeDetach _x; - } forEach _existingRopes; - detach _helper; - deleteVehicle _helper; + // Correct width and length factor for air + private _widthFactor = 0.5; + private _lengthFactor = 0.5; + if (_vehicle isKindOf "Air") then { + _widthFactor = 0.3; }; - _player setVariable ["ASL_Ropes_Vehicle", nil,true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; - } else { - [_this,"ASL_Drop_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Drop_Ropes_Action = { - private ["_vehicleAndIndex"]; - if([] call ASL_Can_Drop_Ropes) then { - _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + if (_vehicle isKindOf "Helicopter") then { + _widthFactor = 0.2; + _lengthFactor = 0.45; }; + + private _centerOfMass = getCenterOfMass _vehicle; + private _bbr = boundingBoxReal _vehicle; + private _p1 = _bbr select 0; + private _p2 = _bbr select 1; + private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; + private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; + private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _heightOffset = _maxHeight/6; + + private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + + [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; -}; - -ASL_Drop_Ropes_Action_Check = { - [] call ASL_Can_Drop_Ropes; -}; - -ASL_Can_Drop_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; -}; - -ASL_Get_Closest_Rope = { - private ["_nearbyVehicles","_closestVehicle","_closestRopeIndex","_closestDistance"]; - private ["_vehicle","_activeRope","_ropes","_ends"]; - private ["_end1","_end2","_minEndDistance"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - _closestVehicle = objNull; - _closestRopeIndex = 0; - _closestDistance = -1; - { - _vehicle = _x; - { - _activeRope = _x; - _ropes = [_vehicle,(_activeRope select 0)] call ASL_Get_Ropes; - { - _ends = ropeEndPosition _x; - if(count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); - if(_closestDistance == -1 || _closestDistance > _minEndDistance) then { - _closestDistance = _minEndDistance; - _closestRopeIndex = (_activeRope select 0); - _closestVehicle = _vehicle; + + ASL_Attach_Ropes = { + params ["_cargo", "_player"]; + private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; + private _vehicle = _vehicleWithIndex select 0; + if (!isNull _vehicle) then { + if (local _vehicle) then { + private _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; + if (count _ropes == 4) then { + private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + private _ropeLength = (ropeLength (_ropes select 0)); + private _objDistance = (_cargo distance _vehicle) + 2; + if (_objDistance > _ropeLength) then { + [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; + } else { + [_vehicle, _player] call ASL_Drop_Ropes; + [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); + [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); + [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); + [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [(_vehicleWithIndex select 1),_cargo]; + _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { + [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + }; }; }; - } forEach _ropes; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearbyVehicles; - [_closestVehicle,_closestRopeIndex]; -}; - -ASL_Pickup_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_helper","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(!isNull _existingCargo) then { - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropesIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - }; - _helper = "Land_Can_V2_F" createVehicle position _player; - { - [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; - _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - } forEach _existingRopes; - hideObject _helper; - [[_helper],"ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - _player setVariable ["ASL_Ropes_Vehicle", [_vehicle,_ropesIndex],true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper,true]; - } else { - [_this,"ASL_Pickup_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Pickup_Ropes_Action = { - private ["_nearbyVehicles","_canPickupRopes","_closestRope"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - if([] call ASL_Can_Pickup_Ropes) then { - _closestRope = [] call ASL_Get_Closest_Rope; - if(!isNull (_closestRope select 0)) then { - _canPickupRopes = true; - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked (_closestRope select 0) > 1 ) then { - ["Cannot pick up cargo ropes from locked vehicle",false] call ASL_Hint; - _canPickupRopes = false; - }; + } else { + [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; }; - if(_canPickupRopes) then { - [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - }; }; }; -}; - -ASL_Pickup_Ropes_Action_Check = { - [] call ASL_Can_Pickup_Ropes; -}; - -ASL_Can_Pickup_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; -}; - -ASL_SUPPORTED_VEHICLES = [ - "Helicopter", - "VTOL_Base_F" -]; - -ASL_Is_Supported_Vehicle = { - params ["_vehicle","_isSupported"]; - _isSupported = false; - if(not isNull _vehicle) then { - { - if(_vehicle isKindOf _x) then { - _isSupported = true; + + ASL_Attach_Ropes_Action = { + private _cargo = cursorTarget; + private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { + private _canBeAttached = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + if (locked _cargo > 1) then { + ["Cannot attach cargo ropes to locked vehicle", false] call ASL_Hint; + _canBeAttached = false; + }; }; - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); - }; - _isSupported; -}; - -ASL_SLING_RULES = [ - ["All","CAN_SLING","All"] -]; - -ASL_Is_Supported_Cargo = { - params ["_vehicle","_cargo"]; - private ["_canSling"]; - _canSling = false; - if(not isNull _vehicle && not isNull _cargo) then { - { - if(_vehicle isKindOf (_x select 0)) then { - if(_cargo isKindOf (_x select 2)) then { - if( (toUpper (_x select 1)) == "CAN_SLING" ) then { - _canSling = true; - } else { - _canSling = false; + if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { + if (!isNil "ExilePlayerInSafezone") then { + if (ExilePlayerInSafezone) then { + ["Cannot attach cargo ropes in safe zone", false] call ASL_Hint; + _canBeAttached = false; }; }; }; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); + if (_canBeAttached) then { + [_cargo, player] call ASL_Attach_Ropes; + }; + }; }; - _canSling; -}; - -ASL_Hint = { - params ["_msg",["_isSuccess",true]]; - if(!isNil "ExileClient_gui_notification_event_addNotification") then { - if(_isSuccess) then { - ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + + ASL_Attach_Ropes_Action_Check = { + private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + private _cargo = cursorTarget; + [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; + }; + + ASL_Can_Attach_Ropes = { + params ["_vehicle", "_cargo"]; + if (!isNull _vehicle && !isNull _cargo) then { + [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; } else { - ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + false; }; - } else { - hint _msg; - }; -}; - -ASL_Hide_Object_Global = { - params ["_obj"]; - if( _obj isKindOf "Land_Can_V2_F" ) then { - hideObjectGlobal _obj; }; -}; - -ASL_Find_Nearby_Vehicles = { - private ["_nearVehicles","_nearVehiclesWithRopes","_vehicle","_ends","_end1","_end2","_playerPosAGL"]; - _nearVehicles = []; - { - _nearVehicles append (player nearObjects [_x, 30]); - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); - _nearVehiclesWithRopes = []; - { - _vehicle = _x; + + ASL_Drop_Ropes = { + params ["_vehicle", "_player", ["_ropesIndex", 0]]; + if (local _vehicle) then { + private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + if (!isNull _helper) then { + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + { + _helper ropeDetach _x; + } forEach _existingRopes; + detach _helper; + deleteVehicle _helper; + }; + _player setVariable ["ASL_Ropes_Vehicle", nil,true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; + } else { + [_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec; + }; + }; + + ASL_Drop_Ropes_Action = { + if ([] call ASL_Can_Drop_Ropes) then { + private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; + if (count _vehicleAndIndex == 2) then { + [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + }; + }; + }; + + ASL_Drop_Ropes_Action_Check = { + [] call ASL_Can_Drop_Ropes; + }; + + ASL_Can_Drop_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; + }; + + ASL_Get_Closest_Rope = { + private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; + private _closestVehicle = objNull; + private _closestRopeIndex = 0; + private _closestDistance = -1; + private ["_vehicle", "_activeRope", "_ropes", "_ends", "_end1", "_end2", "_minEndDistance"]; { - _ropes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _ropes > (_x select 0)) then { - _ropes = _ropes select (_x select 0); + _vehicle = _x; + { + _activeRope = _x; + _ropes = [_vehicle, (_activeRope select 0)] call ASL_Get_Ropes; { _ends = ropeEndPosition _x; - if(count _ends == 2) then { + if (count _ends == 2) then { _end1 = _ends select 0; _end2 = _ends select 1; - _playerPosAGL = ASLtoAGL getPosASL player; - if((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { - _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - } + _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); + if (_closestDistance == -1 || _closestDistance > _minEndDistance) then { + _closestDistance = _minEndDistance; + _closestRopeIndex = (_activeRope select 0); + _closestVehicle = _vehicle; + }; }; } forEach _ropes; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearbyVehicles; + [_closestVehicle, _closestRopeIndex]; + }; + + ASL_Pickup_Ropes = { + params ["_vehicle", "_player", ["_ropesIndex", 0]]; + if (local _vehicle) then { + private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + if (!isNull _existingCargo) then { + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropesIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; }; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearVehicles; - _nearVehiclesWithRopes; -}; - -ASL_Add_Player_Actions = { - - player addAction ["Extend Cargo Ropes", { - [] call ASL_Extend_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; + private _helper = "Land_Can_V2_F" createVehicle position _player; + { + [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; + _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; + } forEach _existingRopes; + hideObject _helper; + [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; + } else { + [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; + }; + }; - player addAction ["Shorten Cargo Ropes", { - [] call ASL_Shorten_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; - - player addAction ["Release Cargo", { - [] call ASL_Release_Cargo_Action; - }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; - - player addAction ["Retract Cargo Ropes", { - [] call ASL_Retract_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; + ASL_Pickup_Ropes_Action = { + private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; + if ([] call ASL_Can_Pickup_Ropes) then { + private _closestRope = [] call ASL_Get_Closest_Rope; + if (!isNull (_closestRope select 0)) then { + private _canPickupRopes = true; + if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + if (locked (_closestRope select 0) > 1) then { + ["Cannot pick up cargo ropes from locked vehicle", false] call ASL_Hint; + _canPickupRopes = false; + }; + }; + if (_canPickupRopes) then { + [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; + }; + }; + }; + }; - player addAction ["Deploy Cargo Ropes", { - [] call ASL_Deploy_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; - - player addAction ["Attach To Cargo Ropes", { - [] call ASL_Attach_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - - player addAction ["Drop Cargo Ropes", { - [] call ASL_Drop_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - - player addAction ["Pickup Cargo Ropes", { - [] call ASL_Pickup_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - - player addEventHandler ["Respawn", { - player setVariable ["ASL_Actions_Loaded",false]; - }]; + ASL_Pickup_Ropes_Action_Check = { + [] call ASL_Can_Pickup_Ropes; + }; -}; - -if(!isDedicated) then { - [] spawn { - while {true} do { - if(!isNull player && isPlayer player) then { - if!( player getVariable ["ASL_Actions_Loaded",false] ) then { - [] call ASL_Add_Player_Actions; - player setVariable ["ASL_Actions_Loaded",true]; + ASL_Can_Pickup_Ropes = { + count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; + }; + + ASL_SUPPORTED_VEHICLES = [ + "Helicopter", + "VTOL_Base_F" + ]; + + ASL_Is_Supported_Vehicle = { + params ["_vehicle"]; + if (isNull _vehicle) exitWith {false}; + private _isSupported = false; + { + if (_vehicle isKindOf _x) exitWith {_isSupported = true}; + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); + _isSupported; + }; + + ASL_SLING_RULES = [ + ["All", "CAN_SLING", "All"] + ]; + + ASL_Is_Supported_Cargo = { + params ["_vehicle", "_cargo"]; + private _canSling = false; + if (not isNull _vehicle && not isNull _cargo) then { + { + if (_vehicle isKindOf (_x select 0)) then { + if (_cargo isKindOf (_x select 2)) then { + if ((toUpper (_x select 1)) == "CAN_SLING") then { + _canSling = true; + } else { + _canSling = false; + }; + }; }; - }; - missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - sleep 2; + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); }; + _canSling; }; -}; - -ASL_RemoteExec = { - params ["_params","_functionName","_target",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, _target]; + + ASL_Hint = { + params ["_msg", ["_isSuccess", true]]; + if (!isNil "ExileClient_gui_notification_event_addNotification") then { + if (_isSuccess) then { + ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + } else { + ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + }; } else { - _params remoteExec [_functionName, _target]; + hint _msg; }; }; -}; - -ASL_RemoteExecServer = { - params ["_params","_functionName",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, 2]; - } else { - _params remoteExec [_functionName, 2]; + + ASL_Hide_Object_Global = { + params ["_obj"]; + if (_obj isKindOf "Land_Can_V2_F") then { + hideObjectGlobal _obj; }; }; -}; - -if(isServer) then { - // Adds support for exile network calls (Only used when running exile) // + ASL_Find_Nearby_Vehicles = { + private _nearVehicles = []; + { + _nearVehicles append (player nearObjects [_x, 30]); + } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); + private _nearVehiclesWithRopes = []; + private ["_vehicle", "_ropes", "_ends", "_end1", "_end2", "_playerPosAGL"]; + { + _vehicle = _x; + { + _ropes = _vehicle getVariable ["ASL_Ropes",[]]; + if (count _ropes > (_x select 0)) then { + _ropes = _ropes select (_x select 0); + { + _ends = ropeEndPosition _x; + if (count _ends == 2) then { + _end1 = _ends select 0; + _end2 = _ends select 1; + _playerPosAGL = ASLtoAGL getPosASL player; + if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { + _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; + } + }; + } forEach _ropes; + }; + } forEach ([_vehicle] call ASL_Get_Active_Ropes); + } forEach _nearVehicles; + _nearVehiclesWithRopes; + }; - ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; + ASL_Add_Vehicle_Actions = { + params ["_vehicle"]; + private _exit = true; + { + if (_vehicle isKindOf _x) exitWith {_exit = false}; + } foreach ASL_SUPPORTED_VEHICLES; + if (_exit) exitWith {}; + + if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { + private _actionID = _vehicle addAction [ + "Deploy Cargo Ropes", // Title + {[_this select 0] call ASL_Deploy_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Deploy_Ropes_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_Deploy", _actionID]; + }; + + if (isNil{_vehicle getVariable "ASL_ActionID_Retract"}) then { + private _actionID = _vehicle addAction [ + "Retract Cargo Ropes", // Title + {[_this select 0, _this select 1] call ASL_Retract_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Retract_Ropes_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_Retract", _actionID]; + }; - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { - params ["_sessionId", "_messageParameters",["_isCall",false]]; - _messageParameters params ["_params","_functionName"]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { - if(_isCall) then { - _params call (missionNamespace getVariable [_functionName,{}]); - } else { - _params spawn (missionNamespace getVariable [_functionName,{}]); - }; + if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { + private _actionID = _vehicle addAction [ + "Extend Cargo Ropes", // Title + {[_this select 0, _this select 1] call ASL_Extend_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Extend_Ropes_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_Extend", _actionID]; + }; + + if (isNil{_vehicle getVariable "ASL_ActionID_Shorten"}) then { + private _actionID = _vehicle addAction [ + "Shorten Cargo Ropes", // Title + {[_this select 0, _this select 1] call ASL_Shorten_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Shorten_Ropes_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_Shorten", _actionID]; + }; + + if (isNil{_vehicle getVariable "ASL_ActionID_Release"}) then { + private _actionID = _vehicle addAction [ + "Release Cargo", // Title + {[_this select 0, _this select 1] call ASL_Release_Cargo_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Release_Cargo_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; }; - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; + ASL_Add_Player_Actions = { + player addAction ["Pickup Cargo Ropes", { + [] call ASL_Pickup_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; + + player addAction ["Drop Cargo Ropes", { + [] call ASL_Drop_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; + + player addAction ["Attach To Cargo Ropes", { + [] call ASL_Attach_Ropes_Action; + }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; + + player addEventHandler ["Respawn", { + player setVariable ["ASL_Actions_Loaded", false]; + }]; + }; + + if (!isDedicated) then { + ["Air", "init", {_this call ASL_Add_Vehicle_Actions}, true] call CBA_fnc_addClassEventHandler; // adds init event to all air vehicles; has to be run preinit! + [] spawn { + while {true} do { + if (!isNull player && isPlayer player) then { + if !(player getVariable ["ASL_Actions_Loaded", false]) then { + [] call ASL_Add_Player_Actions; + player setVariable ["ASL_Actions_Loaded", true]; + }; + }; + missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; + sleep 2; + }; + }; + }; - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { - params ["_sessionId", "_messageParameters"]; - _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { - if(_isCall) then { + ASL_RemoteExec = { + params ["_params", "_functionName", "_target", ["_isCall", false]]; + if (!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecClient", [_params, _functionName, _target, _isCall]] call ExileClient_system_network_send; + } else { + if (_isCall) then { _params remoteExecCall [_functionName, _target]; } else { _params remoteExec [_functionName, _target]; }; }; }; - - // Install Advanced Sling Loading on all clients (plus JIP) // - publicVariable "ASL_Advanced_Sling_Loading_Install"; - remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; + ASL_RemoteExecServer = { + params ["_params", "_functionName", ["_isCall", false]]; + if (!isNil "ExileClient_system_network_send") then { + ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; + } else { + if (_isCall) then { + _params remoteExecCall [_functionName, 2]; + } else { + _params remoteExec [_functionName, 2]; + }; + }; + }; -}; - -// Disable Old Script Version on SA Server -SA_Rope_Action_Check = {false}; -SA_Rope_Pickup_Rope_Action_Check = {false}; -SA_Rope_Drop_Rope_Action_Check = {false}; -SA_Rope_Attach_Rope_Action_Check = {false}; - -diag_log "Advanced Sling Loading Loaded"; + if (isServer) then { + + // Adds support for exile network calls (Only used when running exile) + ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { + params ["_sessionId", "_messageParameters", ["_isCall", false]]; + _messageParameters params ["_params", "_functionName"]; + if (_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { + if (_isCall) then { + _params call (missionNamespace getVariable [_functionName, {}]); + } else { + _params spawn (missionNamespace getVariable [_functionName, {}]); + }; + }; + }; + + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes", "ASL_Deploy_Ropes_Index", "ASL_Rope_Set_Mass", "ASL_Extend_Ropes", "ASL_Shorten_Ropes", "ASL_Release_Cargo", "ASL_Retract_Ropes", "ASL_Deploy_Ropes", "ASL_Hint", "ASL_Attach_Ropes", "ASL_Drop_Ropes"]; + + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { + params ["_sessionId", "_messageParameters"]; + _messageParameters params ["_params", "_functionName", "_target", ["_isCall", false]]; + if (_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { + if (_isCall) then { + _params remoteExecCall [_functionName, _target]; + } else { + _params remoteExec [_functionName, _target]; + }; + }; + }; + + // Install Advanced Sling Loading on all clients (plus JIP) + publicVariable "ASL_Advanced_Sling_Loading_Install"; + remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2, true]; + }; + diag_log "Advanced Sling Loading Loaded"; }; -if(isServer) then { +if (isServer) then { + if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // max rope length in meter + if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // max rope deploy, retract distance in meter (when player is on foot) + if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // Pilots authorized to manipulate ropes + if (isNil "ASL_CommandersAuthorized") then {ASL_CommandersAuthorized = true}; // Pilots authorized to manipulate ropes + if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // Copilots authorized to manipulate ropes + if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = true}; // Gunners authorized to manipulate ropes [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf new file mode 100644 index 0000000..4519ace --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -0,0 +1,53 @@ +[ + "ASL_MaxRopeLength", // internal setting name, should always contain a tag! This will be the global variable which takes the value of the setting. + "SLIDER", // setting type + [format[localize "STR_ASL_MAX_LENGTH"], format[localize "STR_ASL_MAX_LENGTH_TIP"]], // [setting name, tooltip] + format[localize "STR_ASL_TITLE"], // pretty name of the category where the setting can be found. Can be stringtable entry. + [30, 150, 100, 0], // data for this setting: [_min, _max, _default, _trailingDecimals] + true // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer +] call CBA_fnc_addSetting; + +[ + "ASL_MaxDeployRetractDistance", + "SLIDER", + [format[localize "STR_ASL_MAX_DIST"], format[localize "STR_ASL_MAX_DIST_TIP"]], + format[localize "STR_ASL_TITLE"], + [3, 30, 10, 0], + true +] call CBA_fnc_addSetting; + +[ + "ASL_PilotsAuthorized", + "CHECKBOX", + [format[localize "STR_ASL_PILOT"], format[localize "STR_ASL_PILOT_TIP"]], + format[localize "STR_ASL_TITLE"], + true, // default setting + true +] call CBA_fnc_addSetting; + +[ + "ASL_CommandersAuthorized", + "CHECKBOX", + [format[localize "STR_ASL_COMMANDER"], format[localize "STR_ASL_COMMANDER_TIP"]], + format[localize "STR_ASL_TITLE"], + true, + true +] call CBA_fnc_addSetting; + +[ + "ASL_CopilotsAuthorized", + "CHECKBOX", + [format[localize "STR_ASL_COPILOT"], format[localize "STR_ASL_COPILOT_TIP"]], + format[localize "STR_ASL_TITLE"], + true, + true +] call CBA_fnc_addSetting; + +[ + "ASL_GunnersAuthorized", + "CHECKBOX", + [format[localize "STR_ASL_GUNNER"], format[localize "STR_ASL_GUNNER_TIP"]], + format[localize "STR_ASL_TITLE"], + true, + true +] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml new file mode 100644 index 0000000..2664fa1 --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -0,0 +1,57 @@ + + + + + NIC Advanced Sling Loading + NIC Fortgeschrittene Schlinglast + + + Maximum Rope Lenth + Maximale Seillänge + + + Maximum rope lenth in meter from vehicle to load. + Maximale Seillänge in Meter vom Fahrzeug bis zur Ladung. + + + Maximal Deploy / Retract Range + Maximale Ausfahr- / Einfahrreichweite + + + When player is on foot, maximal range in meter from player to vehicle, up to whitch deploying / retracting ropes is possible. + Wenn Spieler zu Fuß ist, maximale Reichweite in Meter von Spieler zu Fahrzeug, bis zu welcher Seile Aus- oder Eingefahren werden können. + + + Pilots + Piloten + + + Pilots are authorized to manipulate vehicle ropes. + Piloten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + Commanders + Komandanten + + + Commanders are authorized to manipulate vehicle ropes. + Komandanten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + Copilots + Kopiloten + + + Copilots are authorized to manipulate vehicle ropes. + Kopiloten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + Gunners + Kanoniere + + + Gunner are authorized to manipulate vehicle ropes. + Kanoniere sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + \ No newline at end of file diff --git a/config.bin b/config.bin deleted file mode 100644 index 9f9de7a9f21cf01b7190d9ad857b0fc1ae3f34da..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 664 zcmb7?&rZTX5XPs)gO5W2sT>OdgW+FVVq(OQO?O%v+Ai*H(W3_+!Kd;GJoq3Uon4fJ zDJC}AHvM+``)0o>NVWjF&S|~6bUTAVk}jBzH>lv=Y|;A+^`ns6DJsQM(m%fSQB}q| z6QzPThom@3r-CcEBanqT5C!Xi?^zimkMgWcCxUT$z%!LwO2e(nOe;8D>bMdgs!Srk zL8-`%Y5|U7z`1F_fuOx6_bNxV9v#>&)Om+k2#v!hj0bs!rG~EI{aqQM+@pjSsX!ly!Z5f6h?e1ab_Fo+Uk?XMfc|_wu|)U>t?`>?DYhq*AiPtD zCVrDgUGASh`{bEqIl}71gjUIMw!msgW11R_$m!tbxI3Y=6-}B}BnwvQjga7XFS?%B jyY$+g-}HOECbg%t0(UIlA_uSIw_D9l>#}wDZ3yrM+UmJc diff --git a/functions/fn_advancedSlingLoadingInit.sqf b/functions/fn_advancedSlingLoadingInit.sqf deleted file mode 100644 index 730b817..0000000 --- a/functions/fn_advancedSlingLoadingInit.sqf +++ /dev/null @@ -1,1178 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2016 Seth Duda - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -ASL_Advanced_Sling_Loading_Install = { - -// Prevent advanced sling loading from installing twice -if(!isNil "ASL_ROPE_INIT") exitWith {}; -ASL_ROPE_INIT = true; - -diag_log "Advanced Sling Loading Loading..."; - -ASL_Rope_Get_Lift_Capability = { - params ["_vehicle"]; - private ["_slingLoadMaxCargoMass"]; - _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); - if(_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = 4000; - }; - _slingLoadMaxCargoMass; -}; - -ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ - ["All", [-0.05, -0.05, -0.05]], - ["CUP_CH47F_base", [-0.05, -2, -0.05]], - ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], - ["RHS_CH_47F", [-0.75, -2.6, -0.75]], - ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], - ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] -]; - -ASL_Get_Sling_Load_Points = { - params ["_vehicle"]; - private ["_modelPoint", "_modelPointASL", "_surfaceIntersectStartASL", "_surfaceIntersectEndASL", "_la", "_lb", "_n", "_p0", "_l", "_d", "_surfaces","_intersectionASL", "_intersectionObject"]; - private _slingLoadPointsArray = []; - private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); - _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; - _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; - private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; - private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - - private _slingLoadPointHeightOffset = 0; - { - if (_vehicle isKindOf (_x select 0)) then { - _slingLoadPointHeightOffset = (_x select 1); - }; - } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - - private _slingLoadPoints = []; - { - _modelPoint = _x; - _modelPointASL = AGLToASL (_vehicle modelToWorldVisual _modelPoint); - _surfaceIntersectStartASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply -5 ); - _surfaceIntersectEndASL = _modelPointASL vectorAdd ( _vehicleUnitVectorUp vectorMultiply 5 ); - - // Determine if the surface intersection line crosses below ground level - // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces - // doesn't work if starting below ground level for some reason - // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection - - _la = ASLToAGL _surfaceIntersectStartASL; - _lb = ASLToAGL _surfaceIntersectEndASL; - - if (_la select 2 < 0 && _lb select 2 > 0) then { - _n = [0, 0, 1]; - _p0 = [0, 0, 0.1]; - _l = (_la vectorFromTo _lb); - if((_l vectorDotProduct _n) != 0) then { - _d = ( ( _p0 vectorAdd ( _la vectorMultiply -1 ) ) vectorDotProduct _n ) / (_l vectorDotProduct _n); - _surfaceIntersectStartASL = AGLToASL ((_l vectorMultiply _d) vectorAdd _la); - }; - }; - - _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; - _intersectionASL = []; - { - _intersectionObject = _x select 2; - if(_intersectionObject == _vehicle) exitWith { - _intersectionASL = _x select 0; - }; - } forEach _surfaces; - if (count _intersectionASL > 0) then { - _intersectionASL = _intersectionASL vectorAdd (( _surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL ) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); - _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); - } else { - _slingLoadPoints pushBack []; - }; - } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - - if (count (_slingLoadPoints select 1) > 0) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 2]; - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0,_slingLoadPoints select 1,_slingLoadPoints select 2]; - }; - }; - }; - }; - _slingLoadPointsArray; -}; - -ASL_Rope_Set_Mass = { - private _obj = [_this,0] call BIS_fnc_param; - private _mass = [_this,1] call BIS_fnc_param; - _obj setMass _mass; -}; - -ASL_Rope_Adjust_Mass = { - params ["_obj","_heli",["_ropes",[]]]; - private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - private _originalMass = getMass _obj; - private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; - if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift) then { - private _originalMassSet = (getMass _obj) == _originalMass; - private ["_ends", "_endDistance", "_ropeLength"]; - while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { - { - _ends = ropeEndPosition _x; - _endDistance = (_ends select 0) distance (_ends select 1); - _ropeLength = ropeLength _x; - if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0) then { - [[_obj, ((_lift)*0.8)],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - _originalMassSet = false; - }; - } forEach _ropes; - sleep 0.1; - }; - while {_obj in (ropeAttachedObjects _heli)} do { - sleep 0.5; - }; - [[_obj, _originalMass],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; - }; -}; - -/* - Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Active_Ropes = { - params ["_vehicle"]; - private _activeRopes = []; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; - private _ropeIndex = 0; - private _totalExistingRopes = count _existingRopes; - private ["_ropeLabels"]; - { - if (count _x > 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _activeRopes; -}; - -/* - Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle -*/ -ASL_Get_Inactive_Ropes = { - params ["_vehicle"]; - private _inactiveRopes = []; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; - private _ropeIndex = 0; - private _totalExistingRopes = count _existingRopes; - private ["_ropeLabels"]; - { - if (count _x == 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _inactiveRopes; -}; - -ASL_Get_Active_Ropes_With_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(!isNull _cargo) then { - _activeRopesWithCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithCargo; -}; - -ASL_Get_Active_Ropes_Without_Cargo = { - params ["_vehicle"]; - private ["_activeRopesWithoutCargo","_existingCargo","_activeRopes","_cargo"]; - _activeRopesWithoutCargo = []; - _existingCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _activeRopes = _this call ASL_Get_Active_Ropes; - { - _cargo = _existingCargo select (_x select 0); - if(isNull _cargo) then { - _activeRopesWithoutCargo pushBack _x; - }; - } forEach _activeRopes; - _activeRopesWithoutCargo; -}; - -ASL_Get_Ropes = { - params ["_vehicle","_ropeIndex"]; - private ["_allRopes","_selectedRopes"]; - _selectedRopes = []; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _allRopes > _ropeIndex) then { - _selectedRopes = _allRopes select _ropeIndex; - }; - _selectedRopes; -}; - - -ASL_Get_Ropes_Count = { - params ["_vehicle"]; - count (_vehicle getVariable ["ASL_Ropes",[]]); -}; - -ASL_Get_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_allCargo","_selectedCargo"]; - _selectedCargo = objNull; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - if(count _allCargo > _ropeIndex) then { - _selectedCargo = _allCargo select _ropeIndex; - }; - _selectedCargo; -}; - -ASL_Get_Ropes_And_Cargo = { - params ["_vehicle","_ropeIndex"]; - private ["_selectedCargo","_selectedRopes"]; - _selectedCargo = (_this call ASL_Get_Cargo); - _selectedRopes = (_this call ASL_Get_Ropes); - [_selectedRopes, _selectedCargo]; -}; - -ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName","_ropesIndexAndLabelArray",["_ropesLabel","Ropes"]]; - ASL_Show_Select_Ropes_Menu_Array = [[_title,false]]; - { - ASL_Show_Select_Ropes_Menu_Array pushBack [ (_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; - } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; -}; - -ASL_Extend_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 100 ) then { - { - ropeUnwind [_x, 3, 5, true]; - } forEach _existingRopes; - }; - }; - } else { - [_this,"ASL_Extend_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Extend_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Extend_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes","ASL_Extend_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Extend_Ropes; - }; - }; - }; -}; - -ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Extend_Ropes; - }; -}; - -ASL_Extend_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Extend_Ropes; -}; - -ASL_Can_Extend_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Shorten_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopes"]; - _existingRopes = [_vehicle,_ropeIndex] call ASL_Get_Ropes; - if(count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); - if(_ropeLength <= 2 ) then { - _this call ASL_Release_Cargo; - } else { - { - if(_ropeLength >= 10) then { - ropeUnwind [_x, 3, -5, true]; - } else { - ropeUnwind [_x, 3, -1, true]; - }; - } forEach _existingRopes; - }; - }; - } else { - [_this,"ASL_Shorten_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Shorten_Ropes_Action = { - private ["_vehicle"]; - _vehicle = vehicle player; - if([_vehicle] call ASL_Can_Shorten_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes","ASL_Shorten_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Shorten_Ropes; - }; - }; - }; -}; - -ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if(_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle,player,_ropeIndex] call ASL_Shorten_Ropes; - }; -}; - -ASL_Shorten_Ropes_Action_Check = { - if(vehicle player == player) exitWith {false}; - [vehicle player] call ASL_Can_Shorten_Ropes; -}; - -ASL_Can_Shorten_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Release_Cargo = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropeIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - _this call ASL_Retract_Ropes; - } else { - [_this,"ASL_Release_Cargo",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Release_Cargo_Action = { - private _vehicle = vehicle player; - if ([_vehicle] call ASL_Can_Release_Cargo) then { - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo","ASL_Release_Cargo_Index_Action",_activeRopes,"Cargo"] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Release_Cargo; - }; - }; - }; -}; - -ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle,player,_ropesIndex] call ASL_Release_Cargo; - }; -}; - -// ASL_Release_Cargo_Action_Check = { - // if (vehicle player == player) exitWith {false}; - // [vehicle player] call ASL_Can_Release_Cargo; -// }; - -ASL_Release_Cargo_Action_Check = { - params ["_parThis", "_parTarget"]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _parThis: ", _parThis, " _parTarget: ", _parTarget]; - // if (vehicle player == player) exitWith {false}; - // [vehicle player] call ASL_Can_Release_Cargo; - false -}; - -ASL_Can_Release_Cargo = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Retract_Ropes = { - params ["_vehicle","_player",["_ropeIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_allRopes","_activeRopes"]; - _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(isNull _existingCargo) then { - _this call ASL_Drop_Ropes; - { - [_x,_vehicle] spawn { - params ["_rope","_vehicle"]; - private ["_count"]; - _count = 0; - ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; - }; - ropeDestroy _rope; - }; - } forEach _existingRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropeIndex,[]]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; - }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if(count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes",nil,true]; - }; - } else { - [_this,"ASL_Retract_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Retract_Ropes_Action = { - private ["_vehicle","_canRetractRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Retract_Ropes) then { - private ["_activeRopes"]; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if(count _activeRopes > 1) then { - player setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes","ASL_Retract_Ropes_Index_Action",_activeRopes] call ASL_Show_Select_Ropes_Menu; - } else { - if(count _activeRopes == 1) then { - [_vehicle,player,(_activeRopes select 0) select 0] call ASL_Retract_Ropes; - }; - }; - }; -}; - -ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Retract_Ropes; - }; -}; - -ASL_Retract_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Retract_Ropes; - } else { - [vehicle player] call ASL_Can_Retract_Ropes; - }; -}; - -ASL_Can_Retract_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 30) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { false }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if((count _activeRopes) == 0) exitWith { false }; - true; -}; - -ASL_Deploy_Ropes = { - params ["_vehicle","_player",["_cargoCount",1],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_cargoRopes","_startLength","_slingLoadPoints"]; - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _existingRopes == 0) then { - if(count _slingLoadPoints == 0) exitWith { - [["Vehicle doesn't support cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - if(count _slingLoadPoints < _cargoCount) exitWith { - [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - _cargoRopes = []; - _cargo = []; - for "_i" from 0 to (_cargoCount-1) do - { - _cargoRopes pushBack []; - _cargo pushBack objNull; - }; - _vehicle setVariable ["ASL_Ropes",_cargoRopes,true]; - _vehicle setVariable ["ASL_Cargo",_cargo,true]; - for "_i" from 0 to (_cargoCount-1) do - { - [_vehicle,_player,_i] call ASL_Deploy_Ropes_Index; - }; - } else { - [["Vehicle already has cargo ropes deployed", false],"ASL_Hint",_player] call ASL_RemoteExec; - }; - } else { - [_this,"ASL_Deploy_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Deploy_Ropes_Index = { - params ["_vehicle","_player",["_ropesIndex",0],["_ropeLength",15]]; - if(local _vehicle) then { - private ["_existingRopes","_existingRopesCount","_allRopes"]; - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if(count _existingRopes == 0) then { - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - { - ropeUnwind [_x, 5, _ropeLength]; - } forEach _cargoRopes; - _allRopes = _vehicle getVariable ["ASL_Ropes",[]]; - _allRopes set [_ropesIndex,_cargoRopes]; - _vehicle setVariable ["ASL_Ropes",_allRopes,true]; - }; - } else { - [_this,"ASL_Deploy_Ropes_Index",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Deploy_Ropes_Action = { - private ["_vehicle","_canDeployRopes"]; - if(vehicle player == player) then { - _vehicle = cursorTarget; - } else { - _vehicle = vehicle player; - }; - if([_vehicle] call ASL_Can_Deploy_Ropes) then { - - _canDeployRopes = true; - - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _vehicle > 1 ) then { - ["Cannot deploy cargo ropes from locked vehicle",false] call ASL_Hint; - _canDeployRopes = false; - }; - }; - - if(_canDeployRopes) then { - - _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; - - if(count _inactiveRopes > 0) then { - - if(count _inactiveRopes > 1) then { - player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - ["Deploy Cargo Ropes","ASL_Deploy_Ropes_Index_Action",_inactiveRopes] call ASL_Show_Select_Ropes_Menu; - } else { - [_vehicle,player,(_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; - }; - - } else { - - _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if(count _slingLoadPoints > 1) then { - player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [ - ["Deploy Ropes",false] - ]; - ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if((count _slingLoadPoints) > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - if((count _slingLoadPoints) > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; - } else { - [_vehicle,player] call ASL_Deploy_Ropes; - }; - - }; - - }; - - }; -}; - -ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private ["_vehicle"]; - _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - if(_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_ropesIndex] call ASL_Deploy_Ropes_Index; - }; -}; - -ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; - private ["_vehicle","_canDeployRopes"]; - _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - if(_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - [_vehicle,player,_count] call ASL_Deploy_Ropes; - }; -}; - -ASL_Deploy_Ropes_Action_Check = { - if(vehicle player == player) then { - [cursorTarget] call ASL_Can_Deploy_Ropes; - } else { - [vehicle player] call ASL_Can_Deploy_Ropes; - }; -}; - -ASL_Can_Deploy_Ropes = { - params ["_vehicle"]; - private ["_existingRopes","_activeRopes"]; - if(player distance _vehicle > 10) exitWith { false }; - if!([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { false }; - _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _existingVehicle > 0) exitWith { false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if((count _existingRopes) == 0) exitWith { true }; - _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if((count _existingRopes) > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { false }; - true; -}; - -ASL_Get_Corner_Points = { - params ["_vehicle"]; - private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; - private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor","_maxHeight","_heightOffset"]; - - // Correct width and length factor for air - _widthFactor = 0.5; - _lengthFactor = 0.5; - if(_vehicle isKindOf "Air") then { - _widthFactor = 0.3; - }; - if(_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; - }; - - _centerOfMass = getCenterOfMass _vehicle; - _bbr = boundingBoxReal _vehicle; - _p1 = _bbr select 0; - _p2 = _bbr select 1; - _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; - _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; - _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - _heightOffset = _maxHeight/6; - - _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - - [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; -}; - - -ASL_Attach_Ropes = { - params ["_cargo","_player"]; - _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _vehicle = _vehicleWithIndex select 0; - if(!isNull _vehicle) then { - if(local _vehicle) then { - private ["_ropes","_attachmentPoints","_objDistance","_ropeLength","_allCargo"]; - _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; - if(count _ropes == 4) then { - _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - _ropeLength = (ropeLength (_ropes select 0)); - _objDistance = (_cargo distance _vehicle) + 2; - if( _objDistance > _ropeLength ) then { - [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; - } else { - [_vehicle,_player] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0,0,-1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0,0,-1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0,0,-1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0,0,-1]] ropeAttachTo (_ropes select 3); - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [(_vehicleWithIndex select 1),_cargo]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if(missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - }; - }; - }; - } else { - [_this,"ASL_Attach_Ropes",_vehicle,true] call ASL_RemoteExec; - }; - }; -}; - -ASL_Attach_Ropes_Action = { - private ["_vehicle","_cargo","_canBeAttached"]; - _cargo = cursorTarget; - _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]) select 0; - if([_vehicle,_cargo] call ASL_Can_Attach_Ropes) then { - - _canBeAttached = true; - - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked _cargo > 1 ) then { - ["Cannot attach cargo ropes to locked vehicle",false] call ASL_Hint; - _canBeAttached = false; - }; - }; - - if!(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED",false]) then { - if(!isNil "ExilePlayerInSafezone") then { - if( ExilePlayerInSafezone ) then { - ["Cannot attach cargo ropes in safe zone",false] call ASL_Hint; - _canBeAttached = false; - }; - }; - }; - - if(_canBeAttached) then { - [_cargo,player] call ASL_Attach_Ropes; - }; - - }; -}; - -ASL_Attach_Ropes_Action_Check = { - private ["_vehicleWithIndex","_cargo"]; - _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; - _cargo = cursorTarget; - [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; -}; - -ASL_Can_Attach_Ropes = { - params ["_vehicle","_cargo"]; - if(!isNull _vehicle && !isNull _cargo) then { - [_vehicle,_cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - } else { - false; - }; -}; - -ASL_Drop_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_helper","_existingRopes"]; - _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - if(!isNull _helper) then { - _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - { - _helper ropeDetach _x; - } forEach _existingRopes; - detach _helper; - deleteVehicle _helper; - }; - _player setVariable ["ASL_Ropes_Vehicle", nil,true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; - } else { - [_this,"ASL_Drop_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Drop_Ropes_Action = { - private ["_vehicleAndIndex"]; - if([] call ASL_Can_Drop_Ropes) then { - _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - if(count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; - }; - }; -}; - -ASL_Drop_Ropes_Action_Check = { - [] call ASL_Can_Drop_Ropes; -}; - -ASL_Can_Drop_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; -}; - -ASL_Get_Closest_Rope = { - private ["_nearbyVehicles","_closestVehicle","_closestRopeIndex","_closestDistance"]; - private ["_vehicle","_activeRope","_ropes","_ends"]; - private ["_end1","_end2","_minEndDistance"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - _closestVehicle = objNull; - _closestRopeIndex = 0; - _closestDistance = -1; - { - _vehicle = _x; - { - _activeRope = _x; - _ropes = [_vehicle,(_activeRope select 0)] call ASL_Get_Ropes; - { - _ends = ropeEndPosition _x; - if(count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); - if(_closestDistance == -1 || _closestDistance > _minEndDistance) then { - _closestDistance = _minEndDistance; - _closestRopeIndex = (_activeRope select 0); - _closestVehicle = _vehicle; - }; - }; - } forEach _ropes; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearbyVehicles; - [_closestVehicle,_closestRopeIndex]; -}; - -ASL_Pickup_Ropes = { - params ["_vehicle","_player",["_ropesIndex",0]]; - if(local _vehicle) then { - private ["_existingRopesAndCargo","_existingRopes","_existingCargo","_helper","_allCargo"]; - _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - _existingRopes = _existingRopesAndCargo select 0; - _existingCargo = _existingRopesAndCargo select 1; - if(!isNull _existingCargo) then { - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - _allCargo = _vehicle getVariable ["ASL_Cargo",[]]; - _allCargo set [_ropesIndex,objNull]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - }; - _helper = "Land_Can_V2_F" createVehicle position _player; - { - [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; - _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - } forEach _existingRopes; - hideObject _helper; - [[_helper],"ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - _player setVariable ["ASL_Ropes_Vehicle", [_vehicle,_ropesIndex],true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper,true]; - } else { - [_this,"ASL_Pickup_Ropes",_vehicle,true] call ASL_RemoteExec; - }; -}; - -ASL_Pickup_Ropes_Action = { - private ["_nearbyVehicles","_canPickupRopes","_closestRope"]; - _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]; - if([] call ASL_Can_Pickup_Ropes) then { - _closestRope = [] call ASL_Get_Closest_Rope; - if(!isNull (_closestRope select 0)) then { - _canPickupRopes = true; - if!(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED",false]) then { - if( locked (_closestRope select 0) > 1 ) then { - ["Cannot pick up cargo ropes from locked vehicle",false] call ASL_Hint; - _canPickupRopes = false; - }; - }; - if(_canPickupRopes) then { - [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - }; - }; - }; -}; - -ASL_Pickup_Ropes_Action_Check = { - [] call ASL_Can_Pickup_Ropes; -}; - -ASL_Can_Pickup_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; -}; - -ASL_SUPPORTED_VEHICLES = [ - "Helicopter", - "VTOL_Base_F" -]; - -ASL_Is_Supported_Vehicle = { - params ["_vehicle","_isSupported"]; - _isSupported = false; - if(not isNull _vehicle) then { - { - if(_vehicle isKindOf _x) then { - _isSupported = true; - }; - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); - }; - _isSupported; -}; - -ASL_SLING_RULES = [ - ["All","CAN_SLING","All"] -]; - -ASL_Is_Supported_Cargo = { - params ["_vehicle","_cargo"]; - private ["_canSling"]; - _canSling = false; - if(not isNull _vehicle && not isNull _cargo) then { - { - if(_vehicle isKindOf (_x select 0)) then { - if(_cargo isKindOf (_x select 2)) then { - if( (toUpper (_x select 1)) == "CAN_SLING" ) then { - _canSling = true; - } else { - _canSling = false; - }; - }; - }; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE",ASL_SLING_RULES]); - }; - _canSling; -}; - -ASL_Hint = { - params ["_msg",["_isSuccess",true]]; - if(!isNil "ExileClient_gui_notification_event_addNotification") then { - if(_isSuccess) then { - ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; - } else { - ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; - }; - } else { - hint _msg; - }; -}; - -ASL_Hide_Object_Global = { - params ["_obj"]; - if( _obj isKindOf "Land_Can_V2_F" ) then { - hideObjectGlobal _obj; - }; -}; - -ASL_Find_Nearby_Vehicles = { - private ["_nearVehicles","_nearVehiclesWithRopes","_vehicle","_ends","_end1","_end2","_playerPosAGL"]; - _nearVehicles = []; - { - _nearVehicles append (player nearObjects [_x, 30]); - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE",ASL_SUPPORTED_VEHICLES]); - _nearVehiclesWithRopes = []; - { - _vehicle = _x; - { - _ropes = _vehicle getVariable ["ASL_Ropes",[]]; - if(count _ropes > (_x select 0)) then { - _ropes = _ropes select (_x select 0); - { - _ends = ropeEndPosition _x; - if(count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _playerPosAGL = ASLtoAGL getPosASL player; - if((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5 ) then { - _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - } - }; - } forEach _ropes; - }; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearVehicles; - _nearVehiclesWithRopes; -}; - -ASL_Add_Player_Actions = { - - player addAction ["Extend Cargo Ropes", { - [] call ASL_Extend_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Extend_Ropes_Action_Check"]; - - player addAction ["Shorten Cargo Ropes", { - [] call ASL_Shorten_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Shorten_Ropes_Action_Check"]; - - // player addAction ["Release Cargo", { - // [] call ASL_Release_Cargo_Action; - // }, nil, 0, false, true, "", "call ASL_Release_Cargo_Action_Check"]; - - player addAction ["Release Cargo", { - [] call ASL_Release_Cargo_Action; - }, nil, 0, false, true, "", "[_target, _this] call ASL_Release_Cargo_Action_Check"]; - - player addAction ["Retract Cargo Ropes", { - [] call ASL_Retract_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Retract_Ropes_Action_Check"]; - - player addAction ["Deploy Cargo Ropes", { - [] call ASL_Deploy_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Deploy_Ropes_Action_Check"]; - - player addAction ["Attach To Cargo Ropes", { - [] call ASL_Attach_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - - player addAction ["Drop Cargo Ropes", { - [] call ASL_Drop_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - - player addAction ["Pickup Cargo Ropes", { - [] call ASL_Pickup_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - - player addEventHandler ["Respawn", { - player setVariable ["ASL_Actions_Loaded",false]; - }]; - -}; - -if(!isDedicated) then { - [] spawn { - while {true} do { - if(!isNull player && isPlayer player) then { - if!( player getVariable ["ASL_Actions_Loaded",false] ) then { - [] call ASL_Add_Player_Actions; - player setVariable ["ASL_Actions_Loaded",true]; - }; - }; - missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - sleep 2; - }; - }; -}; - -ASL_RemoteExec = { - params ["_params","_functionName","_target",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; - }; - }; -}; - -ASL_RemoteExecServer = { - params ["_params","_functionName",["_isCall",false]]; - if(!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; - } else { - if(_isCall) then { - _params remoteExecCall [_functionName, 2]; - } else { - _params remoteExec [_functionName, 2]; - }; - }; -}; - -if(isServer) then { - - // Adds support for exile network calls (Only used when running exile) // - - ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; - - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { - params ["_sessionId", "_messageParameters",["_isCall",false]]; - _messageParameters params ["_params","_functionName"]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { - if(_isCall) then { - _params call (missionNamespace getVariable [_functionName,{}]); - } else { - _params spawn (missionNamespace getVariable [_functionName,{}]); - }; - }; - }; - - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes","ASL_Deploy_Ropes_Index","ASL_Rope_Set_Mass","ASL_Extend_Ropes","ASL_Shorten_Ropes","ASL_Release_Cargo","ASL_Retract_Ropes","ASL_Deploy_Ropes","ASL_Hint","ASL_Attach_Ropes","ASL_Drop_Ropes"]; - - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { - params ["_sessionId", "_messageParameters"]; - _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; - if(_functionName in ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { - if(_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; - }; - }; - }; - - // Install Advanced Sling Loading on all clients (plus JIP) // - - publicVariable "ASL_Advanced_Sling_Loading_Install"; - remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2,true]; - -}; - -// Disable Old Script Version on SA Server -SA_Rope_Action_Check = {false}; -SA_Rope_Pickup_Rope_Action_Check = {false}; -SA_Rope_Drop_Rope_Action_Check = {false}; -SA_Rope_Attach_Rope_Action_Check = {false}; - -diag_log "Advanced Sling Loading Loaded"; - -}; - -if(isServer) then { - [] call ASL_Advanced_Sling_Loading_Install; -}; diff --git a/keys/AdvancedSlingLoading.bikey b/keys/AdvancedSlingLoading.bikey deleted file mode 100644 index d40d64aa0bafcb33509afb2896c89f396adfea7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 173 zcmV;e08;-!WOiY0V`XGhY-w(1OmAUiX>Ml#lmGw#1_A&803-kaQd2=O00aO40RRC2 z{pPNXp<0#kV5;$I2TB3>y^Ym Date: Mon, 22 Mar 2021 15:44:57 +0100 Subject: [PATCH 08/24] Various changes - localized all texts - added max deploy height option - added min vehicle mass option - added passenger authorized option - removed commander authorized option (there are no commander positions in airial vehicles) - bugfixing - code cleaning --- .../functions/fn_advancedSlingLoadingInit.sqf | 183 +++++++++++------- .../scripts/XEH_preInit.sqf | 35 +++- .../NIC_AdvancedSlingLoading/stringtable.xml | 124 ++++++++++++ 3 files changed, 267 insertions(+), 75 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 22a42e3..e0167ef 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -3,17 +3,23 @@ The MIT License (MIT) Copyright (c) 2016 Seth Duda -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. */ ASL_Advanced_Sling_Loading_Install = { - - // Prevent advanced sling loading from installing twice - if (!isNil "ASL_ROPE_INIT") exitWith {}; + if (!isNil "ASL_ROPE_INIT") exitWith {}; // Prevent advanced sling loading from installing twice ASL_ROPE_INIT = true; diag_log "Advanced Sling Loading Loading..."; @@ -136,7 +142,7 @@ ASL_Advanced_Sling_Loading_Install = { private _originalMass = getMass _obj; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; - if (_originalMass >= ((_lift)*0.8) && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { + if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { private _originalMassSet = (getMass _obj) == _originalMass; private ["_ends", "_endDistance", "_ropeLength"]; while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { @@ -145,7 +151,7 @@ ASL_Advanced_Sling_Loading_Install = { _endDistance = (_ends select 0) distance (_ends select 1); _ropeLength = ropeLength _x; if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0) then { - [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))],"ASL_Rope_Set_Mass",_obj,true] call ASL_RemoteExec; + [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; _originalMassSet = false; }; } forEach _ropes; @@ -155,18 +161,22 @@ ASL_Advanced_Sling_Loading_Install = { sleep 0.5; }; [[_obj, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; - }; + }; }; /* - Constructs an array of all active rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle + Constructs an array of all active rope indexes and position labels + (e.g. [[rope index,"Front"],[rope index,"Rear"]]) for a specified vehicle */ ASL_Get_Active_Ropes = { params ["_vehicle"]; private _activeRopes = []; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeLabelSets = [ + [format[localize "STR_ASL_CENTER"]], + [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_REAR"]], + [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_CENTER"], format[localize "STR_ASL_REAR"]] + ]; private _ropeIndex = 0; private _totalExistingRopes = count _existingRopes; private ["_ropeLabels"]; @@ -181,14 +191,18 @@ ASL_Advanced_Sling_Loading_Install = { }; /* - Constructs an array of all inactive rope indexes and position labels (e.g. [[rope index,"Front"],[rope index,"Rear"]]) - for a specified vehicle + Constructs an array of all inactive rope indexes and position labels + (e.g. [[rope index,"Front"],[rope index,"Rear"]]) for a specified vehicle */ ASL_Get_Inactive_Ropes = { params ["_vehicle"]; private _inactiveRopes = []; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [["Center"], ["Front", "Rear"], ["Front", "Center", "Rear"]]; + private _ropeLabelSets = [ + [format[localize "STR_ASL_CENTER"]], + [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_REAR"]], + [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_CENTER"], format[localize "STR_ASL_REAR"]] + ]; private _ropeIndex = 0; private _totalExistingRopes = count _existingRopes; private ["_ropeLabels"]; @@ -265,12 +279,12 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", "Ropes"]]; + params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", format[localize "STR_ASL_ROPE"]]]; ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; { ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack ["All " + _ropesLabel, [0], "", -5, [["expression", "{ [_x] call " + _functionName + " } forEach [0,1,2];"]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0,1,2];"]], "1", "1"]; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; }; @@ -300,10 +314,9 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Is_Unit_Authorized = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Unit_Authorized) _vehicle: ", _vehicle, " _unit: ", _unit]; - // if (driver _vehicle == _unit || gunner _vehicle == _unit || commander _vehicle == _unit) exitWith {true}; if (driver _vehicle == _unit && ASL_PilotsAuthorized || gunner _vehicle == _unit && ASL_GunnersAuthorized || - commander _vehicle == _unit && ASL_CommandersAuthorized) exitWith {true}; + _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) exitWith {true}; if !(ASL_CopilotsAuthorized) exitWith {false}; private _cfg = configFile >> "CfgVehicles" >> typeOf(_vehicle); private _trts = _cfg >> "turrets"; @@ -338,7 +351,7 @@ ASL_Advanced_Sling_Loading_Install = { }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ["Extend Cargo Ropes", "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; }; @@ -401,7 +414,7 @@ ASL_Advanced_Sling_Loading_Install = { }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ["Shorten Cargo Ropes", "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; }; @@ -464,7 +477,6 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 3"]; false }; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) _existingRopes: ", _existingRopes]; true }; @@ -481,7 +493,7 @@ ASL_Advanced_Sling_Loading_Install = { }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ["Release Cargo", "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; }; }; @@ -548,7 +560,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_vehicle", objNull], "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; - if !([_vehicle] call ASL_Can_Retract_Ropes) exitWith {false}; + if !([_vehicle, _unit] call ASL_Can_Retract_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; if (count _activeRopes == 1) then { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; @@ -556,7 +568,7 @@ ASL_Advanced_Sling_Loading_Install = { }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ["Retract Cargo Ropes", "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_RETRACT"], "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; }; @@ -609,10 +621,10 @@ ASL_Advanced_Sling_Loading_Install = { private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; if (count _existingRopes == 0) then { if (count _slingLoadPoints == 0) exitWith { - [["Vehicle doesn't support cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; + [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; }; if (count _slingLoadPoints < _cargoCount) exitWith { - [["Vehicle doesn't support " + _cargoCount + " cargo ropes", false], "ASL_Hint", _player] call ASL_RemoteExec; + [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _player] call ASL_RemoteExec; }; private _cargoRopes = []; private _cargo = []; @@ -627,7 +639,7 @@ ASL_Advanced_Sling_Loading_Install = { [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; }; } else { - [["Vehicle already has cargo ropes deployed", false], "ASL_Hint", _player] call ASL_RemoteExec; + [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _player] call ASL_RemoteExec; }; } else { [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; @@ -708,7 +720,6 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Deploy_Ropes = { params ["_vehicle", "_unit", ["_distanceCheck", false]]; _unit setVariable ["ASL_TargetDeployVehicle", nil]; - // if (_distanceCheck && player distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 1"]; false @@ -724,14 +735,18 @@ ASL_Advanced_Sling_Loading_Install = { false }; _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _existingRopes == 0) exitWith { + if (getPos _vehicle select 2 > ASL_MaxRopeDeployHeight) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 4"]; + false + }; + if (count _existingRopes == 0) exitWith { + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 5"]; _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; true }; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; if (count _existingRopes > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 5"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 6"]; false }; _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; @@ -747,19 +762,18 @@ ASL_Advanced_Sling_Loading_Install = { private _canDeployRopes = true; if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { if (locked _vehicle > 1) then { - ["Cannot deploy cargo ropes from locked vehicle", false] call ASL_Hint; + [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; _canDeployRopes = false; }; }; - if (!_canDeployRopes) exitWith {}; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _canDeployRopes: ", _canDeployRopes]; - + if (!_canDeployRopes) exitWith {}; + private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; if (count _inactiveRopes > 0) then { if (count _inactiveRopes > 1) then { player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - ["Deploy Cargo Ropes", "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; } else { [_vehicle, player, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; }; @@ -768,14 +782,14 @@ ASL_Advanced_Sling_Loading_Install = { if (count _slingLoadPoints > 1) then { player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; ASL_Deploy_Ropes_Count_Menu = [ - ["Deploy Ropes", false] + [format[localize "STR_ASL_ROPES"], false] ]; - ASL_Deploy_Ropes_Count_Menu pushBack ["For Single Cargo", [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if ((count _slingLoadPoints) > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Double Cargo", [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_SINGLE"], [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if (count _slingLoadPoints > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_DOUBLE"], [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; }; - if ((count _slingLoadPoints) > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack ["For Triple Cargo", [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if (count _slingLoadPoints > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_TRIPLE"], [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; }; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; @@ -830,7 +844,7 @@ ASL_Advanced_Sling_Loading_Install = { private _ropeLength = (ropeLength (_ropes select 0)); private _objDistance = (_cargo distance _vehicle) + 2; if (_objDistance > _ropeLength) then { - [["The cargo ropes are too short. Move vehicle closer.", false],"ASL_Hint",_player] call ASL_RemoteExec; + [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; } else { [_vehicle, _player] call ASL_Drop_Ropes; [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); @@ -858,14 +872,14 @@ ASL_Advanced_Sling_Loading_Install = { private _canBeAttached = true; if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { if (locked _cargo > 1) then { - ["Cannot attach cargo ropes to locked vehicle", false] call ASL_Hint; + [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; _canBeAttached = false; }; }; if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { if (!isNil "ExilePlayerInSafezone") then { if (ExilePlayerInSafezone) then { - ["Cannot attach cargo ropes in safe zone", false] call ASL_Hint; + [format[localize "STR_ASL_CANT_SAFE"], false] call ASL_Hint; _canBeAttached = false; }; }; @@ -903,8 +917,8 @@ ASL_Advanced_Sling_Loading_Install = { detach _helper; deleteVehicle _helper; }; - _player setVariable ["ASL_Ropes_Vehicle", nil,true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil,true]; + _player setVariable ["ASL_Ropes_Vehicle", nil, true]; + _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; } else { [_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec; }; @@ -992,7 +1006,7 @@ ASL_Advanced_Sling_Loading_Install = { private _canPickupRopes = true; if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { if (locked (_closestRope select 0) > 1) then { - ["Cannot pick up cargo ropes from locked vehicle", false] call ASL_Hint; + [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; _canPickupRopes = false; }; }; @@ -1099,17 +1113,38 @@ ASL_Advanced_Sling_Loading_Install = { _nearVehiclesWithRopes; }; + ASL_Switch_Vehicle_Actions = { + { + if (_x isKindOf "Air") then {[_x] call ASL_Add_Vehicle_Actions}; + } forEach vehicles; + }; + ASL_Add_Vehicle_Actions = { params ["_vehicle"]; private _exit = true; { - if (_vehicle isKindOf _x) exitWith {_exit = false}; + if (_vehicle isKindOf _x && getMass _vehicle > ASL_MinVehicleMass) exitWith {_exit = false}; } foreach ASL_SUPPORTED_VEHICLES; - if (_exit) exitWith {}; + private ["_actionID"]; + if (_exit) exitWith { + private _actions = [ + "ASL_ActionID_Deploy", + "ASL_ActionID_Retract", + "ASL_ActionID_Extend", + "ASL_ActionID_Shorten", + "ASL_ActionID_Release" + ]; + { + _actionID = _vehicle getVariable _x; + if (isNil{_actionID}) exitWith {}; + _vehicle removeAction _actionID; + _vehicle setVariable [_x, nil]; + } forEach _actions; + }; if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { - private _actionID = _vehicle addAction [ - "Deploy Cargo Ropes", // Title + _actionID = _vehicle addAction [ + format[localize "STR_ASL_DEPLOY"], // Title {[_this select 0] call ASL_Deploy_Ropes_Action;}, // Script nil, // Arguments 0, // Priority @@ -1122,8 +1157,8 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isNil{_vehicle getVariable "ASL_ActionID_Retract"}) then { - private _actionID = _vehicle addAction [ - "Retract Cargo Ropes", // Title + _actionID = _vehicle addAction [ + format[localize "STR_ASL_RETRACT"], // Title {[_this select 0, _this select 1] call ASL_Retract_Ropes_Action;}, // Script nil, // Arguments 0, // Priority @@ -1136,8 +1171,8 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { - private _actionID = _vehicle addAction [ - "Extend Cargo Ropes", // Title + _actionID = _vehicle addAction [ + format[localize "STR_ASL_EXTEND"], // Title {[_this select 0, _this select 1] call ASL_Extend_Ropes_Action;}, // Script nil, // Arguments 0, // Priority @@ -1150,8 +1185,8 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isNil{_vehicle getVariable "ASL_ActionID_Shorten"}) then { - private _actionID = _vehicle addAction [ - "Shorten Cargo Ropes", // Title + _actionID = _vehicle addAction [ + format[localize "STR_ASL_SHORTEN"], // Title {[_this select 0, _this select 1] call ASL_Shorten_Ropes_Action;}, // Script nil, // Arguments 0, // Priority @@ -1164,8 +1199,8 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isNil{_vehicle getVariable "ASL_ActionID_Release"}) then { - private _actionID = _vehicle addAction [ - "Release Cargo", // Title + _actionID = _vehicle addAction [ + format[localize "STR_ASL_RELEASE"], // Title {[_this select 0, _this select 1] call ASL_Release_Cargo_Action;}, // Script nil, // Arguments 0, // Priority @@ -1179,15 +1214,15 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Add_Player_Actions = { - player addAction ["Pickup Cargo Ropes", { + player addAction [format[localize "STR_ASL_PICKUP"], { [] call ASL_Pickup_Ropes_Action; }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - player addAction ["Drop Cargo Ropes", { + player addAction [format[localize "STR_ASL_DROP"], { [] call ASL_Drop_Ropes_Action; }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - player addAction ["Attach To Cargo Ropes", { + player addAction [format[localize "STR_ASL_ATTACH"], { [] call ASL_Attach_Ropes_Action; }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; @@ -1255,7 +1290,19 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["ASL_Pickup_Ropes", "ASL_Deploy_Ropes_Index", "ASL_Rope_Set_Mass", "ASL_Extend_Ropes", "ASL_Shorten_Ropes", "ASL_Release_Cargo", "ASL_Retract_Ropes", "ASL_Deploy_Ropes", "ASL_Hint", "ASL_Attach_Ropes", "ASL_Drop_Ropes"]; + ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = [ + "ASL_Pickup_Ropes", + "ASL_Deploy_Ropes_Index", + "ASL_Rope_Set_Mass", + "ASL_Extend_Ropes", + "ASL_Shorten_Ropes", + "ASL_Release_Cargo", + "ASL_Retract_Ropes", + "ASL_Deploy_Ropes", + "ASL_Hint", + "ASL_Attach_Ropes", + "ASL_Drop_Ropes" + ]; ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { params ["_sessionId", "_messageParameters"]; @@ -1278,11 +1325,13 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isServer) then { - if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // max rope length in meter - if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // max rope deploy, retract distance in meter (when player is on foot) + if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter + if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // Pilots authorized to manipulate ropes - if (isNil "ASL_CommandersAuthorized") then {ASL_CommandersAuthorized = true}; // Pilots authorized to manipulate ropes if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // Copilots authorized to manipulate ropes - if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = true}; // Gunners authorized to manipulate ropes + if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // Gunners authorized to manipulate ropes + if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // Passengers authorized to manipulate ropes + if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter + if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 4519ace..861830e 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -26,28 +26,47 @@ ] call CBA_fnc_addSetting; [ - "ASL_CommandersAuthorized", + "ASL_CopilotsAuthorized", "CHECKBOX", - [format[localize "STR_ASL_COMMANDER"], format[localize "STR_ASL_COMMANDER_TIP"]], + [format[localize "STR_ASL_COPILOT"], format[localize "STR_ASL_COPILOT_TIP"]], format[localize "STR_ASL_TITLE"], true, true ] call CBA_fnc_addSetting; [ - "ASL_CopilotsAuthorized", + "ASL_GunnersAuthorized", "CHECKBOX", - [format[localize "STR_ASL_COPILOT"], format[localize "STR_ASL_COPILOT_TIP"]], + [format[localize "STR_ASL_GUNNER"], format[localize "STR_ASL_GUNNER_TIP"]], format[localize "STR_ASL_TITLE"], - true, + false, true ] call CBA_fnc_addSetting; [ - "ASL_GunnersAuthorized", + "ASL_PassengersAuthorized", "CHECKBOX", - [format[localize "STR_ASL_GUNNER"], format[localize "STR_ASL_GUNNER_TIP"]], + [format[localize "STR_ASL_PASSENGER"], format[localize "STR_ASL_PASSENGER_TIP"]], format[localize "STR_ASL_TITLE"], - true, + false, true +] call CBA_fnc_addSetting; + +[ + "ASL_MaxRopeDeployHeight", + "SLIDER", + [format[localize "STR_ASL_MAX_DEPLOY_HEIGHT"], format[localize "STR_ASL_MAX_DEPLOY_HEIGHT_TIP"]], + format[localize "STR_ASL_TITLE"], + [0, 1000, 100, 0], + true +] call CBA_fnc_addSetting; + +[ + "ASL_MinVehicleMass", + "SLIDER", + [format[localize "STR_ASL_MIN_MASS"], format[localize "STR_ASL_MIN_MASS_TIP"]], + format[localize "STR_ASL_TITLE"], + [0, 2000, 0, 0], + true, + {[] call ASL_Switch_Vehicle_Actions;} // code executed on option changed AND on init ] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index 2664fa1..c266964 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -52,6 +52,130 @@ Gunner are authorized to manipulate vehicle ropes. Kanoniere sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + Passengers + Passagiere + + + Passengers are authorized to manipulate vehicle ropes. + Passagiere sind berechtigt, Seile von Fahrzeugen zu manipulieren. + + + Maximum Deploy Height + Maximale Ausfahrhöhe + + + Maximal Height in meter above ground, up to which vehicle ropes are allowed to be deployed. + Maximalhöhe in Meter über Grund, bis zu welcher Frachtseile ausgefahren werden dürfen. + + + Minimum Vehicle Mass + Minimales Fahrzeuggewicht + + + Minimal mass in kilogram a vehicle has to have, for ropes to be able to be deployed from that vehicle. + Minimales Gewicht in Kilogramm, das ein Fahrzeug haben muss, um Frachtseile von diesem Fahrzeug ausfahren zu können. + + + Deploy Cargo Ropes + Frachtseile Ausfahren + + + Retract Cargo Ropes + Frachtseile Einfahren + + + Extend Cargo Ropes + Frachtseile Verlängern + + + Shorten Cargo Ropes + Frachtseile Verkürzen + + + Release Cargo + Fracht Ablösen + + + Pickup Cargo Ropes + Frachtseile Aufnehmen + + + Drop Cargo Ropes + Frachtseile Fallen Lassen + + + Attach To Cargo Ropes + An Frachtseile Befestigen + + + Cannot deploy cargo ropes from locked vehicle + Frachtseile können von verschlossenen Fahrzeugen nicht ausgefahren werden + + + Deploy Ropes + Seile Ausfahren + + + For Single Cargo + Für Einzellne Fracht + + + For Double Cargo + Für Doppelte Fracht + + + For Triple Cargo + Für Dreifache Fracht + + + Vehicle doesn't support cargo ropes + Fahrzeug unterstützt keine Frachtseile + + + Vehicle doesn't support %1 cargo ropes + Fahrzeug unterstützt keine %1 Frachtseile + + + Vehicle already has cargo ropes deployed + Fahrzeug hat bereits Frachtseile ausgefahren + + + Cargo ropes too short. Extend ropes or move vehicle closer. + Frachtseile zu kurz. Seile weiter ausfahren oder Fahrzeug näher bringen. + + + Cannot attach cargo ropes to locked vehicle. + Frachtseile können nicht an verschlossene Fahrzeuge befestigt werden. + + + Cannot attach cargo ropes in safe zone. + Frachtseile können nicht bfestigt werden in sicheren Zonen. + + + Cannot pick up cargo ropes from locked vehicle. + Frachtseile verschlossener Fahrzeuge können nicht aufgenommen werden. + + + All + Alle + + + Ropes + Seile + + + Front + Front + + + Rear + Heck + + + Center + Zentral \ No newline at end of file From da9260525674d54f68668a9e97443df11e276cd4 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 26 Mar 2021 15:41:15 +0100 Subject: [PATCH 09/24] work commit work commit for further development --- .../ASL_weightSmall.p3d | Bin 0 -> 1323 bytes addons/NIC_AdvancedSlingLoading/config.cpp | 11 +- .../functions/fn_advancedSlingLoadingInit.sqf | 1010 +++++++++++------ mod.cpp | 2 +- 4 files changed, 700 insertions(+), 323 deletions(-) create mode 100644 addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d diff --git a/addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d b/addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d new file mode 100644 index 0000000000000000000000000000000000000000..3f147bb3cf4448a00666db0214af484f6fd0a202 GIT binary patch literal 1323 zcmcIiOHKko5bee<_#ON%T$uC)G%PWhF@mswV1l@ogz=Lo5a9r`@FpC=B?~t$byF|b6BgbFvg^@Rzc;e%ZLE`tufY0=w#jD$cORU>l@!=jL9lpo>nSSHSgL_{c`6v z94K*ZIQsSMtLb~d8cqa{JF%|_kMkgh4sjOb;jxYw>xkjyS?{sm>xSLo(J^0~Oq!~< z2XvG}qJF&BPNog1T35|*sKgtQlV*E_kH=uyHS3d=gaT7ze7gSs@=}$%oyN`i{X?ku JRG-gY>k9$Wq|E>T literal 0 HcmV?d00001 diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp index b69682b..65414e5 100644 --- a/addons/NIC_AdvancedSlingLoading/config.cpp +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -1,7 +1,8 @@ class CfgPatches { class SA_AdvancedSlingLoading { units[] = { - "SA_AdvancedSlingLoading" + "SA_AdvancedSlingLoading", + "ASL_RopeSmallWeight" }; requiredVersion = 1; requiredAddons[] = { @@ -47,6 +48,14 @@ class Extended_PreInit_EventHandlers { init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration }; }; +class CfgVehicles { + class Land_Camping_Light_F; + class ASL_RopeSmallWeight : Land_Camping_Light_F { + scope = 2; + displayname = "Rope weight"; + model = "\SA_AdvancedSlingLoading\ASL_weightSmall"; + }; +}; class cfgMods { author = "76561198131707990"; timepacked = "1473204282"; diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index e0167ef..b22eef7 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -55,7 +55,8 @@ ASL_Advanced_Sling_Loading_Install = { private _slingLoadPointHeightOffset = 0; { - if (_vehicle isKindOf (_x select 0)) then { + // if (_vehicle isKindOf (_x select 0)) then { + if (_vehicle isKindOf (_x select 0)) exitWith { _slingLoadPointHeightOffset = (_x select 1); }; } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; @@ -141,7 +142,14 @@ ASL_Advanced_Sling_Loading_Install = { private _maxLiftableMass = _lift * 8; private _originalMass = getMass _obj; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11", time, "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, " _originalMass: ", _originalMass, " _heli: ", _heli, " _lift: ", _lift, " _heavyLiftMinLift: ", _heavyLiftMinLift]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11", time, + // "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, + // " _originalMass: ", _originalMass, + // " _heli: ", _heli, + // " _lift: ", _lift, + // " _heavyLiftMinLift: ", _heavyLiftMinLift + // ]; if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { private _originalMassSet = (getMass _obj) == _originalMass; private ["_ends", "_endDistance", "_ropeLength"]; @@ -289,14 +297,6 @@ ASL_Advanced_Sling_Loading_Install = { showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; }; - ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; - }; - }; - ASL_Extend_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -355,6 +355,14 @@ ASL_Advanced_Sling_Loading_Install = { }; }; + ASL_Extend_Ropes_Index_Action = { + params ["_ropeIndex"]; + private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; + }; + }; + ASL_Extend_Ropes = { params ["_vehicle", "_player", ["_ropeIndex", 0]]; if (local _vehicle) exitWith { @@ -370,15 +378,7 @@ ASL_Advanced_Sling_Loading_Install = { }; [_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec; }; - - ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; - }; - }; - + ASL_Shorten_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -417,7 +417,15 @@ ASL_Advanced_Sling_Loading_Install = { [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; }; - + + ASL_Shorten_Ropes_Index_Action = { + params ["_ropeIndex"]; + private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; + }; + }; + ASL_Shorten_Ropes = { params ["_vehicle", "_player", ["_ropeIndex", 0]]; if (local _vehicle) exitWith { @@ -438,15 +446,7 @@ ASL_Advanced_Sling_Loading_Install = { }; [_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec; }; - - ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; - }; - }; - + ASL_Release_Cargo_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -496,6 +496,14 @@ ASL_Advanced_Sling_Loading_Install = { [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; }; }; + + ASL_Release_Cargo_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; + }; + }; ASL_Release_Cargo = { params ["_vehicle", "_player", ["_ropeIndex", 0]]; @@ -514,7 +522,7 @@ ASL_Advanced_Sling_Loading_Install = { }; [_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec; }; - + ASL_Retract_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -613,63 +621,7 @@ ASL_Advanced_Sling_Loading_Install = { // [_vehicle, _ropesIndex] call ASL_Retract_Ropes; }; }; - - ASL_Deploy_Ropes = { - params ["_vehicle", "_player", ["_cargoCount", 1]]; - if (local _vehicle) then { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - if (count _existingRopes == 0) then { - if (count _slingLoadPoints == 0) exitWith { - [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - if (count _slingLoadPoints < _cargoCount) exitWith { - [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - private _cargoRopes = []; - private _cargo = []; - for "_i" from 0 to (_cargoCount-1) do { - _cargoRopes pushBack []; - _cargo pushBack objNull; - }; - _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; - _vehicle setVariable ["ASL_Cargo", _cargo, true]; - for "_i" from 0 to (_cargoCount-1) do - { - [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; - }; - } else { - [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _player] call ASL_RemoteExec; - }; - } else { - [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Deploy_Ropes_Index = { - params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; - if (local _vehicle) then { - private _existingRopes = [_vehicle,_ropesIndex] call ASL_Get_Ropes; - private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - if (count _existingRopes == 0) then { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - private _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - { - ropeUnwind [_x, 5, _ropeLength]; - } forEach _cargoRopes; - private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - _allRopes set [_ropesIndex, _cargoRopes]; - _vehicle setVariable ["ASL_Ropes", _allRopes, true]; - }; - } else { - [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; - }; - }; - + ASL_Deploy_Ropes_Index_Action = { params ["_ropesIndex"]; private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; @@ -755,21 +707,13 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Deploy_Ropes_Action = { params [["_vehicle", objNull]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; if (isNull _vehicle) exitWith {false}; - - private _canDeployRopes = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked _vehicle > 1) then { - [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; - _canDeployRopes = false; - }; + if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; }; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _canDeployRopes: ", _canDeployRopes]; - if (!_canDeployRopes) exitWith {}; - private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _inactiveRopes: ", _inactiveRopes]; if (count _inactiveRopes > 0) then { if (count _inactiveRopes > 1) then { player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; @@ -799,6 +743,161 @@ ASL_Advanced_Sling_Loading_Install = { }; }; + // ASL_Deploy_Ropes = { + // params ["_vehicle", "_player", ["_cargoCount", 1]]; + // if (local _vehicle) exitWith { + // private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + // private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; + // if (count _existingRopes == 0) then { + // if (count _slingLoadPoints == 0) exitWith { + // [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; + // }; + // if (count _slingLoadPoints < _cargoCount) exitWith { + // [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _player] call ASL_RemoteExec; + // }; + // private _cargoRopes = []; + // private _cargo = []; + // for "_i" from 0 to (_cargoCount-1) do { + // _cargoRopes pushBack []; + // _cargo pushBack objNull; + // }; + // _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; + // _vehicle setVariable ["ASL_Cargo", _cargo, true]; + // for "_i" from 0 to (_cargoCount-1) do + // { + // [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; + // }; + // } else { + // [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _player] call ASL_RemoteExec; + // }; + // }; + // [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; + // }; + + ASL_Deploy_Ropes = { + params ["_vehicle", "_unit", ["_cargoCount", 1]]; + if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _existingRopes > 0 && _unit == player) exitWith { + [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + }; + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + if (count _slingLoadPoints == 0 && _unit == player) exitWith { + [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + }; + if (count _slingLoadPoints < _cargoCount && _unit == player) exitWith { + [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _unit] call ASL_RemoteExec; + }; + private _cargoRopes = []; + private _cargo = []; + for "_i" from 0 to (_cargoCount - 1) do { + _cargoRopes pushBack []; + _cargo pushBack objNull; + }; + _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; + _vehicle setVariable ["ASL_Cargo", _cargo, true]; + for "_i" from 0 to (_cargoCount - 1) do { + [_vehicle, _unit, _i] call ASL_Deploy_Ropes_Index; + }; + }; + + // ASL_Deploy_Ropes_Index = { + // params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; + // if (local _vehicle) exitWith { + // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + // if (count _existingRopes == 0) then { + // private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + // private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + // private _cargoRopes = []; + // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + // { + // ropeUnwind [_x, 5, _ropeLength]; + // } forEach _cargoRopes; + // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + // _allRopes set [_ropesIndex, _cargoRopes]; + // _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + // }; + // }; + // [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; + // }; + + ASL_Deploy_Ropes_Index = { + params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_ropeLength", 15]]; + if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec}; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) exitWith {}; + private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + private _cargoRopes = []; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + private ["_helper"]; + private _helperArray = []; + { + // _helper = createVehicle ["ASL_RopeSmallWeight", (ropeEndPosition _x) select 1, [], 0, "CAN_COLLIDE"]; + // _helper setMass 0.1; + // _helper allowDamage false; + // [_helper, [0, 0, 0], [0, 0, 0]] ropeAttachTo _x; + // _helper setVariable ["ASL_RopeEndHelper", true, true]; + // _helper setVariable ["ASL_RopesIndex", _ropesIndex, true]; + + + // Once helper is attached to a rope end, it begins searchching for unit in pickup range. + // Only if a unit is then found, the unit will get the 'pickup ropes' action. + // [_helper] spawn ASL_Add_Pickup_Action; + _helper = [_x, _ropesIndex] call ASL_Create_Rope_End_Helper; + _helperArray pushBack _helper; + ropeUnwind [_x, 5, _ropeLength]; + } forEach _cargoRopes; + { + _x setVariable ["ASL_RopesHelperArray", _helperArray, true]; + } forEach _helperArray; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropesIndex, _cargoRopes]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + }; + + ASL_Create_Rope_End_Helper = { + params ["_rope", "_ropesIndex"]; + private _helper = createVehicle ["ASL_RopeSmallWeight", (ropeEndPosition _rope) select 1, [], 0, "CAN_COLLIDE"]; + _helper setMass 0.1; + _helper allowDamage false; + [_helper, [0, 0, 0], [0, 0, 0]] ropeAttachTo _rope; + _helper setVariable ["ASL_RopeEndHelper", true, true]; + _helper setVariable ["ASL_RopesIndex", _ropesIndex, true]; + [_helper] spawn ASL_Add_Pickup_Action; + }; + + ASL_Add_Pickup_Action = { + params [["_object", objNull]]; + if (isNull _object) exitWith {}; + while {alive _object} do { + private _nearbyUnits = (_object nearObjects (ASL_RopePickupDistance)) select {_x isKindOf "CAManBase" && side _x == side player && vehicle _x == _x}; + // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Add_Pickup_Action) _nearbyUnits: ", _nearbyUnits]; + { + if (isNil{_x getVariable "ASL_ActionID_Pickup"}) then { + private _actionID = _x addAction [ + format[localize "STR_ASL_PICKUP"], // Title + {[_this select 0] call ASL_Pickup_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Pickup_Ropes_Action_Check" // Condition + ]; + _x setVariable ["ASL_ActionID_Pickup", _actionID]; + }; + } forEach _nearbyUnits; + sleep 0.5; + }; + }; + ASL_Get_Corner_Points = { params ["_vehicle"]; @@ -832,113 +931,412 @@ ASL_Advanced_Sling_Loading_Install = { [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; - ASL_Attach_Ropes = { - params ["_cargo", "_player"]; - private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - private _vehicle = _vehicleWithIndex select 0; - if (!isNull _vehicle) then { - if (local _vehicle) then { - private _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; - if (count _ropes == 4) then { - private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - private _ropeLength = (ropeLength (_ropes select 0)); - private _objDistance = (_cargo distance _vehicle) + 2; - if (_objDistance > _ropeLength) then { - [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; - } else { - [_vehicle, _player] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [(_vehicleWithIndex select 1),_cargo]; - _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - }; - }; - }; - } else { - [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; - }; + // ASL_Pickup_Ropes_Action_Check = { + // [] call ASL_Can_Pickup_Ropes; + // }; + + // ASL_Can_Pickup_Ropes = { + // count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; + // }; + + ASL_Pickup_Ropes_Action_Check = { + params [["_unit", objNull]]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _target: ", _target, ", _this: ", _this]; + // hintSilent formatText ["%1%2%3%4%5%6", time, "s (ASL_Pickup_Ropes_Action_Check) _unit: ", _unit, lineBreak, "rope ends found: ", count ((_unit nearObjects 5) select {_x getVariable ["ASL_RopeEndHelper", false]})]; + if (count ((_unit nearObjects ASL_RopePickupDistance) select {_x getVariable ["ASL_RopeEndHelper", false]}) > 0 && vehicle _unit == _unit) exitWith {true}; + [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Unit_Actions; // if no rope helper objects near, remove pickup action from unit + false + }; + + // ASL_Pickup_Ropes_Action = { + // // private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; + // if ([] call ASL_Can_Pickup_Ropes) then { + // private _closestRope = [] call ASL_Get_Closest_Rope; + // if (!isNull (_closestRope select 0)) then { + // private _canPickupRopes = true; + // if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + // if (locked (_closestRope select 0) > 1) then { + // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; + // _canPickupRopes = false; + // }; + // }; + // if (_canPickupRopes) then { + // [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; + // }; + // }; + // }; + // }; + + ASL_Pickup_Ropes_Action = { + params [["_unit", objNull]]; + private _ropeEnds = (nearestObjects [_unit, [], ASL_RopePickupDistance]) select {_x getVariable ["ASL_RopeEndHelper", false]}; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _unit: ", _unit, lineBreak, "rope ends 1: ", count _ropeEnds1, lineBreak, "rope ends: ", count _ropeEnds]; + private _closestRopeEnd = _ropeEnds select 0; + if (isNull _closestRopeEnd) exitWith {}; + private _helperArray = _closestRopeEnd getVariable ["ASL_RopesHelperArray", []]; + private _ropesIndex = _closestRopeEnd getVariable "ASL_RopesIndex"; + private _vehicle = ropeAttachedTo _closestRopeEnd; + diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _helperArray: ", _helperArray, "_vehicle: ", _vehicle, "_ropesIndex: ", _ropesIndex]; + if (isNull _vehicle) exitWith {}; + if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; }; + { + deleteVehicle _x; + } forEach _helperArray; // once we got all relevant info, we no longer need the helpers + [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; }; + + // ASL_Pickup_Ropes = { + // params ["_vehicle", "_player", ["_ropesIndex", 0]]; + // if (local _vehicle) exitWith { + // private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; + // private _existingRopes = _existingRopesAndCargo select 0; + // private _existingCargo = _existingRopesAndCargo select 1; + // if (!isNull _existingCargo) then { + // { + // _existingCargo ropeDetach _x; + // } forEach _existingRopes; + // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + // _allCargo set [_ropesIndex, objNull]; + // _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + // }; + // private _helper = "Land_Can_V2_F" createVehicle position _player; + // { + // [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; + // _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; + // } forEach _existingRopes; + // hideObject _helper; + // [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + // _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; + // _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; + // }; + // [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; + // }; - ASL_Attach_Ropes_Action = { - private _cargo = cursorTarget; - private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; - if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { - private _canBeAttached = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked _cargo > 1) then { - [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; - _canBeAttached = false; - }; - }; - if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { - if (!isNil "ExilePlayerInSafezone") then { - if (ExilePlayerInSafezone) then { - [format[localize "STR_ASL_CANT_SAFE"], false] call ASL_Hint; - _canBeAttached = false; - }; - }; - }; - if (_canBeAttached) then { - [_cargo, player] call ASL_Attach_Ropes; - }; + ASL_Pickup_Ropes = { + params ["_vehicle", "_unit", ["_ropesIndex", 0]]; + if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + if (!isNull _existingCargo) then { + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropesIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + }; + private _helper = "Land_Can_V2_F" createVehicle position _unit; + { + [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; + _helper attachTo [_unit, [-0.1, 0.1, 0.15], "Pelvis"]; + } forEach _existingRopes; + hideObjectGlobal _helper; + // [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; + _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; + _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; + + [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Unit_Actions; // remove pickup action, once unit has picked up some ropes + + private ["_actionID"]; + if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { + _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes + format[localize "STR_ASL_ATTACH"], // Title + {[_this select 0] call ASL_Attach_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Attach_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_Attach", _actionID]; + }; + + if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { + _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes + format[localize "STR_ASL_DROP"], // Title + {[_this select 0] call ASL_Drop_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Drop_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_Drop", _actionID]; }; }; + + + + + + + + + + + + + + + + + + // ASL_Attach_Ropes_Action_Check = { + // private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; + // private _cargo = cursorTarget; + // [_vehicleWithIndex select 0, _cargo] call ASL_Can_Attach_Ropes; + // }; + ASL_Attach_Ropes_Action_Check = { - private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull,0]]; + params [["_unit", objNull]]; + if (isNull _unit) exitWith {false}; + private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; private _cargo = cursorTarget; - [_vehicleWithIndex select 0,_cargo] call ASL_Can_Attach_Ropes; - }; - - ASL_Can_Attach_Ropes = { - params ["_vehicle", "_cargo"]; - if (!isNull _vehicle && !isNull _cargo) then { - [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - } else { - false; - }; - }; + [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < 10 && _vehicle != _cargo; + }; + + // ASL_Can_Attach_Ropes = { + // params ["_vehicle", "_cargo", ["_unit", player]]; + // if (isNull _vehicle || isNull _cargo) exitWith {false}; + // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < 10 && _vehicle != _cargo; + // }; + + // ASL_Can_Attach_Ropes = { + // params ["_vehicle", "_cargo"]; + // if (!isNull _vehicle && !isNull _cargo) then { + // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; + // } else { + // false; + // }; + // }; + + // ASL_Attach_Ropes_Action = { + // private _cargo = cursorTarget; + // private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + // if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { + // // private _canBeAttached = true; + // // if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { + // // if (locked _cargo > 1) then { + // // [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; + // // _canBeAttached = false; + // // }; + // // }; + // if (locked _cargo > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + // [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; + // }; + + // private _canBeAttached = true; + // if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { + // if (!isNil "ExilePlayerInSafezone") then { + // if (ExilePlayerInSafezone) then { + // [format[localize "STR_ASL_CANT_SAFE"], false] call ASL_Hint; + // _canBeAttached = false; + // }; + // }; + // }; + + // if (_canBeAttached) then { + // [_cargo, player] call ASL_Attach_Ropes; + // }; + // }; + // }; - ASL_Drop_Ropes = { - params ["_vehicle", "_player", ["_ropesIndex", 0]]; - if (local _vehicle) then { - private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - if (!isNull _helper) then { - private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - { - _helper ropeDetach _x; - } forEach _existingRopes; - detach _helper; - deleteVehicle _helper; + ASL_Attach_Ropes_Action = { + params [["_unit", objNull]]; + if (isNull _unit) exitWith {}; + private _cargo = cursorTarget; + private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + if (locked _cargo > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; + }; + private _canBeAttached = true; + if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { + if (!isNil "ExilePlayerInSafezone") then { + if (ExilePlayerInSafezone) then { + [format[localize "STR_ASL_CANT_SAFE"], false] call ASL_Hint; + _canBeAttached = false; + }; }; - _player setVariable ["ASL_Ropes_Vehicle", nil, true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; - } else { - [_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec; }; - }; + if (_canBeAttached) then { + [_cargo, _unit] call ASL_Attach_Ropes; + }; + }; + + // ASL_Attach_Ropes = { + // params ["_cargo", "_player"]; + // private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; + // private _vehicle = _vehicleWithIndex select 0; + // if (!isNull _vehicle) then { + // if (local _vehicle) then { + // private _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; + // if (count _ropes == 4) then { + // private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + // private _ropeLength = (ropeLength (_ropes select 0)); + // private _objDistance = (_cargo distance _vehicle) + 2; + // if (_objDistance > _ropeLength) then { + // [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; + // } else { + // [_vehicle, _player] call ASL_Drop_Ropes; + // [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); + // [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); + // [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); + // [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); + // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + // _allCargo set [(_vehicleWithIndex select 1),_cargo]; + // _vehicle setVariable ["ASL_Cargo",_allCargo, true]; + // if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { + // [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + // }; + // }; + // }; + // } else { + // [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; + // }; + // }; + // }; - ASL_Drop_Ropes_Action = { - if ([] call ASL_Can_Drop_Ropes) then { - private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - if (count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + ASL_Attach_Ropes = { + params ["_cargo", ["_unit", objNull]]; + private _vehicleWithIndex = _unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; + private _vehicle = _vehicleWithIndex select 0; + if (isNull _vehicle) exitWith {}; + if !(local _vehicle) exitWith {[_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _ropes = [_vehicle, _vehicleWithIndex select 1] call ASL_Get_Ropes; + if (count _ropes != 4) exitWith {}; + private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; + private _ropeLength = (ropeLength (_ropes select 0)); + private _objDistance = (_cargo distance _vehicle) + 2; + if (_objDistance > _ropeLength) then { + [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + } else { + _cargo setVariable ["ASL_RopeEndHelper", true, true]; + private _ropesIndex = _vehicleWithIndex select 1; + _cargo setVariable ["ASL_RopesIndex", _ropesIndex, true]; + + + [_vehicle, _unit] call ASL_Drop_Ropes; + [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); + [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); + [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); + [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [(_vehicleWithIndex select 1), _cargo]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { + [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; }; - }; - }; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Unit_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo + [_cargo] spawn ASL_Add_Pickup_Action; + }; + }; + // ASL_Pickup_Ropes_Action = { + // params [["_unit", objNull]]; + // private _ropeEnds = (nearestObjects [_unit, [], ASL_RopePickupDistance]) select {_x getVariable ["ASL_RopeEndHelper", false]}; + // // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _unit: ", _unit, lineBreak, "rope ends 1: ", count _ropeEnds1, lineBreak, "rope ends: ", count _ropeEnds]; + // private _closestRopeEnd = _ropeEnds select 0; + // if (isNull _closestRopeEnd) exitWith {}; + // private _helperArray = _closestRopeEnd getVariable ["ASL_RopesHelperArray", []]; + // private _ropesIndex = _closestRopeEnd getVariable "ASL_RopesIndex"; + // private _vehicle = ropeAttachedTo _closestRopeEnd; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _helperArray: ", _helperArray, lineBreak, "_vehicle: ", _vehicle]; + // if (isNull _vehicle) exitWith {}; + // if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; + // }; + // { + // deleteVehicle _x; + // } forEach _helperArray; // once we got all relevant info, we no longer need the helpers + // [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; + // }; + + + + + + + + + + + + + // ASL_Drop_Ropes_Action_Check = { + // [] call ASL_Can_Drop_Ropes; + // }; + + // ASL_Can_Drop_Ropes = { + // count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; + // }; ASL_Drop_Ropes_Action_Check = { - [] call ASL_Can_Drop_Ropes; + params [["_unit", objNull]]; + if (isNull _unit) exitWith {false}; + count (_unit getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle _unit == _unit; }; - ASL_Can_Drop_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; + // ASL_Drop_Ropes_Action = { + // if ([] call ASL_Can_Drop_Ropes) then { + // private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; + // if (count _vehicleAndIndex == 2) then { + // [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + // }; + // }; + // }; + + ASL_Drop_Ropes_Action = { + params [["_unit", objNull]]; + if (isNull _unit) exitWith {false}; + private _vehicleAndIndex = _unit getVariable ["ASL_Ropes_Vehicle", []]; + if (count _vehicleAndIndex == 2) then { + [_vehicleAndIndex select 0, _unit, _vehicleAndIndex select 1, true] call ASL_Drop_Ropes; + }; + }; + + // ASL_Drop_Ropes = { + // params ["_vehicle", "_player", ["_ropesIndex", 0]]; + // if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; + // private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + // if (!isNull _helper) then { + // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + // { + // _helper ropeDetach _x; + // } forEach _existingRopes; + // detach _helper; + // deleteVehicle _helper; + // }; + // _player setVariable ["ASL_Ropes_Vehicle", nil, true]; + // _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; + // }; + + ASL_Drop_Ropes = { + params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_createHelper", false]]; + if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + if (!isNull _helper) then { + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + private _helperArray = []; + { + _helper ropeDetach _x; + if (_createHelper) then { + _endHelper = [_x, _ropesIndex] call ASL_Create_Rope_End_Helper; + _helperArray pushBack _endHelper; + }; + } forEach _existingRopes; + detach _helper; + deleteVehicle _helper; + }; + { + _x setVariable ["ASL_RopesHelperArray", _helperArray, true]; + } forEach _helperArray; + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; ASL_Get_Closest_Rope = { @@ -970,61 +1368,6 @@ ASL_Advanced_Sling_Loading_Install = { [_closestVehicle, _closestRopeIndex]; }; - ASL_Pickup_Ropes = { - params ["_vehicle", "_player", ["_ropesIndex", 0]]; - if (local _vehicle) then { - private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - if (!isNull _existingCargo) then { - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [_ropesIndex, objNull]; - _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - }; - private _helper = "Land_Can_V2_F" createVehicle position _player; - { - [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; - _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - } forEach _existingRopes; - hideObject _helper; - [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; - _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - } else { - [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; - }; - }; - - ASL_Pickup_Ropes_Action = { - private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; - if ([] call ASL_Can_Pickup_Ropes) then { - private _closestRope = [] call ASL_Get_Closest_Rope; - if (!isNull (_closestRope select 0)) then { - private _canPickupRopes = true; - if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - if (locked (_closestRope select 0) > 1) then { - [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; - _canPickupRopes = false; - }; - }; - if (_canPickupRopes) then { - [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - }; - }; - }; - }; - - ASL_Pickup_Ropes_Action_Check = { - [] call ASL_Can_Pickup_Ropes; - }; - - ASL_Can_Pickup_Ropes = { - count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; - }; - ASL_SUPPORTED_VEHICLES = [ "Helicopter", "VTOL_Base_F" @@ -1046,22 +1389,33 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Is_Supported_Cargo = { params ["_vehicle", "_cargo"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Supported_Cargo) _vehicle: ", _vehicle, ", _cargo: ", _cargo]; + if (isNull _vehicle || isNull _cargo) exitWith {false}; private _canSling = false; - if (not isNull _vehicle && not isNull _cargo) then { - { - if (_vehicle isKindOf (_x select 0)) then { - if (_cargo isKindOf (_x select 2)) then { - if ((toUpper (_x select 1)) == "CAN_SLING") then { - _canSling = true; - } else { - _canSling = false; - }; - }; - }; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); - }; - _canSling; - }; + { + if (_vehicle isKindOf (_x select 0) && _cargo isKindOf (_x select 2) && (toUpper (_x select 1)) == "CAN_SLING") exitWith {_canSling = true}; + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); + _canSling + }; + + // ASL_Is_Supported_Cargo = { + // params ["_vehicle", "_cargo"]; + // private _canSling = false; + // if (not isNull _vehicle && not isNull _cargo) then { + // { + // if (_vehicle isKindOf (_x select 0)) then { + // if (_cargo isKindOf (_x select 2)) then { + // if ((toUpper (_x select 1)) == "CAN_SLING") then { + // _canSling = true; + // } else { + // _canSling = false; + // }; + // }; + // }; + // } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); + // }; + // _canSling; + // }; ASL_Hint = { params ["_msg", ["_isSuccess", true]]; @@ -1083,42 +1437,42 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - ASL_Find_Nearby_Vehicles = { - private _nearVehicles = []; - { - _nearVehicles append (player nearObjects [_x, 30]); - } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); - private _nearVehiclesWithRopes = []; - private ["_vehicle", "_ropes", "_ends", "_end1", "_end2", "_playerPosAGL"]; - { - _vehicle = _x; - { - _ropes = _vehicle getVariable ["ASL_Ropes",[]]; - if (count _ropes > (_x select 0)) then { - _ropes = _ropes select (_x select 0); - { - _ends = ropeEndPosition _x; - if (count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _playerPosAGL = ASLtoAGL getPosASL player; - if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { - _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - } - }; - } forEach _ropes; - }; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearVehicles; - _nearVehiclesWithRopes; - }; + // ASL_Find_Nearby_Vehicles = { + // private _nearVehicles = []; + // { + // _nearVehicles append (player nearObjects [_x, 30]); + // } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); + // private _nearVehiclesWithRopes = []; + // private ["_vehicle", "_ropes", "_ends", "_end1", "_end2", "_playerPosAGL"]; + // { + // _vehicle = _x; + // { + // _ropes = _vehicle getVariable ["ASL_Ropes",[]]; + // if (count _ropes > (_x select 0)) then { + // _ropes = _ropes select (_x select 0); + // { + // _ends = ropeEndPosition _x; + // if (count _ends == 2) then { + // _end1 = _ends select 0; + // _end2 = _ends select 1; + // _playerPosAGL = ASLtoAGL getPosASL player; + // if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { + // _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; + // } + // }; + // } forEach _ropes; + // }; + // } forEach ([_vehicle] call ASL_Get_Active_Ropes); + // } forEach _nearVehicles; + // _nearVehiclesWithRopes; + // }; + + // ASL_Switch_Vehicle_Actions = { + // { + // if (_x isKindOf "Air") then {[_x] call ASL_Add_Vehicle_Actions}; + // } forEach vehicles; + // }; - ASL_Switch_Vehicle_Actions = { - { - if (_x isKindOf "Air") then {[_x] call ASL_Add_Vehicle_Actions}; - } forEach vehicles; - }; - ASL_Add_Vehicle_Actions = { params ["_vehicle"]; private _exit = true; @@ -1141,7 +1495,7 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable [_x, nil]; } forEach _actions; }; - + if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_DEPLOY"], // Title @@ -1169,7 +1523,7 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Retract", _actionID]; }; - + if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_EXTEND"], // Title @@ -1212,39 +1566,52 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; }; + + ASL_Remove_Unit_Actions = { + params [["_unit", objNull], ["_actions", []]]; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Unit_Actions) _unit: ", _unit, " _actions: ", _actions]; + if (isNull _unit) exitWith {false}; + { + private _actionID = _unit getVariable _x; + if !(isNil{_actionID}) then { + _unit removeAction _actionID; + _unit setVariable [_x, nil]; + }; + } forEach _actions; + }; - ASL_Add_Player_Actions = { - player addAction [format[localize "STR_ASL_PICKUP"], { - [] call ASL_Pickup_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; + // ASL_Add_Player_Actions = { + // player addAction [format[localize "STR_ASL_PICKUP"], { + // [] call ASL_Pickup_Ropes_Action; + // }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - player addAction [format[localize "STR_ASL_DROP"], { - [] call ASL_Drop_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; + // player addAction [format[localize "STR_ASL_DROP"], { + // [] call ASL_Drop_Ropes_Action; + // }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - player addAction [format[localize "STR_ASL_ATTACH"], { - [] call ASL_Attach_Ropes_Action; - }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; + // player addAction [format[localize "STR_ASL_ATTACH"], { + // [] call ASL_Attach_Ropes_Action; + // }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - player addEventHandler ["Respawn", { - player setVariable ["ASL_Actions_Loaded", false]; - }]; - }; + // player addEventHandler ["Respawn", { + // player setVariable ["ASL_Actions_Loaded", false]; + // }]; + // }; if (!isDedicated) then { ["Air", "init", {_this call ASL_Add_Vehicle_Actions}, true] call CBA_fnc_addClassEventHandler; // adds init event to all air vehicles; has to be run preinit! - [] spawn { - while {true} do { - if (!isNull player && isPlayer player) then { - if !(player getVariable ["ASL_Actions_Loaded", false]) then { - [] call ASL_Add_Player_Actions; - player setVariable ["ASL_Actions_Loaded", true]; - }; - }; - missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - sleep 2; - }; - }; + // [] spawn { + // while {true} do { + // if (!isNull player && isPlayer player) then { + // if !(player getVariable ["ASL_Actions_Loaded", false]) then { + // [] call ASL_Add_Player_Actions; + // player setVariable ["ASL_Actions_Loaded", true]; + // }; + // }; + // missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; + // sleep 2; + // }; + // }; }; ASL_RemoteExec = { @@ -1333,5 +1700,6 @@ if (isServer) then { if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // Passengers authorized to manipulate ropes if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes + if (isNil "ASL_RopePickupDistance") then {ASL_RopePickupDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/mod.cpp b/mod.cpp index 1e9ba65..26703ac 100644 --- a/mod.cpp +++ b/mod.cpp @@ -3,7 +3,7 @@ picture = "logo.paa"; description = "Advanced Sling Loading"; logo = "logo.paa"; logoOver = "logo.paa"; -tooltip = "Advanced Sling Loading v2.1.1b"; +tooltip = "Advanced Sling Loading v2.1.1c"; tooltipOwned = "Advanced Sling Loading Owned"; overview = "Advanced Sling Loading"; author = "[SA] Duda"; From 6591ba6332b99c064228137e260c5362edfd64da Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Mon, 29 Mar 2021 13:23:38 +0200 Subject: [PATCH 10/24] First local working iteration - removed all static actions from player - pickup, drop, attach actions are dynamic. They are added or removed to units/players dependent on distance to some rope end - all other actions are added to vehicle s - loads of bugfixes --- .../functions/fn_advancedSlingLoadingInit.sqf | 963 ++++++------------ .../scripts/XEH_preInit.sqf | 2 +- 2 files changed, 291 insertions(+), 674 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index b22eef7..b248e81 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -130,6 +130,39 @@ ASL_Advanced_Sling_Loading_Install = { _slingLoadPointsArray; }; + ASL_Get_Corner_Points = { + params ["_vehicle"]; + + // Correct width and length factor for air + private _widthFactor = 0.5; + private _lengthFactor = 0.5; + if (_vehicle isKindOf "Air") then { + _widthFactor = 0.3; + }; + if (_vehicle isKindOf "Helicopter") then { + _widthFactor = 0.2; + _lengthFactor = 0.45; + }; + + private _centerOfMass = getCenterOfMass _vehicle; + private _bbr = boundingBoxReal _vehicle; + private _p1 = _bbr select 0; + private _p2 = _bbr select 1; + private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; + private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; + private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _heightOffset = _maxHeight/6; + + private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + + [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; + }; + ASL_Rope_Set_Mass = { private _obj = [_this, 0] call BIS_fnc_param; private _mass = [_this, 1] call BIS_fnc_param; @@ -286,17 +319,6 @@ ASL_Advanced_Sling_Loading_Install = { [_selectedRopes, _selectedCargo]; }; - ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", format[localize "STR_ASL_ROPE"]]]; - ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; - { - ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; - } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0,1,2];"]], "1", "1"]; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; - }; - ASL_Extend_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -355,6 +377,17 @@ ASL_Advanced_Sling_Loading_Install = { }; }; + ASL_Show_Select_Ropes_Menu = { + params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", format[localize "STR_ASL_ROPE"]]]; + ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; + { + ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + } forEach _ropesIndexAndLabelArray; + ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0,1,2];"]], "1", "1"]; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; + }; + ASL_Extend_Ropes_Index_Action = { params ["_ropeIndex"]; private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; @@ -365,18 +398,16 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Extend_Ropes = { params ["_vehicle", "_player", ["_ropeIndex", 0]]; - if (local _vehicle) exitWith { - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; - if (count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= ASL_MaxRopeLength) then { - { - ropeUnwind [_x, 3, 5, true]; - } forEach _existingRopes; - }; + if !(local _vehicle) exitWith {[_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= ASL_MaxRopeLength) then { + { + ropeUnwind [_x, 3, 5, true]; + } forEach _existingRopes; }; }; - [_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec; }; ASL_Shorten_Ropes_Action_Check = { @@ -428,23 +459,21 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Shorten_Ropes = { params ["_vehicle", "_player", ["_ropeIndex", 0]]; - if (local _vehicle) exitWith { - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; - if (count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= 2) exitWith { - _this call ASL_Release_Cargo; - }; - { - if (_ropeLength >= 10) then { - ropeUnwind [_x, 3, -5, true]; - } else { - ropeUnwind [_x, 3, -1, true]; - }; - } forEach _existingRopes; - }; + if !(local _vehicle) exitWith {[_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + if (count _existingRopes > 0) then { + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= 2) exitWith { + _this call ASL_Release_Cargo; + }; + { + if (_ropeLength >= 10) then { + ropeUnwind [_x, 3, -5, true]; + } else { + ropeUnwind [_x, 3, -1, true]; + }; + } forEach _existingRopes; }; - [_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec; }; ASL_Release_Cargo_Action_Check = { @@ -489,7 +518,6 @@ ASL_Advanced_Sling_Loading_Install = { private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; if (count _activeRopes == 1) then { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo; - // [_vehicle, (_activeRopes select 0) select 0] call ASL_Release_Cargo; }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; @@ -506,21 +534,21 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Release_Cargo = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; + params ["_vehicle", "_unit", ["_ropeIndex", 0]]; // params ["_vehicle", ["_ropeIndex", 0]]; - if (local _vehicle) exitWith { - private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - { - _existingCargo ropeDetach _x; - } forEach _existingRopes; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [_ropeIndex, objNull]; - _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - _this call ASL_Retract_Ropes; - }; - [_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec; + if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; + private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + { + _existingCargo ropeDetach _x; + } forEach _existingRopes; + _existingCargo setVariable ["ASL_RopeEndHelper", nil, true]; + _existingCargo setVariable ["ASL_RopesIndex", nil, true]; + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [_ropeIndex, objNull]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + _this call ASL_Retract_Ropes; }; ASL_Retract_Ropes_Action_Check = { @@ -568,11 +596,9 @@ ASL_Advanced_Sling_Loading_Install = { params [["_vehicle", objNull], "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; - if !([_vehicle, _unit] call ASL_Can_Retract_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; if (count _activeRopes == 1) then { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; - // [_vehicle, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; }; if (count _activeRopes > 1) then { _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; @@ -581,36 +607,43 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Retract_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; - // params ["_vehicle", ["_ropeIndex", 0]]; - if (local _vehicle) exitWith { - private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; - if (isNull _existingCargo) then { - _this call ASL_Drop_Ropes; - { - [_x] spawn { - params ["_rope"]; - private _count = 0; - ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; - }; - ropeDestroy _rope; - }; - } forEach _existingRopes; - private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - _allRopes set [_ropeIndex, []]; - _vehicle setVariable ["ASL_Ropes", _allRopes, true]; - }; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 0) then { - _vehicle setVariable ["ASL_Ropes", nil, true]; + params ["_vehicle", "_unit", ["_ropeIndex", 0]]; + if !(local _vehicle) exitWith {[_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec}; + private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopes = _existingRopesAndCargo select 0; + private _existingCargo = _existingRopesAndCargo select 1; + private _cargoArray = ropeAttachedObjects _vehicle; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _vehicle: ", _vehicle, " _cargoArray: ", _cargoArray]; + if (count _cargoArray > 0) then { + private _helper = (_cargoArray select {_x getVariable ["ASL_Ropes_Pick_Up_Helper", false]}) select 0; + if (!isNull _helper) then { + private _ropeHolder = attachedTo _helper; + if (!isNull _ropeHolder) then {_unit = _ropeHolder}; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _helper: ", _helper, " _ropeHolder: ", _ropeHolder]; }; }; - [_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec; + if (isNull _existingCargo) then { + [_vehicle, _unit, _ropeIndex] call ASL_Drop_Ropes; + { + [_x] spawn { + params ["_rope"]; + private _count = 0; + ropeUnwind [_rope, 3, 0]; + while {(!ropeUnwound _rope) && _count < 20} do { + sleep 1; + _count = _count + 1; + }; + ropeDestroy _rope; + }; + } forEach _existingRopes; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + _allRopes set [_ropeIndex, []]; + _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + }; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + if (count _activeRopes == 0) then { + _vehicle setVariable ["ASL_Ropes", nil, true]; + }; }; ASL_Retract_Ropes_Index_Action = { @@ -618,25 +651,6 @@ ASL_Advanced_Sling_Loading_Install = { private _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { [_vehicle, player, _ropesIndex] call ASL_Retract_Ropes; - // [_vehicle, _ropesIndex] call ASL_Retract_Ropes; - }; - }; - - ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - // if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; - }; - }; - - ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; - private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - // if (_count > 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - if (_count > 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _count] call ASL_Deploy_Ropes; }; }; @@ -680,7 +694,6 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 2"]; false }; - // private _existingVehicle = player getVariable ["ASL_Ropes_Vehicle", []]; private _existingVehicle = _unit getVariable ["ASL_Ropes_Vehicle", []]; if (count _existingVehicle > 0) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 3"]; @@ -706,8 +719,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Deploy_Ropes_Action = { - params [["_vehicle", objNull]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; + params [["_vehicle", objNull], "_unit"]; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; if (isNull _vehicle) exitWith {false}; if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; @@ -716,15 +729,15 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _inactiveRopes: ", _inactiveRopes]; if (count _inactiveRopes > 0) then { if (count _inactiveRopes > 1) then { - player setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; + _unit setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; } else { - [_vehicle, player, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + [_vehicle, _unit, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; }; } else { private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; if (count _slingLoadPoints > 1) then { - player setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + _unit setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; ASL_Deploy_Ropes_Count_Menu = [ [format[localize "STR_ASL_ROPES"], false] ]; @@ -738,55 +751,41 @@ ASL_Advanced_Sling_Loading_Install = { showCommandingMenu ""; showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; } else { - [_vehicle, player] call ASL_Deploy_Ropes; + [_vehicle, _unit] call ASL_Deploy_Ropes; }; }; }; - // ASL_Deploy_Ropes = { - // params ["_vehicle", "_player", ["_cargoCount", 1]]; - // if (local _vehicle) exitWith { - // private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - // private _existingRopes = _vehicle getVariable ["ASL_Ropes",[]]; - // if (count _existingRopes == 0) then { - // if (count _slingLoadPoints == 0) exitWith { - // [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; - // }; - // if (count _slingLoadPoints < _cargoCount) exitWith { - // [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _player] call ASL_RemoteExec; - // }; - // private _cargoRopes = []; - // private _cargo = []; - // for "_i" from 0 to (_cargoCount-1) do { - // _cargoRopes pushBack []; - // _cargo pushBack objNull; - // }; - // _vehicle setVariable ["ASL_Ropes", _cargoRopes, true]; - // _vehicle setVariable ["ASL_Cargo", _cargo, true]; - // for "_i" from 0 to (_cargoCount-1) do - // { - // [_vehicle, _player, _i] call ASL_Deploy_Ropes_Index; - // }; - // } else { - // [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _player] call ASL_RemoteExec; - // }; - // }; - // [_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec; - // }; + ASL_Deploy_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + // if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; + }; + }; + + ASL_Deploy_Ropes_Count_Action = { + params ["_count"]; + private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + if (_count > 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { + [_vehicle, player, _count] call ASL_Deploy_Ropes; + }; + }; ASL_Deploy_Ropes = { params ["_vehicle", "_unit", ["_cargoCount", 1]]; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _existingRopes > 0 && _unit == player) exitWith { - [[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + if (count _existingRopes > 0) exitWith { + if (_unit == player) then {[[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; }; private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if (count _slingLoadPoints == 0 && _unit == player) exitWith { - [[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + if (count _slingLoadPoints == 0) exitWith { + if (_unit == player) then {[[format[localize "STR_ASL_DOESNT_SUPPORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; }; - if (count _slingLoadPoints < _cargoCount && _unit == player) exitWith { - [[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _unit] call ASL_RemoteExec; + if (count _slingLoadPoints < _cargoCount) exitWith { + if (_unit == player) then {[[format[localize "STR_ASL_DOESNT_SUPPORT_X", _cargoCount], false], "ASL_Hint", _unit] call ASL_RemoteExec}; }; private _cargoRopes = []; private _cargo = []; @@ -801,29 +800,6 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - // ASL_Deploy_Ropes_Index = { - // params ["_vehicle", "_player", ["_ropesIndex", 0], ["_ropeLength", 15]]; - // if (local _vehicle) exitWith { - // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - // if (count _existingRopes == 0) then { - // private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - // private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; - // private _cargoRopes = []; - // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - // { - // ropeUnwind [_x, 5, _ropeLength]; - // } forEach _cargoRopes; - // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - // _allRopes set [_ropesIndex, _cargoRopes]; - // _vehicle setVariable ["ASL_Ropes", _allRopes, true]; - // }; - // }; - // [_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec; - // }; - ASL_Deploy_Ropes_Index = { params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_ropeLength", 15]]; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec}; @@ -832,188 +808,138 @@ ASL_Advanced_Sling_Loading_Install = { private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; private _cargoRopes = []; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; - private ["_helper"]; - private _helperArray = []; + for "_i" from 1 to 4 do { + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + }; { - // _helper = createVehicle ["ASL_RopeSmallWeight", (ropeEndPosition _x) select 1, [], 0, "CAN_COLLIDE"]; - // _helper setMass 0.1; - // _helper allowDamage false; - // [_helper, [0, 0, 0], [0, 0, 0]] ropeAttachTo _x; - // _helper setVariable ["ASL_RopeEndHelper", true, true]; - // _helper setVariable ["ASL_RopesIndex", _ropesIndex, true]; - - - // Once helper is attached to a rope end, it begins searchching for unit in pickup range. - // Only if a unit is then found, the unit will get the 'pickup ropes' action. - // [_helper] spawn ASL_Add_Pickup_Action; - _helper = [_x, _ropesIndex] call ASL_Create_Rope_End_Helper; - _helperArray pushBack _helper; + _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope ropeUnwind [_x, 5, _ropeLength]; } forEach _cargoRopes; - { - _x setVariable ["ASL_RopesHelperArray", _helperArray, true]; - } forEach _helperArray; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; _allRopes set [_ropesIndex, _cargoRopes]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; + [_vehicle] spawn ASL_Rope_Monitor_Vehicle; }; - ASL_Create_Rope_End_Helper = { - params ["_rope", "_ropesIndex"]; - private _helper = createVehicle ["ASL_RopeSmallWeight", (ropeEndPosition _rope) select 1, [], 0, "CAN_COLLIDE"]; - _helper setMass 0.1; - _helper allowDamage false; - [_helper, [0, 0, 0], [0, 0, 0]] ropeAttachTo _rope; - _helper setVariable ["ASL_RopeEndHelper", true, true]; - _helper setVariable ["ASL_RopesIndex", _ropesIndex, true]; - [_helper] spawn ASL_Add_Pickup_Action; - }; - - ASL_Add_Pickup_Action = { - params [["_object", objNull]]; - if (isNull _object) exitWith {}; - while {alive _object} do { - private _nearbyUnits = (_object nearObjects (ASL_RopePickupDistance)) select {_x isKindOf "CAManBase" && side _x == side player && vehicle _x == _x}; - // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Add_Pickup_Action) _nearbyUnits: ", _nearbyUnits]; + ASL_Rope_Monitor_Vehicle = { + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; + if (_vehicle getVariable ["ASL_Vehicle_Rope_Monitor", false]) exitWith {}; // leave, if vehicle is already monitoring rope ends + _vehicle setVariable ["ASL_Vehicle_Rope_Monitor", true, true]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _vehicle: ", _vehicle, ", started rope end monitoring"]; + private ["_allRopes", "_ropeBundle", "_rope", "_nearbyUnits", "_unitRopes"]; + while {alive _vehicle && !(isNil{_vehicle getVariable "ASL_Ropes"})} do { + _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _allRopes: ", _allRopes]; { - if (isNil{_x getVariable "ASL_ActionID_Pickup"}) then { - private _actionID = _x addAction [ - format[localize "STR_ASL_PICKUP"], // Title - {[_this select 0] call ASL_Pickup_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_this] call ASL_Pickup_Ropes_Action_Check" // Condition - ]; - _x setVariable ["ASL_ActionID_Pickup", _actionID]; - }; - } forEach _nearbyUnits; - sleep 0.5; + _ropeBundle = _x; + { + _rope = _x; + _nearbyUnits = ((ropeEndPosition _rope select 1) nearObjects (ASL_RopeHandlingDistance + 10)) select {_x isKindOf "CAManBase" && side _x == side player && vehicle _x == _x}; + // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Monitor_Vehicle) _nearbyUnits: ", _nearbyUnits]; + { + _unitRopes = _x getVariable ["ASL_Ropes_Near_Unit", []]; + if (_unitRopes find _rope == -1) then { + _unitRopes pushBack _rope; + _x setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; + }; + // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Monitor_Vehicle) unit: ", _x, ", _unitRopes: ", _unitRopes]; + [_x] spawn ASL_Rope_Monitor_Unit; + } forEach _nearbyUnits; + } forEach _ropeBundle; + } forEach _allRopes; + sleep 1; }; + _vehicle setVariable ["ASL_Vehicle_Rope_Monitor", nil, true]; }; - ASL_Get_Corner_Points = { - params ["_vehicle"]; - - // Correct width and length factor for air - private _widthFactor = 0.5; - private _lengthFactor = 0.5; - if (_vehicle isKindOf "Air") then { - _widthFactor = 0.3; - }; - if (_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; + ASL_Rope_Monitor_Unit = { + params [["_unit", objNull]]; + if (isNull _unit) exitWith {}; + if (_unit getVariable ["ASL_Unit_Rope_Monitor", false]) exitWith {}; // leave, if unit is already monitoring ror rope ends + _unit setVariable ["ASL_Unit_Rope_Monitor", true]; // raise unit rope monitor flag + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; + if (isNil{_unit getVariable "ASL_ActionID_Pickup"}) then { // add pickup action to unit + private _actionID = _unit addAction [ + format[localize "STR_ASL_PICKUP"], // Title + {[_this select 0] call ASL_Pickup_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Pickup_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_Pickup", _actionID]; + }; + private ["_unitRopes", "_index"]; + while {alive _unit && (count(_unit getVariable ["ASL_Ropes_Near_Unit", []]) > 0)} do { + _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unitRopes: ", _unitRopes]; + // hintSilent formatText ["%1%2%3%4%5%6%7", "unit: ", _unit, lineBreak, "Ropes: ", lineBreak, _unitRopes]; + if (objNull in _unitRopes) then { + _unitRopes = _unitRopes - [objNull]; + _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; + }; + { + if (!alive _x || (_unit distance (ropeEndPosition _x select 1) > (ASL_RopeHandlingDistance + 15) && _unitRopes find _x != -1)) then { + _index = _unitRopes find _x; + if (_index == -1) exitWith {}; + _unitRopes deleteAt _index; + _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; + }; + } forEach _unitRopes; + sleep 0.1; }; - - private _centerOfMass = getCenterOfMass _vehicle; - private _bbr = boundingBoxReal _vehicle; - private _p1 = _bbr select 0; - private _p2 = _bbr select 1; - private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; - private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; - private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - private _heightOffset = _maxHeight/6; - - private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - - [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; + [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Actions; // if no rope ends near, remove pickup action from unit + _unit setVariable ["ASL_Ropes_Near_Unit", nil]; // annil unit rope array + _unit setVariable ["ASL_Unit_Rope_Monitor", nil]; // annil unit rope monitor flag }; - // ASL_Pickup_Ropes_Action_Check = { - // [] call ASL_Can_Pickup_Ropes; - // }; - - // ASL_Can_Pickup_Ropes = { - // count (player getVariable ["ASL_Ropes_Vehicle", []]) == 0 && count (missionNamespace getVariable ["ASL_Nearby_Vehicles",[]]) > 0 && vehicle player == player; - // }; - ASL_Pickup_Ropes_Action_Check = { params [["_unit", objNull]]; + if (isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _target: ", _target, ", _this: ", _this]; // hintSilent formatText ["%1%2%3%4%5%6", time, "s (ASL_Pickup_Ropes_Action_Check) _unit: ", _unit, lineBreak, "rope ends found: ", count ((_unit nearObjects 5) select {_x getVariable ["ASL_RopeEndHelper", false]})]; - if (count ((_unit nearObjects ASL_RopePickupDistance) select {_x getVariable ["ASL_RopeEndHelper", false]}) > 0 && vehicle _unit == _unit) exitWith {true}; - [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Unit_Actions; // if no rope helper objects near, remove pickup action from unit - false + if (vehicle _unit != _unit) exitWith {false}; + if !(isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}) exitWith {false}; + private _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; + if (objNull in _unitRopes) then { + _unitRopes = _unitRopes - [objNull]; + _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; + }; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _unitRopes: ", _unitRopes]; + private _pickup = false; + { + if (alive _x && (_unit distance (ropeEndPosition _x select 1) < ASL_RopeHandlingDistance)) exitWith {_pickup = true}; + } forEach _unitRopes; + _pickup }; - - // ASL_Pickup_Ropes_Action = { - // // private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; - // if ([] call ASL_Can_Pickup_Ropes) then { - // private _closestRope = [] call ASL_Get_Closest_Rope; - // if (!isNull (_closestRope select 0)) then { - // private _canPickupRopes = true; - // if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - // if (locked (_closestRope select 0) > 1) then { - // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; - // _canPickupRopes = false; - // }; - // }; - // if (_canPickupRopes) then { - // [(_closestRope select 0), player, (_closestRope select 1)] call ASL_Pickup_Ropes; - // }; - // }; - // }; - // }; - + ASL_Pickup_Ropes_Action = { params [["_unit", objNull]]; - private _ropeEnds = (nearestObjects [_unit, [], ASL_RopePickupDistance]) select {_x getVariable ["ASL_RopeEndHelper", false]}; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _unit: ", _unit, lineBreak, "rope ends 1: ", count _ropeEnds1, lineBreak, "rope ends: ", count _ropeEnds]; - private _closestRopeEnd = _ropeEnds select 0; - if (isNull _closestRopeEnd) exitWith {}; - private _helperArray = _closestRopeEnd getVariable ["ASL_RopesHelperArray", []]; - private _ropesIndex = _closestRopeEnd getVariable "ASL_RopesIndex"; - private _vehicle = ropeAttachedTo _closestRopeEnd; - diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _helperArray: ", _helperArray, "_vehicle: ", _vehicle, "_ropesIndex: ", _ropesIndex]; + if (isNull _unit) exitWith {}; + private _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; + // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; + private _closestRope = objNull; + private _closestDistance = ASL_RopeHandlingDistance + 100; + { + _distance = _unit distance (ropeEndPosition _x select 1); + if (_x != objNull && _distance < ASL_RopeHandlingDistance && _distance < _closestDistance) then { + _closestRope = _x; + }; + } forEach _unitRopes; + if (isNull _closestRope) exitWith {}; + private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") select 0; if (isNull _vehicle) exitWith {}; if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; }; - { - deleteVehicle _x; - } forEach _helperArray; // once we got all relevant info, we no longer need the helpers + private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") select 1; [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; }; - // ASL_Pickup_Ropes = { - // params ["_vehicle", "_player", ["_ropesIndex", 0]]; - // if (local _vehicle) exitWith { - // private _existingRopesAndCargo = [_vehicle,_ropesIndex] call ASL_Get_Ropes_And_Cargo; - // private _existingRopes = _existingRopesAndCargo select 0; - // private _existingCargo = _existingRopesAndCargo select 1; - // if (!isNull _existingCargo) then { - // { - // _existingCargo ropeDetach _x; - // } forEach _existingRopes; - // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - // _allCargo set [_ropesIndex, objNull]; - // _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - // }; - // private _helper = "Land_Can_V2_F" createVehicle position _player; - // { - // [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; - // _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; - // } forEach _existingRopes; - // hideObject _helper; - // [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; - // _player setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; - // _player setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - // }; - // [_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec; - // }; - ASL_Pickup_Ropes = { params ["_vehicle", "_unit", ["_ropesIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; @@ -1029,16 +955,14 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable ["ASL_Cargo", _allCargo, true]; }; private _helper = "Land_Can_V2_F" createVehicle position _unit; + _helper setVariable ["ASL_Ropes_Pick_Up_Helper", true, true]; { [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; _helper attachTo [_unit, [-0.1, 0.1, 0.15], "Pelvis"]; } forEach _existingRopes; hideObjectGlobal _helper; - // [[_helper], "ASL_Hide_Object_Global"] call ASL_RemoteExecServer; _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - - [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Unit_Actions; // remove pickup action, once unit has picked up some ropes private ["_actionID"]; if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { @@ -1070,83 +994,14 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - - - - - - - - - - - - - - - - - - // ASL_Attach_Ropes_Action_Check = { - // private _vehicleWithIndex = player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - // private _cargo = cursorTarget; - // [_vehicleWithIndex select 0, _cargo] call ASL_Can_Attach_Ropes; - // }; - ASL_Attach_Ropes_Action_Check = { params [["_unit", objNull]]; if (isNull _unit) exitWith {false}; - private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; private _cargo = cursorTarget; - [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < 10 && _vehicle != _cargo; + private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; }; - // ASL_Can_Attach_Ropes = { - // params ["_vehicle", "_cargo", ["_unit", player]]; - // if (isNull _vehicle || isNull _cargo) exitWith {false}; - // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < 10 && _vehicle != _cargo; - // }; - - // ASL_Can_Attach_Ropes = { - // params ["_vehicle", "_cargo"]; - // if (!isNull _vehicle && !isNull _cargo) then { - // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; - // } else { - // false; - // }; - // }; - - // ASL_Attach_Ropes_Action = { - // private _cargo = cursorTarget; - // private _vehicle = (player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; - // if ([_vehicle, _cargo] call ASL_Can_Attach_Ropes) then { - // // private _canBeAttached = true; - // // if !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false]) then { - // // if (locked _cargo > 1) then { - // // [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; - // // _canBeAttached = false; - // // }; - // // }; - // if (locked _cargo > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { - // [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; - // }; - - // private _canBeAttached = true; - // if !(missionNamespace getVariable ["ASL_EXILE_SAFEZONE_ENABLED", false]) then { - // if (!isNil "ExilePlayerInSafezone") then { - // if (ExilePlayerInSafezone) then { - // [format[localize "STR_ASL_CANT_SAFE"], false] call ASL_Hint; - // _canBeAttached = false; - // }; - // }; - // }; - - // if (_canBeAttached) then { - // [_cargo, player] call ASL_Attach_Ropes; - // }; - // }; - // }; - ASL_Attach_Ropes_Action = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; @@ -1169,39 +1024,6 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - // ASL_Attach_Ropes = { - // params ["_cargo", "_player"]; - // private _vehicleWithIndex = _player getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - // private _vehicle = _vehicleWithIndex select 0; - // if (!isNull _vehicle) then { - // if (local _vehicle) then { - // private _ropes = [_vehicle,(_vehicleWithIndex select 1)] call ASL_Get_Ropes; - // if (count _ropes == 4) then { - // private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - // private _ropeLength = (ropeLength (_ropes select 0)); - // private _objDistance = (_cargo distance _vehicle) + 2; - // if (_objDistance > _ropeLength) then { - // [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _player] call ASL_RemoteExec; - // } else { - // [_vehicle, _player] call ASL_Drop_Ropes; - // [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); - // [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); - // [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); - // [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); - // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - // _allCargo set [(_vehicleWithIndex select 1),_cargo]; - // _vehicle setVariable ["ASL_Cargo",_allCargo, true]; - // if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED",true]) then { - // [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; - // }; - // }; - // }; - // } else { - // [_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec; - // }; - // }; - // }; - ASL_Attach_Ropes = { params ["_cargo", ["_unit", objNull]]; private _vehicleWithIndex = _unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; @@ -1216,64 +1038,23 @@ ASL_Advanced_Sling_Loading_Install = { if (_objDistance > _ropeLength) then { [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; } else { - _cargo setVariable ["ASL_RopeEndHelper", true, true]; private _ropesIndex = _vehicleWithIndex select 1; - _cargo setVariable ["ASL_RopesIndex", _ropesIndex, true]; - - + _cargo setVariable ["ASL_RopesIndex", _ropesIndex, true]; [_vehicle, _unit] call ASL_Drop_Ropes; - [_cargo, _attachmentPoints select 0, [0, 0, -1]] ropeAttachTo (_ropes select 0); - [_cargo, _attachmentPoints select 1, [0, 0, -1]] ropeAttachTo (_ropes select 1); - [_cargo, _attachmentPoints select 2, [0, 0, -1]] ropeAttachTo (_ropes select 2); - [_cargo, _attachmentPoints select 3, [0, 0, -1]] ropeAttachTo (_ropes select 3); + for "_i" from 0 to 3 do { + [_cargo, _attachmentPoints select _i, [0, 0, -1]] ropeAttachTo (_ropes select _i); + }; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [(_vehicleWithIndex select 1), _cargo]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; }; - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Unit_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo - [_cargo] spawn ASL_Add_Pickup_Action; - }; - }; - // ASL_Pickup_Ropes_Action = { - // params [["_unit", objNull]]; - // private _ropeEnds = (nearestObjects [_unit, [], ASL_RopePickupDistance]) select {_x getVariable ["ASL_RopeEndHelper", false]}; - // // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _unit: ", _unit, lineBreak, "rope ends 1: ", count _ropeEnds1, lineBreak, "rope ends: ", count _ropeEnds]; - // private _closestRopeEnd = _ropeEnds select 0; - // if (isNull _closestRopeEnd) exitWith {}; - // private _helperArray = _closestRopeEnd getVariable ["ASL_RopesHelperArray", []]; - // private _ropesIndex = _closestRopeEnd getVariable "ASL_RopesIndex"; - // private _vehicle = ropeAttachedTo _closestRopeEnd; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Pickup_Ropes_Action) _helperArray: ", _helperArray, lineBreak, "_vehicle: ", _vehicle]; - // if (isNull _vehicle) exitWith {}; - // if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { - // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; - // }; - // { - // deleteVehicle _x; - // } forEach _helperArray; // once we got all relevant info, we no longer need the helpers - // [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; - // }; - - - - - - - - - - - - - // ASL_Drop_Ropes_Action_Check = { - // [] call ASL_Can_Drop_Ropes; - // }; - - // ASL_Can_Drop_Ropes = { - // count (player getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle player == player; - // }; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; + }; + }; ASL_Drop_Ropes_Action_Check = { params [["_unit", objNull]]; @@ -1281,93 +1062,32 @@ ASL_Advanced_Sling_Loading_Install = { count (_unit getVariable ["ASL_Ropes_Vehicle", []]) > 0 && vehicle _unit == _unit; }; - // ASL_Drop_Ropes_Action = { - // if ([] call ASL_Can_Drop_Ropes) then { - // private _vehicleAndIndex = player getVariable ["ASL_Ropes_Vehicle", []]; - // if (count _vehicleAndIndex == 2) then { - // [_vehicleAndIndex select 0, player, _vehicleAndIndex select 1] call ASL_Drop_Ropes; - // }; - // }; - // }; - ASL_Drop_Ropes_Action = { params [["_unit", objNull]]; if (isNull _unit) exitWith {false}; private _vehicleAndIndex = _unit getVariable ["ASL_Ropes_Vehicle", []]; if (count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, _unit, _vehicleAndIndex select 1, true] call ASL_Drop_Ropes; + [_vehicleAndIndex select 0, _unit, _vehicleAndIndex select 1] call ASL_Drop_Ropes; }; }; - // ASL_Drop_Ropes = { - // params ["_vehicle", "_player", ["_ropesIndex", 0]]; - // if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; - // private _helper = (_player getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - // if (!isNull _helper) then { - // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - // { - // _helper ropeDetach _x; - // } forEach _existingRopes; - // detach _helper; - // deleteVehicle _helper; - // }; - // _player setVariable ["ASL_Ropes_Vehicle", nil, true]; - // _player setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; - // }; - ASL_Drop_Ropes = { - params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_createHelper", false]]; + params ["_vehicle", "_unit", ["_ropesIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); if (!isNull _helper) then { private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; - private _helperArray = []; { _helper ropeDetach _x; - if (_createHelper) then { - _endHelper = [_x, _ropesIndex] call ASL_Create_Rope_End_Helper; - _helperArray pushBack _endHelper; - }; } forEach _existingRopes; detach _helper; - deleteVehicle _helper; + deleteVehicle _helper; }; - { - _x setVariable ["ASL_RopesHelperArray", _helperArray, true]; - } forEach _helperArray; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; - - ASL_Get_Closest_Rope = { - private _nearbyVehicles = missionNamespace getVariable ["ASL_Nearby_Vehicles", []]; - private _closestVehicle = objNull; - private _closestRopeIndex = 0; - private _closestDistance = -1; - private ["_vehicle", "_activeRope", "_ropes", "_ends", "_end1", "_end2", "_minEndDistance"]; - { - _vehicle = _x; - { - _activeRope = _x; - _ropes = [_vehicle, (_activeRope select 0)] call ASL_Get_Ropes; - { - _ends = ropeEndPosition _x; - if (count _ends == 2) then { - _end1 = _ends select 0; - _end2 = _ends select 1; - _minEndDistance = ((position player) distance _end1) min ((position player) distance _end2); - if (_closestDistance == -1 || _closestDistance > _minEndDistance) then { - _closestDistance = _minEndDistance; - _closestRopeIndex = (_activeRope select 0); - _closestVehicle = _vehicle; - }; - }; - } forEach _ropes; - } forEach ([_vehicle] call ASL_Get_Active_Ropes); - } forEach _nearbyVehicles; - [_closestVehicle, _closestRopeIndex]; - }; - + ASL_SUPPORTED_VEHICLES = [ "Helicopter", "VTOL_Base_F" @@ -1398,25 +1118,6 @@ ASL_Advanced_Sling_Loading_Install = { _canSling }; - // ASL_Is_Supported_Cargo = { - // params ["_vehicle", "_cargo"]; - // private _canSling = false; - // if (not isNull _vehicle && not isNull _cargo) then { - // { - // if (_vehicle isKindOf (_x select 0)) then { - // if (_cargo isKindOf (_x select 2)) then { - // if ((toUpper (_x select 1)) == "CAN_SLING") then { - // _canSling = true; - // } else { - // _canSling = false; - // }; - // }; - // }; - // } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); - // }; - // _canSling; - // }; - ASL_Hint = { params ["_msg", ["_isSuccess", true]]; if (!isNil "ExileClient_gui_notification_event_addNotification") then { @@ -1429,87 +1130,38 @@ ASL_Advanced_Sling_Loading_Install = { hint _msg; }; }; - - ASL_Hide_Object_Global = { - params ["_obj"]; - if (_obj isKindOf "Land_Can_V2_F") then { - hideObjectGlobal _obj; - }; + + ASL_Switch_Vehicles_Actions = { + { + [_x] call ASL_Add_Vehicle_Actions; + } foreach vehicles; }; - - // ASL_Find_Nearby_Vehicles = { - // private _nearVehicles = []; - // { - // _nearVehicles append (player nearObjects [_x, 30]); - // } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); - // private _nearVehiclesWithRopes = []; - // private ["_vehicle", "_ropes", "_ends", "_end1", "_end2", "_playerPosAGL"]; - // { - // _vehicle = _x; - // { - // _ropes = _vehicle getVariable ["ASL_Ropes",[]]; - // if (count _ropes > (_x select 0)) then { - // _ropes = _ropes select (_x select 0); - // { - // _ends = ropeEndPosition _x; - // if (count _ends == 2) then { - // _end1 = _ends select 0; - // _end2 = _ends select 1; - // _playerPosAGL = ASLtoAGL getPosASL player; - // if ((_playerPosAGL distance _end1) < 5 || (_playerPosAGL distance _end2) < 5) then { - // _nearVehiclesWithRopes = _nearVehiclesWithRopes + [_vehicle]; - // } - // }; - // } forEach _ropes; - // }; - // } forEach ([_vehicle] call ASL_Get_Active_Ropes); - // } forEach _nearVehicles; - // _nearVehiclesWithRopes; - // }; - - // ASL_Switch_Vehicle_Actions = { - // { - // if (_x isKindOf "Air") then {[_x] call ASL_Add_Vehicle_Actions}; - // } forEach vehicles; - // }; - + ASL_Add_Vehicle_Actions = { params ["_vehicle"]; private _exit = true; { if (_vehicle isKindOf _x && getMass _vehicle > ASL_MinVehicleMass) exitWith {_exit = false}; } foreach ASL_SUPPORTED_VEHICLES; - private ["_actionID"]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Add_Vehicle_Actions) _vehicle: ", _vehicle, ", mass: ", getMass _vehicle, ", min: ", ASL_MinVehicleMass]; if (_exit) exitWith { - private _actions = [ - "ASL_ActionID_Deploy", - "ASL_ActionID_Retract", - "ASL_ActionID_Extend", - "ASL_ActionID_Shorten", - "ASL_ActionID_Release" - ]; - { - _actionID = _vehicle getVariable _x; - if (isNil{_actionID}) exitWith {}; - _vehicle removeAction _actionID; - _vehicle setVariable [_x, nil]; - } forEach _actions; + [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release"]] call ASL_Remove_Actions; }; + private ["_actionID"]; if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_DEPLOY"], // Title - {[_this select 0] call ASL_Deploy_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Deploy_Ropes_Action_Check" // Condition + format[localize "STR_ASL_DEPLOY"], // Title + {[_this select 0, _this select 1] call ASL_Deploy_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Deploy_Ropes_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Deploy", _actionID]; }; - if (isNil{_vehicle getVariable "ASL_ActionID_Retract"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_RETRACT"], // Title @@ -1523,7 +1175,6 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Retract", _actionID]; }; - if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_EXTEND"], // Title @@ -1537,7 +1188,6 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Extend", _actionID]; }; - if (isNil{_vehicle getVariable "ASL_ActionID_Shorten"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_SHORTEN"], // Title @@ -1551,7 +1201,6 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Shorten", _actionID]; }; - if (isNil{_vehicle getVariable "ASL_ActionID_Release"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_RELEASE"], // Title @@ -1567,51 +1216,22 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - ASL_Remove_Unit_Actions = { - params [["_unit", objNull], ["_actions", []]]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Unit_Actions) _unit: ", _unit, " _actions: ", _actions]; - if (isNull _unit) exitWith {false}; + ASL_Remove_Actions = { + params [["_object", objNull], ["_actions", []]]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; + if (isNull _object) exitWith {false}; + private ["_actionID"]; { - private _actionID = _unit getVariable _x; + _actionID = _object getVariable _x; if !(isNil{_actionID}) then { - _unit removeAction _actionID; - _unit setVariable [_x, nil]; + _object removeAction _actionID; + _object setVariable [_x, nil]; }; } forEach _actions; }; - // ASL_Add_Player_Actions = { - // player addAction [format[localize "STR_ASL_PICKUP"], { - // [] call ASL_Pickup_Ropes_Action; - // }, nil, 0, false, true, "", "call ASL_Pickup_Ropes_Action_Check"]; - - // player addAction [format[localize "STR_ASL_DROP"], { - // [] call ASL_Drop_Ropes_Action; - // }, nil, 0, false, true, "", "call ASL_Drop_Ropes_Action_Check"]; - - // player addAction [format[localize "STR_ASL_ATTACH"], { - // [] call ASL_Attach_Ropes_Action; - // }, nil, 0, false, true, "", "call ASL_Attach_Ropes_Action_Check"]; - - // player addEventHandler ["Respawn", { - // player setVariable ["ASL_Actions_Loaded", false]; - // }]; - // }; - if (!isDedicated) then { ["Air", "init", {_this call ASL_Add_Vehicle_Actions}, true] call CBA_fnc_addClassEventHandler; // adds init event to all air vehicles; has to be run preinit! - // [] spawn { - // while {true} do { - // if (!isNull player && isPlayer player) then { - // if !(player getVariable ["ASL_Actions_Loaded", false]) then { - // [] call ASL_Add_Player_Actions; - // player setVariable ["ASL_Actions_Loaded", true]; - // }; - // }; - // missionNamespace setVariable ["ASL_Nearby_Vehicles", (call ASL_Find_Nearby_Vehicles)]; - // sleep 2; - // }; - // }; }; ASL_RemoteExec = { @@ -1641,10 +1261,7 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isServer) then { - - // Adds support for exile network calls (Only used when running exile) - ASL_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["ASL_Hide_Object_Global"]; - + ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { params ["_sessionId", "_messageParameters", ["_isCall", false]]; _messageParameters params ["_params", "_functionName"]; @@ -1700,6 +1317,6 @@ if (isServer) then { if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // Passengers authorized to manipulate ropes if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes - if (isNil "ASL_RopePickupDistance") then {ASL_RopePickupDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope + if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 861830e..07cbe3a 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -68,5 +68,5 @@ format[localize "STR_ASL_TITLE"], [0, 2000, 0, 0], true, - {[] call ASL_Switch_Vehicle_Actions;} // code executed on option changed AND on init + {[] call ASL_Switch_Vehicles_Actions} // code executed on option changed AND on init ] call CBA_fnc_addSetting; \ No newline at end of file From f55897e6c4a5f246b954cdc479aeda8c4695fe49 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Wed, 31 Mar 2021 16:49:54 +0200 Subject: [PATCH 11/24] 'v1.0' all major changes complete - added more CBA options - replaced player by variable - renamed mod with my tag -> untested: Multiplayer! --- .../functions/fn_advancedSlingLoadingInit.sqf | 196 ++++++++++-------- .../scripts/XEH_preInit.sqf | 18 ++ .../NIC_AdvancedSlingLoading/stringtable.xml | 44 +++- mod.cpp | 12 +- 4 files changed, 163 insertions(+), 107 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index b248e81..0fb3e1a 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -55,7 +55,6 @@ ASL_Advanced_Sling_Loading_Install = { private _slingLoadPointHeightOffset = 0; { - // if (_vehicle isKindOf (_x select 0)) then { if (_vehicle isKindOf (_x select 0)) exitWith { _slingLoadPointHeightOffset = (_x select 1); }; @@ -153,12 +152,12 @@ ASL_Advanced_Sling_Loading_Install = { private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - private _heightOffset = _maxHeight/6; + private _heightOffset = _maxHeight / 6; - private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; - private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2)+_heightOffset]; + private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; @@ -368,13 +367,12 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Extend_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 1) then { - [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; + if (count _activeRopes == 1) exitWith { + [_vehicle, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; }; - if (count _activeRopes > 1) then { - _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - }; + _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; + ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself + [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; ASL_Show_Select_Ropes_Menu = { @@ -383,28 +381,34 @@ ASL_Advanced_Sling_Loading_Install = { { ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0,1,2];"]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0, 1, 2];"]], "1", "1"]; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; }; ASL_Extend_Ropes_Index_Action = { params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Extend_Index_Vehicle", objNull]; + private _unit = ASL_ParamMenuUnit; + // ASL_ParamMenuUnit = nil; + private _vehicle = _unit getVariable ["ASL_Extend_Index_Vehicle", objNull]; if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Extend_Ropes; + [_vehicle, _ropeIndex] call ASL_Extend_Ropes; }; }; ASL_Extend_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; + params ["_vehicle", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; if (count _existingRopes > 0) then { private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= ASL_MaxRopeLength) then { + if (_ropeLength < ASL_MaxRopeLength) then { + private _unwindLength = ASL_ExtendShortenRopeLength; + if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { + _unwindLength = ASL_MaxRopeLength - _ropeLength; + }; { - ropeUnwind [_x, 3, 5, true]; + ropeUnwind [_x, 3, _unwindLength, true]; } forEach _existingRopes; }; }; @@ -433,32 +437,32 @@ ASL_Advanced_Sling_Loading_Install = { if (count _activeRopes == 0) exitWith {false}; true }; - + ASL_Shorten_Ropes_Action = { params [["_vehicle", objNull], "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 1) then { - [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + if (count _activeRopes == 1) exitWith { + [_vehicle, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; }; - if (count _activeRopes > 1) then { - _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - }; + _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; + ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself + [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; ASL_Shorten_Ropes_Index_Action = { params ["_ropeIndex"]; - private _vehicle = player getVariable ["ASL_Shorten_Index_Vehicle", objNull]; + private _unit = ASL_ParamMenuUnit; + private _vehicle = _unit getVariable ["ASL_Shorten_Index_Vehicle", objNull]; if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle, player, _ropeIndex] call ASL_Shorten_Ropes; + [_vehicle, _ropeIndex] call ASL_Shorten_Ropes; }; }; ASL_Shorten_Ropes = { - params ["_vehicle", "_player", ["_ropeIndex", 0]]; + params ["_vehicle", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; if (count _existingRopes > 0) then { @@ -466,16 +470,20 @@ ASL_Advanced_Sling_Loading_Install = { if (_ropeLength <= 2) exitWith { _this call ASL_Release_Cargo; }; + private _unwindLength = ASL_ExtendShortenRopeLength; + if (_ropeLength - _unwindLength < 5) then { + _unwindLength = _ropeLength - 5; + }; { if (_ropeLength >= 10) then { - ropeUnwind [_x, 3, -5, true]; + ropeUnwind [_x, 3, -_unwindLength, true]; } else { ropeUnwind [_x, 3, -1, true]; }; } forEach _existingRopes; }; }; - + ASL_Release_Cargo_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -516,26 +524,25 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Release_Cargo) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - if (count _activeRopes == 1) then { + if (count _activeRopes == 1) exitWith { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo; }; - if (count _activeRopes > 1) then { - _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; - }; + _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; + ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself + [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; }; - + ASL_Release_Cargo_Index_Action = { params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; + private _unit = ASL_ParamMenuUnit; + private _vehicle = _unit getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { - [_vehicle, player, _ropesIndex] call ASL_Release_Cargo; + [_vehicle, _unit, _ropesIndex] call ASL_Release_Cargo; }; }; ASL_Release_Cargo = { params ["_vehicle", "_unit", ["_ropeIndex", 0]]; - // params ["_vehicle", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; @@ -597,15 +604,24 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if (count _activeRopes == 1) then { + if (count _activeRopes == 1) exitWith { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; }; - if (count _activeRopes > 1) then { - _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - [format[localize "STR_ASL_RETRACT"], "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; - }; + _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; + ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself + [format[localize "STR_ASL_RETRACT"], "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; }; + ASL_Retract_Ropes_Index_Action = { + params ["_ropesIndex"]; + private _unit = ASL_ParamMenuUnit; + private _vehicle = _unit getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Retract_Ropes_Index_Action) _unit: ", _unit, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + [_vehicle, _unit, _ropesIndex] call ASL_Retract_Ropes; + }; + }; + ASL_Retract_Ropes = { params ["_vehicle", "_unit", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec}; @@ -646,14 +662,6 @@ ASL_Advanced_Sling_Loading_Install = { }; }; - ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { - [_vehicle, player, _ropesIndex] call ASL_Retract_Ropes; - }; - }; - ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit = { params ["_UAV", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) _UAV: ", _UAV, " _unit: ", _unit]; @@ -720,59 +728,61 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Deploy_Ropes_Action = { params [["_vehicle", objNull], "_unit"]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; if (isNull _vehicle) exitWith {false}; if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; }; + ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _inactiveRopes: ", _inactiveRopes]; - if (count _inactiveRopes > 0) then { + if (count _inactiveRopes > 0) exitWith { if (count _inactiveRopes > 1) then { _unit setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; } else { [_vehicle, _unit, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; }; - } else { - private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; - if (count _slingLoadPoints > 1) then { - _unit setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [ - [format[localize "STR_ASL_ROPES"], false] - ]; - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_SINGLE"], [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - if (count _slingLoadPoints > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_DOUBLE"], [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - if (count _slingLoadPoints > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_TRIPLE"], [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; - }; - showCommandingMenu ""; - showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; - } else { - [_vehicle, _unit] call ASL_Deploy_Ropes; - }; }; + private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Deploy_Ropes_Action) _slingLoadPoints: ", _slingLoadPoints, ", _unit: ", _unit]; + if (count _slingLoadPoints == 1) exitWith { + [_vehicle, _unit] call ASL_Deploy_Ropes; + }; + _unit setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [ + [format[localize "STR_ASL_ROPES"], false] + ]; + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_SINGLE"], [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + if (count _slingLoadPoints > 1) then { + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_DOUBLE"], [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + if (count _slingLoadPoints > 2) then { + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_TRIPLE"], [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + }; + showCommandingMenu ""; + showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; }; ASL_Deploy_Ropes_Index_Action = { params ["_ropesIndex"]; - private _vehicle = player getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; - // if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Deploy_Ropes) then { - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _ropesIndex] call ASL_Deploy_Ropes_Index; + private _unit = ASL_ParamMenuUnit; + private _vehicle = _unit getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, _unit] call ASL_Can_Deploy_Ropes) then { + [_vehicle, _unit, _ropesIndex] call ASL_Deploy_Ropes_Index; }; }; - + ASL_Deploy_Ropes_Count_Action = { params ["_count"]; - private _vehicle = player getVariable ["ASL_Deploy_Count_Vehicle", objNull]; - if (_count > 0 && !isNull _vehicle && [_vehicle, player] call ASL_Can_Deploy_Ropes) then { - [_vehicle, player, _count] call ASL_Deploy_Ropes; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Deploy_Ropes_Count_Action) _count: ", _count, ", ASL_ParamMenuUnit: ", ASL_ParamMenuUnit]; + private _unit = ASL_ParamMenuUnit; + private _vehicle = _unit getVariable ["ASL_Deploy_Count_Vehicle", objNull]; + if (_count > 0 && !isNull _vehicle && [_vehicle, _unit] call ASL_Can_Deploy_Ropes) then { + [_vehicle, _unit, _count] call ASL_Deploy_Ropes; }; }; - + ASL_Deploy_Ropes = { params ["_vehicle", "_unit", ["_cargoCount", 1]]; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec}; @@ -801,7 +811,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Deploy_Ropes_Index = { - params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_ropeLength", 15]]; + // params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_ropeLength", 15]]; + params ["_vehicle", "_unit", ["_ropesIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (count _existingRopes > 0) exitWith {}; @@ -813,7 +824,8 @@ ASL_Advanced_Sling_Loading_Install = { }; { _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - ropeUnwind [_x, 5, _ropeLength]; + // ropeUnwind [_x, 5, _ropeLength]; + ropeUnwind [_x, 5, ASL_InitialDeployRopeLength]; } forEach _cargoRopes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; _allRopes set [_ropesIndex, _cargoRopes]; @@ -891,7 +903,7 @@ ASL_Advanced_Sling_Loading_Install = { } forEach _unitRopes; sleep 0.1; }; - [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Actions; // if no rope ends near, remove pickup action from unit + [_unit, ["ASL_ActionID_Pickup"]] call ASL_Remove_Actions; // if no rope ends near, remove pickup action from unit _unit setVariable ["ASL_Ropes_Near_Unit", nil]; // annil unit rope array _unit setVariable ["ASL_Unit_Rope_Monitor", nil]; // annil unit rope monitor flag }; @@ -1122,9 +1134,9 @@ ASL_Advanced_Sling_Loading_Install = { params ["_msg", ["_isSuccess", true]]; if (!isNil "ExileClient_gui_notification_event_addNotification") then { if (_isSuccess) then { - ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; + [format[localize "STR_ASL_SUCCESS"], [_msg]] call ExileClient_gui_notification_event_addNotification; } else { - ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; + [[format[localize "STR_ASL_WHOOPS"], [_msg]] call ExileClient_gui_notification_event_addNotification; }; } else { hint _msg; @@ -1311,12 +1323,14 @@ ASL_Advanced_Sling_Loading_Install = { if (isServer) then { if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) - if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // Pilots authorized to manipulate ropes - if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // Copilots authorized to manipulate ropes - if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // Gunners authorized to manipulate ropes - if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // Passengers authorized to manipulate ropes + if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes + if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes + if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // gunners authorized to manipulate ropes + if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope + if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // rope length in meter, when rope is deployed + if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 07cbe3a..f494908 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -69,4 +69,22 @@ [0, 2000, 0, 0], true, {[] call ASL_Switch_Vehicles_Actions} // code executed on option changed AND on init +] call CBA_fnc_addSetting; + +[ + "ASL_InitialDeployRopeLength", + "SLIDER", + [format[localize "STR_ASL_INITIAL_DEPLOY"], format[localize "STR_ASL_INITIAL_DEPLOY_TIP"]], + format[localize "STR_ASL_TITLE"], + [5, 100, 15, 0], + true +] call CBA_fnc_addSetting; + +[ + "ASL_ExtendShortenRopeLength", + "SLIDER", + [format[localize "STR_ASL_EXTEND_SHORTEN"], format[localize "STR_ASL_EXTEND_SHORTEN_TIP"]], + format[localize "STR_ASL_TITLE"], + [1, 25, 5, 0], + true ] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index c266964..a51b8c6 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -26,40 +26,40 @@ Piloten - Pilots are authorized to manipulate vehicle ropes. - Piloten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + Pilots are authorized to manipulate vehicle ropes (deploy, retract, extend, shorten, release cargo). + Piloten sind berechtigt, Seile von Fahrzeugen zu manipulieren (ausfahren, einfahren, verlängern, kürzen, Ladung ablösen). Commanders Komandanten - Commanders are authorized to manipulate vehicle ropes. - Komandanten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + Commanders are authorized to manipulate vehicle ropes (deploy, retract, extend, shorten, release cargo). + Komandanten sind berechtigt, Seile von Fahrzeugen zu manipulieren (ausfahren, einfahren, verlängern, kürzen, Ladung ablösen). Copilots Kopiloten - Copilots are authorized to manipulate vehicle ropes. - Kopiloten sind berechtigt, Seile von Fahrzeugen zu manipulieren. + Copilots are authorized to manipulate vehicle ropes (deploy, retract, extend, shorten, release cargo). + Kopiloten sind berechtigt, Seile von Fahrzeugen zu manipulieren (ausfahren, einfahren, verlängern, kürzen, Ladung ablösen). Gunners Kanoniere - Gunner are authorized to manipulate vehicle ropes. - Kanoniere sind berechtigt, Seile von Fahrzeugen zu manipulieren. + Gunner are authorized to manipulate vehicle ropes (deploy, retract, extend, shorten, release cargo). + Kanoniere sind berechtigt, Seile von Fahrzeugen zu manipulieren (ausfahren, einfahren, verlängern, kürzen, Ladung ablösen). Passengers Passagiere - Passengers are authorized to manipulate vehicle ropes. - Passagiere sind berechtigt, Seile von Fahrzeugen zu manipulieren. + Passengers are authorized to manipulate vehicle ropes (deploy, retract, extend, shorten, release cargo). + Passagiere sind berechtigt, Seile von Fahrzeugen zu manipulieren (ausfahren, einfahren, verlängern, kürzen, Ladung ablösen). Maximum Deploy Height @@ -76,6 +76,22 @@ Minimal mass in kilogram a vehicle has to have, for ropes to be able to be deployed from that vehicle. Minimales Gewicht in Kilogramm, das ein Fahrzeug haben muss, um Frachtseile von diesem Fahrzeug ausfahren zu können. + + + Deploy Rope Length + Ausfahrseillänge + + + Initial length (meter) of a rope being deployed. + Initiallänge des Seils (Meter), wenn es ausgefahren wird. + + + Extend / Shorten Rope Length + Ausfahr- / Kürzseillänge + + + Length (meter) added or taken from a rope, that is extended / shortened. + Hinzugegebene oder abgezogene Länge (Meter) von einem Seil, das ausgefarhen / gekürzt wird. Deploy Cargo Ropes @@ -176,6 +192,14 @@ Center Zentral + + + Success + Erfolgreich + + + Whoops + Uups \ No newline at end of file diff --git a/mod.cpp b/mod.cpp index 26703ac..8f7e93e 100644 --- a/mod.cpp +++ b/mod.cpp @@ -1,12 +1,12 @@ -name = "Advanced Sling Loading"; +name = "NIC Advanced Sling Loading"; picture = "logo.paa"; -description = "Advanced Sling Loading"; +description = "NIC Advanced Sling Loading"; logo = "logo.paa"; logoOver = "logo.paa"; -tooltip = "Advanced Sling Loading v2.1.1c"; -tooltipOwned = "Advanced Sling Loading Owned"; -overview = "Advanced Sling Loading"; +tooltip = "NIC Advanced Sling Loading v2.1.1c"; +tooltipOwned = "NIC Advanced Sling Loading Owned"; +overview = "NIC Advanced Sling Loading"; author = "[SA] Duda"; overviewPicture = "logo.paa"; -overviewText = "Advanced Sling Loading"; +overviewText = "NIC Advanced Sling Loading"; overviewFootnote = ""; \ No newline at end of file From bb45e16c76b29feb2d7f3e09fdaed2a81070c175 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 2 Apr 2021 10:52:50 +0200 Subject: [PATCH 12/24] minor change --- .../functions/fn_advancedSlingLoadingInit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 0fb3e1a..c7d75a0 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -1330,7 +1330,7 @@ if (isServer) then { if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope - if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // rope length in meter, when rope is deployed + if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened [] call ASL_Advanced_Sling_Loading_Install; }; From ab9c30a785e9dccd53809f630023882fdce20786 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Sun, 11 Apr 2021 22:34:42 +0200 Subject: [PATCH 13/24] minimal syntax change --- .../functions/fn_advancedSlingLoadingInit.sqf | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index c7d75a0..94995c8 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -975,7 +975,6 @@ ASL_Advanced_Sling_Loading_Install = { hideObjectGlobal _helper; _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - private ["_actionID"]; if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes @@ -989,8 +988,7 @@ ASL_Advanced_Sling_Loading_Install = { "[_this] call ASL_Attach_Ropes_Action_Check" // Condition ]; _unit setVariable ["ASL_ActionID_Attach", _actionID]; - }; - + }; if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes format[localize "STR_ASL_DROP"], // Title @@ -1159,7 +1157,6 @@ ASL_Advanced_Sling_Loading_Install = { if (_exit) exitWith { [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release"]] call ASL_Remove_Actions; }; - private ["_actionID"]; if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { _actionID = _vehicle addAction [ @@ -1227,7 +1224,7 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; }; - + ASL_Remove_Actions = { params [["_object", objNull], ["_actions", []]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; @@ -1273,7 +1270,6 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isServer) then { - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecServer = { params ["_sessionId", "_messageParameters", ["_isCall", false]]; _messageParameters params ["_params", "_functionName"]; @@ -1285,7 +1281,6 @@ ASL_Advanced_Sling_Loading_Install = { }; }; }; - ASL_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = [ "ASL_Pickup_Ropes", "ASL_Deploy_Ropes_Index", @@ -1299,7 +1294,6 @@ ASL_Advanced_Sling_Loading_Install = { "ASL_Attach_Ropes", "ASL_Drop_Ropes" ]; - ExileServer_AdvancedSlingLoading_network_AdvancedSlingLoadingRemoteExecClient = { params ["_sessionId", "_messageParameters"]; _messageParameters params ["_params", "_functionName", "_target", ["_isCall", false]]; @@ -1316,7 +1310,7 @@ ASL_Advanced_Sling_Loading_Install = { publicVariable "ASL_Advanced_Sling_Loading_Install"; remoteExecCall ["ASL_Advanced_Sling_Loading_Install", -2, true]; }; - + diag_log "Advanced Sling Loading Loaded"; }; From f88e65082f3bf57f58e7674baad1d402c5252620 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Tue, 27 Apr 2021 09:38:28 +0200 Subject: [PATCH 14/24] - minor changes - added bikey - removed irrelevant code --- addons/NIC_AdvancedSlingLoading/config.cpp | 23 +--- .../functions/fn_advancedSlingLoadingInit.sqf | 99 ++++++++++-------- .../scripts/XEH_preInit.sqf | 25 +++-- .../NIC_AdvancedSlingLoading/stringtable.xml | 16 +++ keys/NIC.bikey | Bin 0 -> 156 bytes meta.cpp | 4 - 6 files changed, 93 insertions(+), 74 deletions(-) create mode 100644 keys/NIC.bikey delete mode 100644 meta.cpp diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp index 65414e5..d41fe51 100644 --- a/addons/NIC_AdvancedSlingLoading/config.cpp +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -1,8 +1,7 @@ class CfgPatches { class SA_AdvancedSlingLoading { units[] = { - "SA_AdvancedSlingLoading", - "ASL_RopeSmallWeight" + "SA_AdvancedSlingLoading" }; requiredVersion = 1; requiredAddons[] = { @@ -33,11 +32,7 @@ class CfgFunctions { class SA { class AdvancedSlingLoading { file = "\SA_AdvancedSlingLoading\functions"; - // class ASLaddActions { - // preInit = 1; - // }; class advancedSlingLoadingInit { - // postInit = 1; preInit = 1; }; }; @@ -48,15 +43,7 @@ class Extended_PreInit_EventHandlers { init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration }; }; -class CfgVehicles { - class Land_Camping_Light_F; - class ASL_RopeSmallWeight : Land_Camping_Light_F { - scope = 2; - displayname = "Rope weight"; - model = "\SA_AdvancedSlingLoading\ASL_weightSmall"; - }; -}; -class cfgMods { - author = "76561198131707990"; - timepacked = "1473204282"; -}; +// class cfgMods { + // author = "76561198131707990"; + // timepacked = "1473204282"; +// }; diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 94995c8..7864396 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -22,13 +22,27 @@ ASL_Advanced_Sling_Loading_Install = { if (!isNil "ASL_ROPE_INIT") exitWith {}; // Prevent advanced sling loading from installing twice ASL_ROPE_INIT = true; + // if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter + // if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) + // if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes + // if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes + // if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // gunners authorized to manipulate ropes + // if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes + // if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter + // if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes + // if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope + // if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed + // if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened + // if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted + // if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) + diag_log "Advanced Sling Loading Loading..."; ASL_Rope_Get_Lift_Capability = { params ["_vehicle"]; private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); if (_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = 4000; + _slingLoadMaxCargoMass = ASL_DefaultLiftableMass; }; _slingLoadMaxCargoMass; }; @@ -52,14 +66,12 @@ ASL_Advanced_Sling_Loading_Install = { _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - private _slingLoadPointHeightOffset = 0; { if (_vehicle isKindOf (_x select 0)) exitWith { _slingLoadPointHeightOffset = (_x select 1); }; } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; - private _slingLoadPoints = []; private ["_modelPoint", "_modelPointASL", @@ -85,10 +97,8 @@ ASL_Advanced_Sling_Loading_Install = { // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces // doesn't work if starting below ground level for some reason // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection - _la = ASLToAGL _surfaceIntersectStartASL; _lb = ASLToAGL _surfaceIntersectEndASL; - if (_la select 2 < 0 && _lb select 2 > 0) then { _n = [0, 0, 1]; _p0 = [0, 0, 0.1]; @@ -131,47 +141,42 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Corner_Points = { params ["_vehicle"]; - - // Correct width and length factor for air - private _widthFactor = 0.5; - private _lengthFactor = 0.5; - if (_vehicle isKindOf "Air") then { - _widthFactor = 0.3; + private _widthFactor = 0.5; + private _lengthFactor = 0.5; + if (_vehicle isKindOf "Air") then { // Correct width and length factor for air + _widthFactor = 0.3; }; if (_vehicle isKindOf "Helicopter") then { - _widthFactor = 0.2; - _lengthFactor = 0.45; - }; - - private _centerOfMass = getCenterOfMass _vehicle; - private _bbr = boundingBoxReal _vehicle; - private _p1 = _bbr select 0; - private _p2 = _bbr select 1; - private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; - private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; - private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); - private _heightOffset = _maxHeight / 6; - - private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - + _widthFactor = 0.2; + _lengthFactor = 0.45; + }; + private _centerOfMass = getCenterOfMass _vehicle; + private _bbr = boundingBoxReal _vehicle; + private _p1 = _bbr select 0; + private _p2 = _bbr select 1; + private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); + private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; + private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); + private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; + private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _heightOffset = _maxHeight / 6; + private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; ASL_Rope_Set_Mass = { - private _obj = [_this, 0] call BIS_fnc_param; - private _mass = [_this, 1] call BIS_fnc_param; + private _obj = [_this, 0] call BIS_fnc_param; + private _mass = [_this, 1] call BIS_fnc_param; _obj setMass _mass; }; ASL_Rope_Adjust_Mass = { params ["_obj", "_heli", ["_ropes", []]]; private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; - private _maxLiftableMass = _lift * 8; + private _maxLiftableMass = _lift * ASL_MaxLiftableMassFactor; private _originalMass = getMass _obj; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; // diag_log formatText [ @@ -257,7 +262,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Active_Ropes_With_Cargo = { - params ["_vehicle"]; + // params ["_vehicle"]; + params [["_vehicle", objNull], ["_unit", objNull]]; private _activeRopesWithCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; private _activeRopes = _this call ASL_Get_Active_Ropes; @@ -265,6 +271,9 @@ ASL_Advanced_Sling_Loading_Install = { { _cargo = _existingCargo select (_x select 0); if (!isNull _cargo) then { + if ((!alive _cargo || ropeAttachedTo _cargo != _vehicle) && !isNull _unit) exitWith { + [_vehicle, _unit, _foreachindex] call ASL_Release_Cargo; // in case cargo destroyed + }; _activeRopesWithCargo pushBack _x; }; } forEach _activeRopes; @@ -493,13 +502,15 @@ ASL_Advanced_Sling_Loading_Install = { }; if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; - [_vehicle] call ASL_Can_Release_Cargo + // [_vehicle] call ASL_Can_Release_Cargo + [_vehicle, _unit] call ASL_Can_Release_Cargo }; false }; ASL_Can_Release_Cargo = { - params ["_vehicle"]; + // params ["_vehicle"]; + params [["_vehicle", objNull], ["_unit", objNull]]; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 1"]; false @@ -509,7 +520,9 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 2"]; false }; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; + if (count _activeRopes == 0) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 3"]; false @@ -531,7 +544,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; }; - + ASL_Release_Cargo_Index_Action = { params ["_ropesIndex"]; private _unit = ASL_ParamMenuUnit; @@ -557,7 +570,7 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable ["ASL_Cargo", _allCargo, true]; _this call ASL_Retract_Ropes; }; - + ASL_Retract_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -811,7 +824,6 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Deploy_Ropes_Index = { - // params ["_vehicle", "_unit", ["_ropesIndex", 0], ["_ropeLength", 15]]; params ["_vehicle", "_unit", ["_ropesIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; @@ -824,7 +836,6 @@ ASL_Advanced_Sling_Loading_Install = { }; { _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - // ropeUnwind [_x, 5, _ropeLength]; ropeUnwind [_x, 5, ASL_InitialDeployRopeLength]; } forEach _cargoRopes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; @@ -1134,7 +1145,7 @@ ASL_Advanced_Sling_Loading_Install = { if (_isSuccess) then { [format[localize "STR_ASL_SUCCESS"], [_msg]] call ExileClient_gui_notification_event_addNotification; } else { - [[format[localize "STR_ASL_WHOOPS"], [_msg]] call ExileClient_gui_notification_event_addNotification; + [format[localize "STR_ASL_WHOOPS"], [_msg]] call ExileClient_gui_notification_event_addNotification; }; } else { hint _msg; @@ -1326,5 +1337,7 @@ if (isServer) then { if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened + if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted + if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index f494908..6d72b4c 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -6,7 +6,6 @@ [30, 150, 100, 0], // data for this setting: [_min, _max, _default, _trailingDecimals] true // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer ] call CBA_fnc_addSetting; - [ "ASL_MaxDeployRetractDistance", "SLIDER", @@ -15,7 +14,6 @@ [3, 30, 10, 0], true ] call CBA_fnc_addSetting; - [ "ASL_PilotsAuthorized", "CHECKBOX", @@ -24,7 +22,6 @@ true, // default setting true ] call CBA_fnc_addSetting; - [ "ASL_CopilotsAuthorized", "CHECKBOX", @@ -33,7 +30,6 @@ true, true ] call CBA_fnc_addSetting; - [ "ASL_GunnersAuthorized", "CHECKBOX", @@ -42,7 +38,6 @@ false, true ] call CBA_fnc_addSetting; - [ "ASL_PassengersAuthorized", "CHECKBOX", @@ -51,7 +46,6 @@ false, true ] call CBA_fnc_addSetting; - [ "ASL_MaxRopeDeployHeight", "SLIDER", @@ -60,7 +54,6 @@ [0, 1000, 100, 0], true ] call CBA_fnc_addSetting; - [ "ASL_MinVehicleMass", "SLIDER", @@ -70,7 +63,6 @@ true, {[] call ASL_Switch_Vehicles_Actions} // code executed on option changed AND on init ] call CBA_fnc_addSetting; - [ "ASL_InitialDeployRopeLength", "SLIDER", @@ -79,7 +71,6 @@ [5, 100, 15, 0], true ] call CBA_fnc_addSetting; - [ "ASL_ExtendShortenRopeLength", "SLIDER", @@ -87,4 +78,20 @@ format[localize "STR_ASL_TITLE"], [1, 25, 5, 0], true +] call CBA_fnc_addSetting; +[ + "ASL_DefaultLiftableMass", + "SLIDER", + [format[localize "STR_ASL_DEFAULT_MASS"], format[localize "STR_ASL_DEFAULT_MASS_TIP"]], + format[localize "STR_ASL_TITLE"], + [500, 10000, 4000, 0], + true +] call CBA_fnc_addSetting; +[ + "ASL_MaxLiftableMassFactor", + "SLIDER", + [format[localize "STR_ASL_MAX_MASS"], format[localize "STR_ASL_MAX_MASS_TIP"]], + format[localize "STR_ASL_TITLE"], + [1, 20, 8, 0], + true ] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index a51b8c6..da2a478 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -92,6 +92,22 @@ Length (meter) added or taken from a rope, that is extended / shortened. Hinzugegebene oder abgezogene Länge (Meter) von einem Seil, das ausgefarhen / gekürzt wird. + + + Default Liftable Mass + Standardschlinglastmasse + + + Default liftable mass in kg a vehicle can lift. + Standardschlinglastmasse in kg, die ein Fahrzeug anheben kann. + + + Maximum Liftable Mass Factor + Maximalschlinglastmassenfaktor + + + Maximum liftable mass factor a vehicle can lift (factor * vehicle lift capabilty). + Faktor der die Maximalschlinglastmasse bestimmt (Faktor * Fahrzeughebekapazität). Deploy Cargo Ropes diff --git a/keys/NIC.bikey b/keys/NIC.bikey new file mode 100644 index 0000000000000000000000000000000000000000..faece5843af936a499c3047ec82fc0836f81b5d8 GIT binary patch literal 156 zcmV;N0Av47NkagX000060ssI2Bme+XQ$aBR1ONa50096+FjxCvqd^`+6gIbZsIBEs zr;SMvncJ8iJqs6t#CkRH;9Y>2e|B4ESvH%v*UEFABJId+F`%*)HlJKODU9Aj#sn$Y z7-ki^>$IDxuVubdUy>%IZ8xsN0DUog0*k{lvz#A0waVuQf K7G1mQIMKY~UO{63 literal 0 HcmV?d00001 diff --git a/meta.cpp b/meta.cpp deleted file mode 100644 index da14732..0000000 --- a/meta.cpp +++ /dev/null @@ -1,4 +0,0 @@ -protocol = 1; -publishedid = 615007497; -name = "Advanced Sling Loading"; -timestamp = 5247774176389108621; From 2cdfbbf312d3a26fce38b1b10774782a0013f457 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 30 Apr 2021 10:32:13 +0200 Subject: [PATCH 15/24] Various additions - added rope length hints for deploying, shortening and extending cargo ropes - added more CBA settings - fixed typos and bugs - added server key - added drop cargo hotkey for players --- addons/NIC_AdvancedSlingLoading/config.cpp | 9 +- .../functions/fn_advancedSlingLoadingInit.sqf | 197 ++++++++++++------ .../scripts/XEH_postInit.sqf | 14 ++ .../scripts/XEH_preInit.sqf | 18 +- .../NIC_AdvancedSlingLoading/stringtable.xml | 70 ++++++- addons/replace me with the .bisign file | 0 6 files changed, 233 insertions(+), 75 deletions(-) create mode 100644 addons/NIC_AdvancedSlingLoading/scripts/XEH_postInit.sqf create mode 100644 addons/replace me with the .bisign file diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp index d41fe51..3140ca0 100644 --- a/addons/NIC_AdvancedSlingLoading/config.cpp +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -43,7 +43,8 @@ class Extended_PreInit_EventHandlers { init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration }; }; -// class cfgMods { - // author = "76561198131707990"; - // timepacked = "1473204282"; -// }; +class Extended_PostInit_EventHandlers { + class SA { + init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_postInit.sqf'"; // CBA key binding integration + }; +}; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 7864396..35e5df8 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -8,7 +8,8 @@ documentation files (the "Software"), to deal in the Software without restrictio the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions +of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR @@ -21,21 +22,7 @@ DEALINGS IN THE SOFTWARE. ASL_Advanced_Sling_Loading_Install = { if (!isNil "ASL_ROPE_INIT") exitWith {}; // Prevent advanced sling loading from installing twice ASL_ROPE_INIT = true; - - // if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter - // if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) - // if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes - // if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes - // if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // gunners authorized to manipulate ropes - // if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes - // if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter - // if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes - // if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope - // if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed - // if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened - // if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted - // if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) - + diag_log "Advanced Sling Loading Loading..."; ASL_Rope_Get_Lift_Capability = { @@ -262,11 +249,11 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Active_Ropes_With_Cargo = { - // params ["_vehicle"]; params [["_vehicle", objNull], ["_unit", objNull]]; private _activeRopesWithCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - private _activeRopes = _this call ASL_Get_Active_Ropes; + // private _activeRopes = _this call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); @@ -284,7 +271,8 @@ ASL_Advanced_Sling_Loading_Install = { params ["_vehicle"]; private _activeRopesWithoutCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - private _activeRopes = _this call ASL_Get_Active_Ropes; + // private _activeRopes = _this call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); @@ -377,11 +365,36 @@ ASL_Advanced_Sling_Loading_Install = { if !([_vehicle] call ASL_Can_Extend_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; if (count _activeRopes == 1) exitWith { - [_vehicle, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; + private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; + if (_ropeLength <= ASL_MaxRopeLength) exitWith { + private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + if (_ropeLength == ASL_MaxRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (max)"]; + }; + hint _messageText; + }; + hint format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]; }; _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + private _extendedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; + if (count _extendedRopes > 0) then { + private _messageText = format[localize "STR_ASL_ROPES_EXTENDED"]; + { + if (_x select 1 <= ASL_MaxRopeLength) then { + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_EXTENDED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; + if (_x select 1 == ASL_MaxRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (max)"]; + }; + } else { + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]]; + }; + } forEach _extendedRopes; + _messageText setAttributes ["align", "left"]; + hint composeText [_messageText]; + _vehicle setVariable ["ASL_Ropes_Change", nil]; + }; }; ASL_Show_Select_Ropes_Menu = { @@ -393,36 +406,45 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0, 1, 2];"]], "1", "1"]; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; + waitUntil {commandingMenu == ""}; }; ASL_Extend_Ropes_Index_Action = { params ["_ropeIndex"]; private _unit = ASL_ParamMenuUnit; - // ASL_ParamMenuUnit = nil; private _vehicle = _unit getVariable ["ASL_Extend_Index_Vehicle", objNull]; if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - [_vehicle, _ropeIndex] call ASL_Extend_Ropes; + private _ropeLength = [_vehicle, _ropeIndex] call ASL_Extend_Ropes; + [_vehicle, _ropeLength, _ropeIndex] call ASL_Save_Rope_Change; }; }; + ASL_Save_Rope_Change = { + params [["_vehicle", objNull], ["_ropeLength", 0], ["_ropeIndex", 0]]; + if (isNull _vehicle) exitWith {}; + private _changedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; + _changedRopes pushBack [_ropeIndex, _ropeLength]; + _vehicle setVariable ["ASL_Ropes_Change", _changedRopes]; + }; + ASL_Extend_Ropes = { params ["_vehicle", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; - if (count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength < ASL_MaxRopeLength) then { - private _unwindLength = ASL_ExtendShortenRopeLength; - if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { - _unwindLength = ASL_MaxRopeLength - _ropeLength; - }; - { - ropeUnwind [_x, 3, _unwindLength, true]; - } forEach _existingRopes; - }; + if (count _existingRopes == 0) exitWith {0}; + private _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength >= ASL_MaxRopeLength) exitWith {ASL_MaxRopeLength + 1}; + private _unwindLength = ASL_ExtendShortenRopeLength; + if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { + _unwindLength = ASL_MaxRopeLength - _ropeLength; }; + { + ropeUnwind [_x, 3, _unwindLength, true]; + } forEach _existingRopes; + _ropeLength = _ropeLength + _unwindLength; + _ropeLength }; - + ASL_Shorten_Ropes_Action_Check = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -454,11 +476,36 @@ ASL_Advanced_Sling_Loading_Install = { if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; if (count _activeRopes == 1) exitWith { - [_vehicle, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + if (_ropeLength >= ASL_MinRopeLength) exitWith { + private _messageText = format[localize "STR_ASL_ROPES_SHORTENED_TO", _ropeLength]; + if (_ropeLength == ASL_MinRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (min)"]; + }; + hint _messageText; + }; + hint format[localize "STR_ASL_ALREADY_MIN_LENGTH", ASL_MinRopeLength]; }; _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + private _shortenedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; + if (count _shortenedRopes > 0) then { + private _messageText = format[localize "STR_ASL_ROPES_SHORTENED"]; + { + if (_x select 1 >= ASL_MinRopeLength) then { + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; + if (_x select 1 == ASL_MinRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (min)"]; + }; + } else { + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ALREADY_MIN_LENGTH", ASL_MinRopeLength]]; + }; + } forEach _shortenedRopes; + _messageText setAttributes ["align", "left"]; + hint composeText [_messageText]; + _vehicle setVariable ["ASL_Ropes_Change", nil]; + }; }; ASL_Shorten_Ropes_Index_Action = { @@ -466,31 +513,35 @@ ASL_Advanced_Sling_Loading_Install = { private _unit = ASL_ParamMenuUnit; private _vehicle = _unit getVariable ["ASL_Shorten_Index_Vehicle", objNull]; if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - [_vehicle, _ropeIndex] call ASL_Shorten_Ropes; + private _ropeLength = [_vehicle, _ropeIndex] call ASL_Shorten_Ropes; + [_vehicle, _ropeLength, _ropeIndex] call ASL_Save_Rope_Change; }; }; - + ASL_Shorten_Ropes = { params ["_vehicle", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + private _ropeLength = -1; if (count _existingRopes > 0) then { - private _ropeLength = ropeLength (_existingRopes select 0); - if (_ropeLength <= 2) exitWith { - _this call ASL_Release_Cargo; + _ropeLength = ropeLength (_existingRopes select 0); + if (_ropeLength <= ASL_MinRopeLength) exitWith { + if (ASL_MinRopeLengthDropCargo) then { + _this call ASL_Release_Cargo; + }; + _ropeLength = ASL_MinRopeLength - 1; }; private _unwindLength = ASL_ExtendShortenRopeLength; if (_ropeLength - _unwindLength < 5) then { _unwindLength = _ropeLength - 5; }; + if (_ropeLength < 10) then {_unwindLength = 1}; { - if (_ropeLength >= 10) then { - ropeUnwind [_x, 3, -_unwindLength, true]; - } else { - ropeUnwind [_x, 3, -1, true]; - }; + ropeUnwind [_x, 3, -_unwindLength, true]; } forEach _existingRopes; + _ropeLength = _ropeLength - _unwindLength; }; + _ropeLength }; ASL_Release_Cargo_Action_Check = { @@ -502,14 +553,12 @@ ASL_Advanced_Sling_Loading_Install = { }; if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; - // [_vehicle] call ASL_Can_Release_Cargo [_vehicle, _unit] call ASL_Can_Release_Cargo }; false }; ASL_Can_Release_Cargo = { - // params ["_vehicle"]; params [["_vehicle", objNull], ["_unit", objNull]]; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 1"]; @@ -520,9 +569,7 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 2"]; false }; - // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; - private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; - + private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; if (count _activeRopes == 0) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 3"]; false @@ -532,13 +579,14 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Release_Cargo_Action = { - params [["_vehicle", objNull], "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Release_Cargo) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; if (count _activeRopes == 1) exitWith { - [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo; + [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo }; _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself @@ -557,13 +605,12 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo = { params ["_vehicle", "_unit", ["_ropeIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; - private _existingRopesAndCargo = [_vehicle,_ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; private _existingCargo = _existingRopesAndCargo select 1; { _existingCargo ropeDetach _x; } forEach _existingRopes; - _existingCargo setVariable ["ASL_RopeEndHelper", nil, true]; _existingCargo setVariable ["ASL_RopesIndex", nil, true]; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [_ropeIndex, objNull]; @@ -842,6 +889,7 @@ ASL_Advanced_Sling_Loading_Install = { _allRopes set [_ropesIndex, _cargoRopes]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; [_vehicle] spawn ASL_Rope_Monitor_Vehicle; + hint format[localize "STR_ASL_ROPES_DEPLOYED", ASL_InitialDeployRopeLength]; }; ASL_Rope_Monitor_Vehicle = { @@ -875,12 +923,12 @@ ASL_Advanced_Sling_Loading_Install = { }; _vehicle setVariable ["ASL_Vehicle_Rope_Monitor", nil, true]; }; - + ASL_Rope_Monitor_Unit = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; if (_unit getVariable ["ASL_Unit_Rope_Monitor", false]) exitWith {}; // leave, if unit is already monitoring ror rope ends - _unit setVariable ["ASL_Unit_Rope_Monitor", true]; // raise unit rope monitor flag + _unit setVariable ["ASL_Unit_Rope_Monitor", true, true]; // raise unit rope monitor flag // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; if (isNil{_unit getVariable "ASL_ActionID_Pickup"}) then { // add pickup action to unit private _actionID = _unit addAction [ @@ -923,7 +971,6 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull]]; if (isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _target: ", _target, ", _this: ", _this]; - // hintSilent formatText ["%1%2%3%4%5%6", time, "s (ASL_Pickup_Ropes_Action_Check) _unit: ", _unit, lineBreak, "rope ends found: ", count ((_unit nearObjects 5) select {_x getVariable ["ASL_RopeEndHelper", false]})]; if (vehicle _unit != _unit) exitWith {false}; if !(isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}) exitWith {false}; private _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; @@ -932,13 +979,15 @@ ASL_Advanced_Sling_Loading_Install = { _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; }; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _unitRopes: ", _unitRopes]; - private _pickup = false; + private _pickup = false; + private _ropeHandlingDistance = ASL_RopeHandlingDistance; + if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; { - if (alive _x && (_unit distance (ropeEndPosition _x select 1) < ASL_RopeHandlingDistance)) exitWith {_pickup = true}; + if (alive _x && (_unit distance (ropeEndPosition _x select 1) < _ropeHandlingDistance)) exitWith {_pickup = true}; } forEach _unitRopes; _pickup }; - + ASL_Pickup_Ropes_Action = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; @@ -946,13 +995,24 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; private _closestRope = objNull; - private _closestDistance = ASL_RopeHandlingDistance + 100; + + private _ropeHandlingDistance = ASL_RopeHandlingDistance; + if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; + private _closestDistance = _ropeHandlingDistance + 100; { _distance = _unit distance (ropeEndPosition _x select 1); - if (_x != objNull && _distance < ASL_RopeHandlingDistance && _distance < _closestDistance) then { + if (_x != objNull && _distance < _ropeHandlingDistance && _distance < _closestDistance) then { _closestRope = _x; }; } forEach _unitRopes; + + // private _closestDistance = ASL_RopeHandlingDistance + 100; + // { + // _distance = _unit distance (ropeEndPosition _x select 1); + // if (_x != objNull && _distance < ASL_RopeHandlingDistance && _distance < _closestDistance) then { + // _closestRope = _x; + // }; + // } forEach _unitRopes; if (isNull _closestRope) exitWith {}; private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") select 0; if (isNull _vehicle) exitWith {}; @@ -962,7 +1022,7 @@ ASL_Advanced_Sling_Loading_Install = { private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") select 1; [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; }; - + ASL_Pickup_Ropes = { params ["_vehicle", "_unit", ["_ropesIndex", 0]]; if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; @@ -1020,7 +1080,12 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _unit) exitWith {false}; private _cargo = cursorTarget; private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; - [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; + + private _ropeHandlingDistance = ASL_RopeHandlingDistance; + if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; + + // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; + [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < _ropeHandlingDistance && _vehicle != _cargo; }; ASL_Attach_Ropes_Action = { @@ -1327,6 +1392,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isServer) then { if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter + if (isNil "ASL_MinRopeLength") then {ASL_MinRopeLength = 2}; // minimum rope length in meter if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes @@ -1339,5 +1405,6 @@ if (isServer) then { if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) + if (isNil "ASL_MinRopeLengthDropCargo") then {ASL_MinRopeLengthDropCargo = false}; // drop cargo, when minimum rope length is reached, and ropes are shortened once more [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_postInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_postInit.sqf new file mode 100644 index 0000000..ea52aac --- /dev/null +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_postInit.sqf @@ -0,0 +1,14 @@ +[ + format[localize "STR_ASL_TITLE"], // name of mod + "ASL_DropCargoKey", // id of the key action + [format[localize "STR_DROP_CARGO_KEY"], format[localize "STR_DROP_CARGO_KEY_TIP"]], // [name of key bind action, tool tip] + { + if (vehicle player == player || !([vehicle player, player] call ASL_Is_Unit_Authorized)) exitWith {}; + private _allCargo = vehicle player getVariable ["ASL_Cargo", []]; + { + [vehicle player, player, _foreachindex] call ASL_Release_Cargo; + } forEach _allCargo; + }, // code executed on key down + {false}, // code executed on key up + [0x20, [false, true, false]] // [key for starting action, [shift, ctrl, alt] (additional key to be pressed)] +] call CBA_fnc_addKeybind; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 6d72b4c..632063d 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -94,4 +94,20 @@ format[localize "STR_ASL_TITLE"], [1, 20, 8, 0], true -] call CBA_fnc_addSetting; \ No newline at end of file +] call CBA_fnc_addSetting; +[ + "ASL_MinRopeLengthDropCargo", + "CHECKBOX", + [format[localize "STR_ASL_MIN_MASS_DROP"], format[localize "STR_ASL_MIN_MASS_DROP_TIP"]], + format[localize "STR_ASL_TITLE"], + false, + true +] call CBA_fnc_addSetting; +[ + "ASL_RopeHandlingDistance", + "SLIDER", + [format[localize "STR_ROPE_HANDLING_DIST"], format[localize "STR_ROPE_HANDLING_DIST_TIP"]], + format[localize "STR_ASL_TITLE"], + [2, 20, 5, 0], + true +] call CBA_fnc_addSetting; diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index da2a478..cea8c07 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -107,7 +107,7 @@ Maximum liftable mass factor a vehicle can lift (factor * vehicle lift capabilty). - Faktor der die Maximalschlinglastmasse bestimmt (Faktor * Fahrzeughebekapazität). + Faktor, der die Maximalschlinglastmasse bestimmt (Faktor * Fahrzeughebekapazität). Deploy Cargo Ropes @@ -143,7 +143,7 @@ Cannot deploy cargo ropes from locked vehicle - Frachtseile können von verschlossenen Fahrzeugen nicht ausgefahren werden + Frachtseile können nicht von verschlossenen Fahrzeugen aus ausgefahren werden Deploy Ropes @@ -175,15 +175,15 @@ Cargo ropes too short. Extend ropes or move vehicle closer. - Frachtseile zu kurz. Seile weiter ausfahren oder Fahrzeug näher bringen. + Frachtseile zu kurz. Seile weiter ausfahren oder Fahrzeug näher fahren. Cannot attach cargo ropes to locked vehicle. - Frachtseile können nicht an verschlossene Fahrzeuge befestigt werden. + Frachtseile können nicht an verschlossenen Fahrzeugen befestigt werden. Cannot attach cargo ropes in safe zone. - Frachtseile können nicht bfestigt werden in sicheren Zonen. + Frachtseile können in sicheren Zonen nicht bfestigt werden. Cannot pick up cargo ropes from locked vehicle. @@ -216,6 +216,66 @@ Whoops Uups + + + Ropes deployed (%1 m) + Seile ausgefahren (%1 m) + + + Ropes extended + Seile verlängert + + + Ropes extended to %1 m + Seile auf %1 m verlängert + + + %1 ropes %2 m + %1 Seile %2 m + + + Ropes already at maximum lenghth (%1 m) + Seile bereits auf Maximallänge (%1 m) + + + Ropes shortened + Seile verkürzt + + + Ropes shortened to %1 m + Seile auf %1 m verkürzt + + + %1 ropes %2 m + %1 Seile %2 m + + + Ropes already at minimum length (%1 m) + Seile bereits auf Minimallänge (%1 m) + + + Minimum Rope Length Drop Cargo + Minimalseillänge Ladung Lösen + + + Drop cargo, when ropes were already retracted to their minimal length, and ropes are retracted once more. + Ladung Lösen, wenn Seile bereits auf Minimalseillänge verkürzt wurden, und Seile ein weiteres mal verkürzt werden. + + + Drop Cargo + Ladung Lösen + + + Drop all cargo and retract all ropes. + Alle Ladung Lösen und alle Seile einfahren. + + + Rope Handling Distance + Seilmanipulationsentfernung + + + Rope hanling distance in meter from a unit to a rope end. + Seilmanipulationsentfernung in meter von einer Einheit zu einem Seilende. \ No newline at end of file diff --git a/addons/replace me with the .bisign file b/addons/replace me with the .bisign file new file mode 100644 index 0000000..e69de29 From a1bfe3c7013f3f60a9e9068c0c375cbe5f698370 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 30 Apr 2021 11:59:36 +0200 Subject: [PATCH 16/24] weekend playtest version - rearranged some code and functions, got rid of no longer needed small weight --- .../ASL_weightSmall.p3d | Bin 1323 -> 0 bytes .../functions/fn_advancedSlingLoadingInit.sqf | 94 +++++++----------- .../NIC_AdvancedSlingLoading/stringtable.xml | 4 + 3 files changed, 39 insertions(+), 59 deletions(-) delete mode 100644 addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d diff --git a/addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d b/addons/NIC_AdvancedSlingLoading/ASL_weightSmall.p3d deleted file mode 100644 index 3f147bb3cf4448a00666db0214af484f6fd0a202..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1323 zcmcIiOHKko5bee<_#ON%T$uC)G%PWhF@mswV1l@ogz=Lo5a9r`@FpC=B?~t$byF|b6BgbFvg^@Rzc;e%ZLE`tufY0=w#jD$cORU>l@!=jL9lpo>nSSHSgL_{c`6v z94K*ZIQsSMtLb~d8cqa{JF%|_kMkgh4sjOb;jxYw>xkjyS?{sm>xSLo(J^0~Oq!~< z2XvG}qJF&BPNog1T35|*sKgtQlV*E_kH=uyHS3d=gaT7ze7gSs@=}$%oyN`i{X?ku JRG-gY>k9$Wq|E>T diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 35e5df8..0309361 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -197,11 +197,13 @@ ASL_Advanced_Sling_Loading_Install = { }; /* - Constructs an array of all active rope indexes and position labels - (e.g. [[rope index,"Front"],[rope index,"Rear"]]) for a specified vehicle + Constructs an array of all active (or inactive) rope indexes and position labels + (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle */ ASL_Get_Active_Ropes = { - params ["_vehicle"]; + params [["_vehicle", objNull], ["_active", false]]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Get_Ropes) _vehicle: ", _vehicle, " _active: ", _active]; + if (isNull _vehicle) exitWith {false}; private _activeRopes = []; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; private _ropeLabelSets = [ @@ -209,51 +211,24 @@ ASL_Advanced_Sling_Loading_Install = { [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_REAR"]], [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_CENTER"], format[localize "STR_ASL_REAR"]] ]; - private _ropeIndex = 0; private _totalExistingRopes = count _existingRopes; private ["_ropeLabels"]; { - if (count _x > 0) then { + if ((_active && count _x > 0) || (!_active && count _x == 0)) then { _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; + _activeRopes pushBack [_foreachindex, _ropeLabels select _foreachindex]; }; - _ropeIndex = _ropeIndex + 1; } forEach _existingRopes; _activeRopes; }; - /* - Constructs an array of all inactive rope indexes and position labels - (e.g. [[rope index,"Front"],[rope index,"Rear"]]) for a specified vehicle - */ - ASL_Get_Inactive_Ropes = { - params ["_vehicle"]; - private _inactiveRopes = []; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - private _ropeLabelSets = [ - [format[localize "STR_ASL_CENTER"]], - [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_REAR"]], - [format[localize "STR_ASL_FRONT"], format[localize "STR_ASL_CENTER"], format[localize "STR_ASL_REAR"]] - ]; - private _ropeIndex = 0; - private _totalExistingRopes = count _existingRopes; - private ["_ropeLabels"]; - { - if (count _x == 0) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _inactiveRopes pushBack [_ropeIndex, _ropeLabels select _ropeIndex]; - }; - _ropeIndex = _ropeIndex + 1; - } forEach _existingRopes; - _inactiveRopes; - }; - ASL_Get_Active_Ropes_With_Cargo = { params [["_vehicle", objNull], ["_unit", objNull]]; private _activeRopesWithCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; // private _activeRopes = _this call ASL_Get_Active_Ropes; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); @@ -272,7 +247,8 @@ ASL_Advanced_Sling_Loading_Install = { private _activeRopesWithoutCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; // private _activeRopes = _this call ASL_Get_Active_Ropes; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); @@ -333,15 +309,16 @@ ASL_Advanced_Sling_Loading_Install = { params ["_vehicle", "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Unit_Authorized) _vehicle: ", _vehicle, " _unit: ", _unit]; if (driver _vehicle == _unit && ASL_PilotsAuthorized || - gunner _vehicle == _unit && ASL_GunnersAuthorized || - _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) exitWith {true}; + gunner _vehicle == _unit && ASL_GunnersAuthorized || + _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) + exitWith {true}; if !(ASL_CopilotsAuthorized) exitWith {false}; private _cfg = configFile >> "CfgVehicles" >> typeOf(_vehicle); - private _trts = _cfg >> "turrets"; + private _turrets = _cfg >> "turrets"; private _isCopilot = false; - for "_i" from 0 to (count _trts - 1) do { - private _trt = _trts select _i; - if (getNumber(_trt >> "iscopilot") == 1) exitWith { + for "_i" from 0 to (count _turrets - 1) do { + private _turret = _turrets select _i; + if (getNumber(_turret >> "iscopilot") == 1) exitWith { _isCopilot = ((_vehicle turretUnit [_i]) == _unit); // check, if unit is copilot }; }; @@ -351,19 +328,17 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Extend_Ropes = { params ["_vehicle"]; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _existingRopes == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 0) exitWith {false}; + if (count (_vehicle getVariable ["ASL_Ropes", []]) == 0) exitWith {false}; + if (count ([_vehicle, true] call ASL_Get_Active_Ropes) == 0) exitWith {false}; true; }; - + ASL_Extend_Ropes_Action = { params [["_vehicle", objNull], "_unit"]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Extend_Ropes) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; if (count _activeRopes == 1) exitWith { private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; if (_ropeLength <= ASL_MaxRopeLength) exitWith { @@ -458,14 +433,12 @@ ASL_Advanced_Sling_Loading_Install = { }; false }; - + ASL_Can_Shorten_Ropes = { params ["_vehicle"]; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _existingRopes == 0) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; - if (count _activeRopes == 0) exitWith {false}; + if (count (_vehicle getVariable ["ASL_Ropes", []]) == 0) exitWith {false}; + if (count ([_vehicle, true] call ASL_Get_Active_Ropes) == 0) exitWith {false}; true }; @@ -474,7 +447,8 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; if (count _activeRopes == 1) exitWith { private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; if (_ropeLength >= ASL_MinRopeLength) exitWith { @@ -590,7 +564,7 @@ ASL_Advanced_Sling_Loading_Install = { }; _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, "Cargo"] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, format[localize "STR_ASL_CARGO"]] call ASL_Show_Select_Ropes_Menu; }; ASL_Release_Cargo_Index_Action = { @@ -716,7 +690,7 @@ ASL_Advanced_Sling_Loading_Install = { _allRopes set [_ropeIndex, []]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; }; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; if (count _activeRopes == 0) then { _vehicle setVariable ["ASL_Ropes", nil, true]; }; @@ -777,7 +751,7 @@ ASL_Advanced_Sling_Loading_Install = { _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; true }; - private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; + private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; if (count _existingRopes > 0 && (count _existingRopes) == (count _activeRopes)) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 6"]; false @@ -794,7 +768,9 @@ ASL_Advanced_Sling_Loading_Install = { [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; }; ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + // private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; + private _inactiveRopes = [_vehicle, false] call ASL_Get_Active_Ropes; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _inactiveRopes: ", _inactiveRopes]; if (count _inactiveRopes > 0) exitWith { if (count _inactiveRopes > 1) then { @@ -897,7 +873,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {}; if (_vehicle getVariable ["ASL_Vehicle_Rope_Monitor", false]) exitWith {}; // leave, if vehicle is already monitoring rope ends _vehicle setVariable ["ASL_Vehicle_Rope_Monitor", true, true]; - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _vehicle: ", _vehicle, ", started rope end monitoring"]; + diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _vehicle: ", _vehicle, ", started rope end monitoring"]; private ["_allRopes", "_ropeBundle", "_rope", "_nearbyUnits", "_unitRopes"]; while {alive _vehicle && !(isNil{_vehicle getVariable "ASL_Ropes"})} do { _allRopes = _vehicle getVariable ["ASL_Ropes", []]; @@ -1400,7 +1376,7 @@ if (isServer) then { if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes - if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // distance in meter a unit has to be from a rope end to be able to pick up the rope + if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // maximum distance in meter a unit has to be from a rope end to be able to pick up the rope if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index cea8c07..99e7ecb 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -192,6 +192,10 @@ All Alle + + + Cargo + Fracht Ropes From 38117765e5c502cbf837ba086fa681bac3ee9e88 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 7 May 2021 12:39:10 +0200 Subject: [PATCH 17/24] - weekend playtest version - added messages regarding rope length changes - added new option 'extend to ground' - various bugfixes - various syntax changes --- .../functions/fn_advancedSlingLoadingInit.sqf | 625 +++++++++++------- .../scripts/XEH_preInit.sqf | 41 +- .../NIC_AdvancedSlingLoading/stringtable.xml | 33 +- 3 files changed, 451 insertions(+), 248 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 0309361..38b034c 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -26,7 +26,8 @@ ASL_Advanced_Sling_Loading_Install = { diag_log "Advanced Sling Loading Loading..."; ASL_Rope_Get_Lift_Capability = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); if (_slingLoadMaxCargoMass <= 0) then { _slingLoadMaxCargoMass = ASL_DefaultLiftableMass; @@ -44,7 +45,8 @@ ASL_Advanced_Sling_Loading_Install = { ]; ASL_Get_Sling_Load_Points = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; private _slingLoadPointsArray = []; private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); @@ -127,7 +129,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Corner_Points = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; private _widthFactor = 0.5; private _lengthFactor = 0.5; if (_vehicle isKindOf "Air") then { // Correct width and length factor for air @@ -155,44 +158,45 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Rope_Set_Mass = { - private _obj = [_this, 0] call BIS_fnc_param; + private _object = [_this, 0] call BIS_fnc_param; private _mass = [_this, 1] call BIS_fnc_param; - _obj setMass _mass; + _object setMass _mass; }; ASL_Rope_Adjust_Mass = { - params ["_obj", "_heli", ["_ropes", []]]; - private _lift = [_heli] call ASL_Rope_Get_Lift_Capability; + params [["_object", objNull], ["_vehicle", objNull], ["_ropes", []]]; + if (isNull _object || isNull _vehicle) exitWith {}; + private _lift = [_vehicle] call ASL_Rope_Get_Lift_Capability; private _maxLiftableMass = _lift * ASL_MaxLiftableMassFactor; - private _originalMass = getMass _obj; + private _originalMass = getMass _object; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; // diag_log formatText [ // "%1%2%3%4%5%6%7%8%9%10%11", time, - // "s (ASL_Rope_Adjust_Mass) _obj: ", _obj, + // "s (ASL_Rope_Adjust_Mass) _object: ", _object, // " _originalMass: ", _originalMass, - // " _heli: ", _heli, + // " _vehicle: ", _vehicle, // " _lift: ", _lift, // " _heavyLiftMinLift: ", _heavyLiftMinLift // ]; if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { - private _originalMassSet = (getMass _obj) == _originalMass; + private _originalMassSet = (getMass _object) == _originalMass; private ["_ends", "_endDistance", "_ropeLength"]; - while {_obj in (ropeAttachedObjects _heli) && _originalMassSet} do { + while {_object in (ropeAttachedObjects _vehicle) && _originalMassSet} do { { _ends = ropeEndPosition _x; _endDistance = (_ends select 0) distance (_ends select 1); _ropeLength = ropeLength _x; - if ((_ropeLength - 2) <= _endDistance && ((position _heli) select 2) > 0) then { - [[_obj, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + if ((_ropeLength - 2) <= _endDistance && ((position _vehicle) select 2) > 0) then { + [[_object, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _object, true] call ASL_RemoteExec; _originalMassSet = false; }; } forEach _ropes; sleep 0.1; }; - while {_obj in (ropeAttachedObjects _heli)} do { + while {_object in (ropeAttachedObjects _vehicle)} do { sleep 0.5; }; - [[_obj, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + [[_object, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; }; }; @@ -224,16 +228,15 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Get_Active_Ropes_With_Cargo = { params [["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; private _activeRopesWithCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - // private _activeRopes = _this call ASL_Get_Active_Ropes; - // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); if (!isNull _cargo) then { - if ((!alive _cargo || ropeAttachedTo _cargo != _vehicle) && !isNull _unit) exitWith { + if (!alive _cargo || ropeAttachedTo _cargo != _vehicle) exitWith { [_vehicle, _unit, _foreachindex] call ASL_Release_Cargo; // in case cargo destroyed }; _activeRopesWithCargo pushBack _x; @@ -243,12 +246,12 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Active_Ropes_Without_Cargo = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; private _activeRopesWithoutCargo = []; private _existingCargo = _vehicle getVariable ["ASL_Cargo", []]; - // private _activeRopes = _this call ASL_Get_Active_Ropes; - // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Active_Ropes_Without_Cargo) _vehicle: ", _vehicle, ", _existingCargo: ", _existingCargo, ", _activeRopes: ", _activeRopes]; private ["_cargo"]; { _cargo = _existingCargo select (_x select 0); @@ -256,58 +259,65 @@ ASL_Advanced_Sling_Loading_Install = { _activeRopesWithoutCargo pushBack _x; }; } forEach _activeRopes; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Active_Ropes_Without_Cargo) _activeRopesWithoutCargo: ", _activeRopesWithoutCargo]; _activeRopesWithoutCargo; }; ASL_Get_Ropes = { - params ["_vehicle", "_ropeIndex"]; + params [["_vehicle", objNull], "_ropesIndex"]; + if (isNull _vehicle) exitWith {}; private _selectedRopes = []; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - if (count _allRopes > _ropeIndex) then { - _selectedRopes = _allRopes select _ropeIndex; + if (count _allRopes > _ropesIndex) then { + _selectedRopes = _allRopes select _ropesIndex; }; _selectedRopes; }; ASL_Get_Ropes_Count = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; count (_vehicle getVariable ["ASL_Ropes", []]); }; ASL_Get_Cargo = { - params ["_vehicle", "_ropeIndex"]; + params [["_vehicle", objNull], "_ropesIndex"]; + if (isNull _vehicle) exitWith {}; private _selectedCargo = objNull; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - if (count _allCargo > _ropeIndex) then { - _selectedCargo = _allCargo select _ropeIndex; + if (count _allCargo > _ropesIndex) then { + _selectedCargo = _allCargo select _ropesIndex; }; _selectedCargo; }; ASL_Get_Ropes_And_Cargo = { - params ["_vehicle", "_ropeIndex"]; + params [["_vehicle", objNull], "_ropesIndex"]; + if (isNull _vehicle) exitWith {}; private _selectedCargo = (_this call ASL_Get_Cargo); private _selectedRopes = (_this call ASL_Get_Ropes); [_selectedRopes, _selectedCargo]; }; ASL_Extend_Ropes_Action_Check = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull], ["_toGround", false]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; - [getConnectedUAV _unit] call ASL_Can_Extend_Ropes + [getConnectedUAV _unit, _toGround] call ASL_Can_Extend_Ropes }; if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; - [_vehicle] call ASL_Can_Extend_Ropes + [_vehicle, _toGround] call ASL_Can_Extend_Ropes }; false }; ASL_Is_Unit_Authorized = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Unit_Authorized) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if (driver _vehicle == _unit && ASL_PilotsAuthorized || gunner _vehicle == _unit && ASL_GunnersAuthorized || _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) @@ -326,93 +336,199 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Can_Extend_Ropes = { - params ["_vehicle"]; + params [["_vehicle", objNull], ["_toGround", false]]; + if (isNull _vehicle) exitWith {false}; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; - if (count (_vehicle getVariable ["ASL_Ropes", []]) == 0) exitWith {false}; + private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + if (count _allRopes == 0) exitWith {false}; if (count ([_vehicle, true] call ASL_Get_Active_Ropes) == 0) exitWith {false}; + private _exit = false; + if (_toGround) then { + // private _ropeEndHeight = ropeEndPosition (_allRopes #0 #0) #1 #2; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Extend_Ropes) _vehicleHeight: ", _vehicleHeight, ", _ropeEndHeight: ", _ropeEndHeight]; + // if (_ropeEndHeight < ASL_ExtendShortenRopeLength) exitWith {_exit = true}; + if (ropeEndPosition (_allRopes #0 #0) #1 #2 < ASL_ExtendShortenRopeLength) exitWith {_exit = true}; + private _vehicleHeight = getPos _vehicle #2; + if (_vehicleHeight < ASL_ExtendShortenRopeLength || _vehicleHeight > ASL_MaxRopeLength) then {_exit = true}; + }; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Extend_Ropes) _vehicle: ", _vehicle, " _toGround: ", _toGround]; + if (_exit) exitWith {false}; true; }; ASL_Extend_Ropes_Action = { - params [["_vehicle", objNull], "_unit"]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; - if (isNull _vehicle) exitWith {false}; - if !([_vehicle] call ASL_Can_Extend_Ropes) exitWith {false}; + params [["_vehicle", objNull], ["_unit", objNull], ["_toGround", false]]; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _toGround: ", _toGround]; + if (isNull _vehicle || isNull _unit) exitWith {}; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; + private _canReleaseCargo = false; + if (_toGround) then { + _canReleaseCargo = [_vehicle, _unit] call ASL_Can_Release_Cargo; + }; + private ["_messageText"]; if (count _activeRopes == 1) exitWith { - private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Extend_Ropes; + private _ropeLength = [_vehicle, _activeRopes #0 #0, _toGround] call ASL_Extend_Ropes; if (_ropeLength <= ASL_MaxRopeLength) exitWith { - private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + // private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + if (_toGround) then {_messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO_G", _ropeLength]}; if (_ropeLength == ASL_MaxRopeLength) then { _messageText = formatText ["%1%2", _messageText, " (max)"]; }; - hint _messageText; + if (ASL_RopeMessagesAuthorized) then {hint _messageText}; + diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; + if (_toGround && _canReleaseCargo) then { + private _rope = (_vehicle getVariable "ASL_Ropes") #0 #0; + private _cargo = (_vehicle getVariable "ASL_Cargo") #0; + [_vehicle, _unit, _rope, _ropeLength, _cargo] spawn ASL_Release_Cargo_Near_Ground; + }; }; + if (!ASL_RopeMessagesAuthorized) exitWith {}; hint format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]; }; - _unit setVariable ["ASL_Extend_Index_Vehicle", _vehicle]; - ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_EXTEND"], "ASL_Extend_Ropes_Index_Action", _activeRopes, format[localize "STR_ASL_ROPE"], _vehicle, _unit, _toGround] call ASL_Show_Select_Ropes_Menu; private _extendedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; - if (count _extendedRopes > 0) then { - private _messageText = format[localize "STR_ASL_ROPES_EXTENDED"]; - { - if (_x select 1 <= ASL_MaxRopeLength) then { - _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_EXTENDED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; - if (_x select 1 == ASL_MaxRopeLength) then { - _messageText = formatText ["%1%2", _messageText, " (max)"]; - }; - } else { - _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]]; - }; - } forEach _extendedRopes; - _messageText setAttributes ["align", "left"]; - hint composeText [_messageText]; - _vehicle setVariable ["ASL_Ropes_Change", nil]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Action) _extendedRopes: ", _extendedRopes, ", _activeRopes: ", _activeRopes]; + if (count _extendedRopes == 0) exitWith {}; + private ["_extendedRopeIndex", "_activeCargoRopes"]; + _messageText = format[localize "STR_ASL_ROPES_EXTENDED"]; + if (_toGround) then { + // _messageText = formatText ["%1%2%3", _messageText, " ", format[localize "STR_ASL_ROPES_EXTENDED_TG"]]; + _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TG", _messageText]; + _activeCargoRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; }; + { + if (_x #1 <= ASL_MaxRopeLength) then { + _extendedRopeIndex = _x #0; + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_EXTENDED_TO_IND", (_activeRopes select {_x #0 == _extendedRopeIndex}) #0 #1, _x #1]]; + if (_x #1 == ASL_MaxRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (max)"]; + }; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9", time, + "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo, + ", _extendedRopeIndex: ", _extendedRopeIndex + ]; + if (_toGround && _canReleaseCargo) then { + private _rope = (_vehicle getVariable "ASL_Ropes") #_extendedRopeIndex #0; + private _cargo = (_vehicle getVariable "ASL_Cargo") #_extendedRopeIndex; + [_vehicle, _unit, _rope, _x #1, _cargo, _extendedRopeIndex] spawn ASL_Release_Cargo_Near_Ground; + }; + } else { + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]]; + }; + } forEach _extendedRopes; + _messageText setAttributes ["align", "left"]; + if (ASL_RopeMessagesAuthorized) then {hint composeText [_messageText]}; + _vehicle setVariable ["ASL_Ropes_Change", nil]; }; + ASL_Release_Cargo_Near_Ground = { + params [["_vehicle", objNull], ["_unit", objNull], ["_rope", objNull], ["_ropeLength", 0], ["_cargo", objNull], ["_ropesIndex", 0]]; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + "s (ASL_Release_Cargo_Near_Ground) _vehicle: ", _vehicle, + ", _unit: ", _unit, + ", _rope: ", _rope, + ", _ropeLength: ", _ropeLength, + ", _cargo: ", _cargo + ]; + if (isNull _vehicle || isNull _unit || isNull _rope || _ropeLength == 0 || isNull _cargo) exitWith {}; + private _future = time + 60; + sleep 1; + while { + !ropeUnwound _rope && + alive _vehicle && + time < _future && + ropeLength _rope < _ropeLength && + alive _cargo && + getPos _cargo #2 > 1 + } do {sleep 1}; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + "s (ASL_Release_Cargo_Near_Ground) EXIT LOOP! ropeUnwound: ", !ropeUnwound _rope, + ", alive _vehicle: ", alive _vehicle, + ", time < _future: ", time < _future, + ", ropeLength _rope < _ropeLength: ", ropeLength _rope < _ropeLength, + ", alive _cargo: ", alive _cargo, + ", getPos _cargo #2 > 1: ", getPos _cargo #2 > 1 + ]; + if (!alive _vehicle || (getPos _cargo #2 > 5 && alive _cargo)) exitWith {}; + // [_vehicle, _unit] call ASL_Release_Cargo_Action; + [_ropesIndex, _vehicle, _unit] call ASL_Release_Cargo_Index_Action; + }; + ASL_Show_Select_Ropes_Menu = { - params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", format[localize "STR_ASL_ROPE"]]]; + params ["_title", "_functionName", "_ropesIndexAndLabelArray", ["_ropesLabel", format[localize "STR_ASL_ROPE"]], ["_vehicle", objNull], ["_unit", objNull], ["_toGround", false]]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10%11%12%13%14%15", time, "s (ASL_Show_Select_Ropes_Menu) _title: ", _title, ", _functionName: ", _functionName, ", _ropesIndexAndLabelArray: ", _ropesIndexAndLabelArray, ", _ropesLabel: ", _ropesLabel, ", _vehicle: ", _vehicle, ", _unit: ", _unit, ", _toGround: ", _toGround]; + if (isNull _vehicle || isNull _unit) exitWith {}; ASL_Show_Select_Ropes_Menu_Array = [[_title, false]]; + ASL_Vehicle = _vehicle; + ASL_Unit = _unit; + ASL_toGround = _toGround; { - ASL_Show_Select_Ropes_Menu_Array pushBack [(_x select 1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+"] call " + _functionName]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [(_x #1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+", ASL_Vehicle, ASL_Unit, ASL_toGround] call " + _functionName]], "1", "1"]; } forEach _ropesIndexAndLabelArray; - ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x] call " + _functionName + "} forEach [0, 1, 2];"]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x, ASL_Vehicle, ASL_Unit, ASL_toGround] call " + _functionName + "} forEach [0, 1, 2];"]], "1", "1"]; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Show_Select_Ropes_Menu_Array"; waitUntil {commandingMenu == ""}; }; ASL_Extend_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Extend_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Extend_Ropes) then { - private _ropeLength = [_vehicle, _ropeIndex] call ASL_Extend_Ropes; - [_vehicle, _ropeLength, _ropeIndex] call ASL_Save_Rope_Change; + params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull], ["_toGround", false]]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Index_Action) _ropesIndex: ", _ropesIndex, ", _vehicle: ", _vehicle, ", _unit: ", _unit, ", _toGround: ", _toGround]; + if (isNull _vehicle || isNull _unit) exitWith {}; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, _toGround] call ASL_Can_Extend_Ropes) then { + private _ropeLength = [_vehicle, _ropesIndex, _toGround] call ASL_Extend_Ropes; + [_vehicle, _ropeLength, _ropesIndex] call ASL_Save_Rope_Change; }; }; ASL_Save_Rope_Change = { - params [["_vehicle", objNull], ["_ropeLength", 0], ["_ropeIndex", 0]]; + params [["_vehicle", objNull], ["_ropeLength", 0], ["_ropesIndex", 0]]; if (isNull _vehicle) exitWith {}; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Save_Rope_Change) _ropeLength: ", _ropeLength, ", _ropesIndex: ", _ropesIndex]; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + if (count _existingRopes == 0 || _ropeLength == 0) exitWith {}; private _changedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; - _changedRopes pushBack [_ropeIndex, _ropeLength]; + _changedRopes pushBack [_ropesIndex, _ropeLength]; _vehicle setVariable ["ASL_Ropes_Change", _changedRopes]; }; - + ASL_Extend_Ropes = { - params ["_vehicle", ["_ropeIndex", 0]]; + params [["_vehicle", objNull], ["_ropesIndex", 0], ["_toGround", false]]; + if (isNull _vehicle) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec}; - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (count _existingRopes == 0) exitWith {0}; private _ropeLength = ropeLength (_existingRopes select 0); if (_ropeLength >= ASL_MaxRopeLength) exitWith {ASL_MaxRopeLength + 1}; private _unwindLength = ASL_ExtendShortenRopeLength; + if (_toGround) then { + _unwindLength = ceil((getPos _vehicle select 2) - _ropeLength + 5); + /* + 'getPos' will return the height of the vehicle above the next object underneath. + So, if the vehicle has a sling load, it is likely the height will be measured false + from vehicle to the sling load underneath. If there is a cargo, recalculate unwind + length from sling load to ground. + */ + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + private _cargo = _allCargo #_ropesIndex; + if (isNull _cargo) exitWith {}; + _unwindLength = ceil(getPos _cargo select 2) + 3; + }; if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { _unwindLength = ASL_MaxRopeLength - _ropeLength; }; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + "s (ASL_Extend_Ropes) _unwindLength: ", _unwindLength, + ", vehicle height: ", getPos _vehicle select 2, + ", ASL_MaxRopeLength: ", ASL_MaxRopeLength, + ", _ropeLength: ", _ropeLength, + ", _ropesIndex: ", _ropesIndex + ]; { ropeUnwind [_x, 3, _unwindLength, true]; } forEach _existingRopes; @@ -421,8 +537,9 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Shorten_Ropes_Action_Check = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; [getConnectedUAV _unit] call ASL_Can_Shorten_Ropes @@ -433,9 +550,11 @@ ASL_Advanced_Sling_Loading_Install = { }; false }; - + ASL_Can_Shorten_Ropes = { params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {false}; if (count (_vehicle getVariable ["ASL_Ropes", []]) == 0) exitWith {false}; if (count ([_vehicle, true] call ASL_Get_Active_Ropes) == 0) exitWith {false}; @@ -443,14 +562,14 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Shorten_Ropes_Action = { - params [["_vehicle", objNull], "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; - if (isNull _vehicle) exitWith {false}; + if (isNull _vehicle || isNull _unit) exitWith {false}; if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; - // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; if (count _activeRopes == 1) exitWith { - private _ropeLength = [_vehicle, (_activeRopes select 0) select 0] call ASL_Shorten_Ropes; + private _ropeLength = [_vehicle, _activeRopes #0 #0] call ASL_Shorten_Ropes; + if (!ASL_RopeMessagesAuthorized) exitWith {}; if (_ropeLength >= ASL_MinRopeLength) exitWith { private _messageText = format[localize "STR_ASL_ROPES_SHORTENED_TO", _ropeLength]; if (_ropeLength == ASL_MinRopeLength) then { @@ -460,16 +579,17 @@ ASL_Advanced_Sling_Loading_Install = { }; hint format[localize "STR_ASL_ALREADY_MIN_LENGTH", ASL_MinRopeLength]; }; - _unit setVariable ["ASL_Shorten_Index_Vehicle", _vehicle]; - ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_SHORTEN"], "ASL_Shorten_Ropes_Index_Action", _activeRopes, format[localize "STR_ASL_ROPE"], _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; private _shortenedRopes = _vehicle getVariable ["ASL_Ropes_Change", []]; if (count _shortenedRopes > 0) then { private _messageText = format[localize "STR_ASL_ROPES_SHORTENED"]; + private ["_shortenedRopesIndex"]; { - if (_x select 1 >= ASL_MinRopeLength) then { - _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; - if (_x select 1 == ASL_MinRopeLength) then { + if (_x #1 >= ASL_MinRopeLength) then { + _shortenedRopesIndex = _x#0; + // _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", (_activeRopes select {_x#0 == _shortenedRopesIndex})#0#1, _x#1]]; + if (_x #1 == ASL_MinRopeLength) then { _messageText = formatText ["%1%2", _messageText, " (min)"]; }; } else { @@ -477,25 +597,25 @@ ASL_Advanced_Sling_Loading_Install = { }; } forEach _shortenedRopes; _messageText setAttributes ["align", "left"]; - hint composeText [_messageText]; + if (ASL_RopeMessagesAuthorized) then {hint composeText [_messageText]}; _vehicle setVariable ["ASL_Ropes_Change", nil]; }; }; ASL_Shorten_Ropes_Index_Action = { - params ["_ropeIndex"]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Shorten_Index_Vehicle", objNull]; - if (_ropeIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { - private _ropeLength = [_vehicle, _ropeIndex] call ASL_Shorten_Ropes; - [_vehicle, _ropeLength, _ropeIndex] call ASL_Save_Rope_Change; + params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {}; + if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { + private _ropeLength = [_vehicle, _ropesIndex] call ASL_Shorten_Ropes; + [_vehicle, _ropeLength, _ropesIndex] call ASL_Save_Rope_Change; }; }; - + ASL_Shorten_Ropes = { - params ["_vehicle", ["_ropeIndex", 0]]; + params [["_vehicle", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle) exitWith {}; if !(local _vehicle) exitWith {[_this,"ASL_Shorten_Ropes", _vehicle, true] call ASL_RemoteExec}; - private _existingRopes = [_vehicle, _ropeIndex] call ASL_Get_Ropes; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; private _ropeLength = -1; if (count _existingRopes > 0) then { _ropeLength = ropeLength (_existingRopes select 0); @@ -519,11 +639,12 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Release_Cargo_Action_Check = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 1, can release: ", [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo]; - [getConnectedUAV _unit] call ASL_Can_Release_Cargo + [getConnectedUAV _unit, _unit] call ASL_Can_Release_Cargo }; if (vehicle _unit == _vehicle && [_vehicle, _unit] call ASL_Is_Unit_Authorized) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action_Check) EXIT 2, can release: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; @@ -534,6 +655,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Release_Cargo = { params [["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Release_Cargo) EXIT 1"]; false @@ -554,32 +676,30 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo_Action = { params [["_vehicle", objNull], ["_unit", objNull]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; - if (isNull _vehicle) exitWith {false}; - if !([_vehicle] call ASL_Can_Release_Cargo) exitWith {false}; - // private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_With_Cargo; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + if (isNull _vehicle || isNull _unit) exitWith {false}; + if !([_vehicle, _unit] call ASL_Can_Release_Cargo) exitWith {false}; private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; if (count _activeRopes == 1) exitWith { [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo }; - _unit setVariable ["ASL_Release_Cargo_Index_Vehicle", _vehicle]; - ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, format[localize "STR_ASL_CARGO"]] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, format[localize "STR_ASL_CARGO"], _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; }; ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex"]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Release_Cargo_Index_Vehicle", objNull]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Release_Cargo) then { + params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo_Index_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; + if (isNull _vehicle || isNull _unit) exitWith {}; + if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Release_Cargo) then { [_vehicle, _unit, _ropesIndex] call ASL_Release_Cargo; }; }; ASL_Release_Cargo = { - params ["_vehicle", "_unit", ["_ropeIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; - private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; private _existingCargo = _existingRopesAndCargo select 1; { @@ -587,13 +707,14 @@ ASL_Advanced_Sling_Loading_Install = { } forEach _existingRopes; _existingCargo setVariable ["ASL_RopesIndex", nil, true]; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [_ropeIndex, objNull]; + _allCargo set [_ropesIndex, objNull]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; _this call ASL_Retract_Ropes; }; ASL_Retract_Ropes_Action_Check = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action_Check) EXIT 1"]; @@ -611,7 +732,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Can_Retract_Ropes = { - params ["_vehicle", "_unit", ["_distanceCheck", false]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_distanceCheck", false]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 1"]; false @@ -634,60 +756,74 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Retract_Ropes_Action = { - params [["_vehicle", objNull], "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; - if (isNull _vehicle) exitWith {false}; + if (isNull _vehicle || isNull _unit) exitWith {}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; - if (count _activeRopes == 1) exitWith { + if (count _activeRopes == 1) exitWith { + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) inactive ropes: ", [_vehicle] call ASL_Get_Active_Ropes, ", existing ropes: ", _vehicle getVariable ["ASL_Ropes", []]]; [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; + if (!ASL_RopeMessagesAuthorized) exitWith {}; + hint format[localize "STR_ASL_ROPES_RETRACTED"]; + [] spawn { + sleep 3; + hintSilent ""; + }; }; - _unit setVariable ["ASL_Retract_Ropes_Index_Vehicle", _vehicle]; - ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - [format[localize "STR_ASL_RETRACT"], "ASL_Retract_Ropes_Index_Action", _activeRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_RETRACT"], "ASL_Retract_Ropes_Index_Action", _activeRopes, format[localize "STR_ASL_ROPE"], _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; }; ASL_Retract_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Retract_Ropes_Index_Vehicle", objNull]; + params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Retract_Ropes_Index_Action) _unit: ", _unit, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; - if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Retract_Ropes) then { + if (isNull _vehicle || isNull _unit) exitWith {}; + // if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Retract_Ropes) then { + if (_ropesIndex >= 0) then { [_vehicle, _unit, _ropesIndex] call ASL_Retract_Ropes; }; }; - + ASL_Retract_Ropes = { - params ["_vehicle", "_unit", ["_ropeIndex", 0]]; + // params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0], ["_hadCargo", false]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec}; - private _existingRopesAndCargo = [_vehicle, _ropeIndex] call ASL_Get_Ropes_And_Cargo; + private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; private _existingCargo = _existingRopesAndCargo select 1; private _cargoArray = ropeAttachedObjects _vehicle; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _vehicle: ", _vehicle, " _cargoArray: ", _cargoArray]; if (count _cargoArray > 0) then { private _helper = (_cargoArray select {_x getVariable ["ASL_Ropes_Pick_Up_Helper", false]}) select 0; - if (!isNull _helper) then { - private _ropeHolder = attachedTo _helper; - if (!isNull _ropeHolder) then {_unit = _ropeHolder}; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _helper: ", _helper, " _ropeHolder: ", _ropeHolder]; - }; + if (isNil {_helper}) exitWith {}; + // if (!isNull _helper) then { + private _ropeHolder = attachedTo _helper; + if (!isNull _ropeHolder) then {_unit = _ropeHolder}; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _helper: ", _helper, " _ropeHolder: ", _ropeHolder]; + // }; }; if (isNull _existingCargo) then { - [_vehicle, _unit, _ropeIndex] call ASL_Drop_Ropes; + [_vehicle, _unit, _ropesIndex] call ASL_Drop_Ropes; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11%12", time, + "s (ASL_Retract_Ropes) _existingRopes: ", _existingRopes, + // ", Ropes_Without_Cargo: ", [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo, + // ", _allRopes: ", _vehicle getVariable ["ASL_Ropes", []], + ", _activeRopes: ", [_vehicle, true] call ASL_Get_Active_Ropes, + ", _inactiveRopes: ", [_vehicle] call ASL_Get_Active_Ropes + ]; { - [_x] spawn { - params ["_rope"]; - private _count = 0; + [_x, _vehicle] spawn { + params ["_rope", "_vehicle"]; + if (isNull _rope || isNull _vehicle) exitWith {}; + private _future = time + 25; ropeUnwind [_rope, 3, 0]; - while {(!ropeUnwound _rope) && _count < 20} do { - sleep 1; - _count = _count + 1; - }; + while {!ropeUnwound _rope && alive _vehicle && time < _future} do {sleep 1}; ropeDestroy _rope; }; } forEach _existingRopes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - _allRopes set [_ropeIndex, []]; + _allRopes set [_ropesIndex, []]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; }; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; @@ -697,9 +833,9 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit = { - params ["_UAV", "_unit"]; + params [["_UAV", objNull], ["_unit", objNull]]; + if (isNull _UAV || isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) _UAV: ", _UAV, " _unit: ", _unit]; - if (isNull _UAV) exitWith {false}; if (UAVControl _UAV select 0 == _unit && (UAVControl _UAV select 1 == "GUNNER" || UAVControl _UAV select 1 == "DRIVER")) exitWith { // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) EXIT 1: unit is UAV gunner or driver"]; true @@ -708,7 +844,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Deploy_Ropes_Action_Check = { - params ["_vehicle", "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; if ([getConnectedUAV _unit, _unit] call ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) EXIT 1"]; @@ -726,8 +863,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Can_Deploy_Ropes = { - params ["_vehicle", "_unit", ["_distanceCheck", false]]; - _unit setVariable ["ASL_TargetDeployVehicle", nil]; + params [["_vehicle", objNull], ["_unit", objNull], ["_distanceCheck", false]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 1"]; false @@ -741,14 +878,13 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 3"]; false }; - _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; if (getPos _vehicle select 2 > ASL_MaxRopeDeployHeight) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 4"]; false }; + _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; if (count _existingRopes == 0) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 5"]; - _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; true }; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; @@ -756,26 +892,22 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 6"]; false }; - _unit setVariable ["ASL_TargetDeployVehicle", _vehicle]; true }; ASL_Deploy_Ropes_Action = { - params [["_vehicle", objNull], "_unit"]; + params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _this: ", _this]; - if (isNull _vehicle) exitWith {false}; + if (isNull _vehicle || isNull _unit) exitWith {}; if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANNOT_DEPLOY"], false] call ASL_Hint; }; - ASL_ParamMenuUnit = _unit; // this ugly workaround is because there is NO way passing the 'caller' of the menu to the menu itself - // private _inactiveRopes = [_vehicle] call ASL_Get_Inactive_Ropes; - private _inactiveRopes = [_vehicle, false] call ASL_Get_Active_Ropes; + private _inactiveRopes = [_vehicle] call ASL_Get_Active_Ropes; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action) _inactiveRopes: ", _inactiveRopes]; if (count _inactiveRopes > 0) exitWith { if (count _inactiveRopes > 1) then { - _unit setVariable ["ASL_Deploy_Ropes_Index_Vehicle", _vehicle]; - [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes] call ASL_Show_Select_Ropes_Menu; + [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes, _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; } else { [_vehicle, _unit, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; }; @@ -785,42 +917,40 @@ ASL_Advanced_Sling_Loading_Install = { if (count _slingLoadPoints == 1) exitWith { [_vehicle, _unit] call ASL_Deploy_Ropes; }; - _unit setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; - ASL_Deploy_Ropes_Count_Menu = [ - [format[localize "STR_ASL_ROPES"], false] - ]; - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_SINGLE"], [0], "", -5, [["expression", "[1] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + // _unit setVariable ["ASL_Deploy_Count_Vehicle", _vehicle]; + ASL_Deploy_Ropes_Count_Menu = [[format[localize "STR_ASL_ROPES"], false]]; + ASL_Vehicle = _vehicle; + ASL_Unit = _unit; + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_SINGLE"], [0], "", -5, [["expression", "[1, ASL_Vehicle, ASL_Unit] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; if (count _slingLoadPoints > 1) then { - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_DOUBLE"], [0], "", -5, [["expression", "[2] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_DOUBLE"], [0], "", -5, [["expression", "[2, ASL_Vehicle, ASL_Unit] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; }; if (count _slingLoadPoints > 2) then { - ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_TRIPLE"], [0], "", -5, [["expression", "[3] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; + ASL_Deploy_Ropes_Count_Menu pushBack [format[localize "STR_ASL_TRIPLE"], [0], "", -5, [["expression", "[3, ASL_Vehicle, ASL_Unit] call ASL_Deploy_Ropes_Count_Action"]], "1", "1"]; }; showCommandingMenu ""; showCommandingMenu "#USER:ASL_Deploy_Ropes_Count_Menu"; }; ASL_Deploy_Ropes_Index_Action = { - params ["_ropesIndex"]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Deploy_Ropes_Index_Vehicle", objNull]; + params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle, _unit] call ASL_Can_Deploy_Ropes) then { [_vehicle, _unit, _ropesIndex] call ASL_Deploy_Ropes_Index; }; }; - + ASL_Deploy_Ropes_Count_Action = { - params ["_count"]; + params ["_count", ["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Deploy_Ropes_Count_Action) _count: ", _count, ", ASL_ParamMenuUnit: ", ASL_ParamMenuUnit]; - private _unit = ASL_ParamMenuUnit; - private _vehicle = _unit getVariable ["ASL_Deploy_Count_Vehicle", objNull]; if (_count > 0 && !isNull _vehicle && [_vehicle, _unit] call ASL_Can_Deploy_Ropes) then { [_vehicle, _unit, _count] call ASL_Deploy_Ropes; }; }; - + ASL_Deploy_Ropes = { - params ["_vehicle", "_unit", ["_cargoCount", 1]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_cargoCount", 1]]; + if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; if (count _existingRopes > 0) exitWith { @@ -847,7 +977,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Deploy_Ropes_Index = { - params ["_vehicle", "_unit", ["_ropesIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes_Index", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (count _existingRopes > 0) exitWith {}; @@ -865,6 +996,7 @@ ASL_Advanced_Sling_Loading_Install = { _allRopes set [_ropesIndex, _cargoRopes]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; [_vehicle] spawn ASL_Rope_Monitor_Vehicle; + if (!ASL_RopeMessagesAuthorized) exitWith {}; hint format[localize "STR_ASL_ROPES_DEPLOYED", ASL_InitialDeployRopeLength]; }; @@ -873,7 +1005,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {}; if (_vehicle getVariable ["ASL_Vehicle_Rope_Monitor", false]) exitWith {}; // leave, if vehicle is already monitoring rope ends _vehicle setVariable ["ASL_Vehicle_Rope_Monitor", true, true]; - diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _vehicle: ", _vehicle, ", started rope end monitoring"]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Vehicle) _vehicle: ", _vehicle, ", started rope end monitoring"]; private ["_allRopes", "_ropeBundle", "_rope", "_nearbyUnits", "_unitRopes"]; while {alive _vehicle && !(isNil{_vehicle getVariable "ASL_Ropes"})} do { _allRopes = _vehicle getVariable ["ASL_Ropes", []]; @@ -904,8 +1036,8 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; if (_unit getVariable ["ASL_Unit_Rope_Monitor", false]) exitWith {}; // leave, if unit is already monitoring ror rope ends - _unit setVariable ["ASL_Unit_Rope_Monitor", true, true]; // raise unit rope monitor flag - // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; + _unit setVariable ["ASL_Unit_Rope_Monitor", true]; // raise unit rope monitor flag + diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; if (isNil{_unit getVariable "ASL_ActionID_Pickup"}) then { // add pickup action to unit private _actionID = _unit addAction [ format[localize "STR_ASL_PICKUP"], // Title @@ -1000,7 +1132,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Pickup_Ropes = { - params ["_vehicle", "_unit", ["_ropesIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; private _existingRopes = _existingRopesAndCargo select 0; @@ -1056,12 +1189,16 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _unit) exitWith {false}; private _cargo = cursorTarget; private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; - private _ropeHandlingDistance = ASL_RopeHandlingDistance; - if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; - - // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; - [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < _ropeHandlingDistance && _vehicle != _cargo; + if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; // AI gets a higher range, as AI's do not get close enough to vehicles + // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; + if (vehicle _unit != _unit || _unit distance _cargo > _ropeHandlingDistance || _vehicle == _cargo || !alive _cargo) exitWith {false}; + [_vehicle, _cargo] call ASL_Is_Supported_Cargo + // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && + // vehicle _unit == _unit && + // _unit distance _cargo < _ropeHandlingDistance && + // _vehicle != _cargo && + // alive _cargo; }; ASL_Attach_Ropes_Action = { @@ -1087,7 +1224,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Attach_Ropes = { - params ["_cargo", ["_unit", objNull]]; + params [["_cargo", objNull], ["_unit", objNull]]; + if (isNull _cargo || isNull _unit) exitWith {}; private _vehicleWithIndex = _unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; private _vehicle = _vehicleWithIndex select 0; if (isNull _vehicle) exitWith {}; @@ -1134,7 +1272,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Drop_Ropes = { - params ["_vehicle", "_unit", ["_ropesIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); if (!isNull _helper) then { @@ -1156,7 +1295,7 @@ ASL_Advanced_Sling_Loading_Install = { ]; ASL_Is_Supported_Vehicle = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; if (isNull _vehicle) exitWith {false}; private _isSupported = false; { @@ -1170,7 +1309,7 @@ ASL_Advanced_Sling_Loading_Install = { ]; ASL_Is_Supported_Cargo = { - params ["_vehicle", "_cargo"]; + params [["_vehicle", objNull], ["_cargo", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Supported_Cargo) _vehicle: ", _vehicle, ", _cargo: ", _cargo]; if (isNull _vehicle || isNull _cargo) exitWith {false}; private _canSling = false; @@ -1200,7 +1339,8 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Add_Vehicle_Actions = { - params ["_vehicle"]; + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; private _exit = true; { if (_vehicle isKindOf _x && getMass _vehicle > ASL_MinVehicleMass) exitWith {_exit = false}; @@ -1212,79 +1352,93 @@ ASL_Advanced_Sling_Loading_Install = { private ["_actionID"]; if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_DEPLOY"], // Title - {[_this select 0, _this select 1] call ASL_Deploy_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Deploy_Ropes_Action_Check" // Condition + format[localize "STR_ASL_DEPLOY"], // Title + {[_this select 0, _this select 1] call ASL_Deploy_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Deploy_Ropes_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Deploy", _actionID]; }; if (isNil{_vehicle getVariable "ASL_ActionID_Retract"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_RETRACT"], // Title - {[_this select 0, _this select 1] call ASL_Retract_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Retract_Ropes_Action_Check" // Condition + format[localize "STR_ASL_RETRACT"], // Title + {[_this select 0, _this select 1] call ASL_Retract_Ropes_Action;}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Retract_Ropes_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Retract", _actionID]; }; if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_EXTEND"], // Title - {[_this select 0, _this select 1] call ASL_Extend_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Extend_Ropes_Action_Check" // Condition + format[localize "STR_ASL_EXTEND"], // Title + {[_this select 0, _this select 1] call ASL_Extend_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Extend_Ropes_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Extend", _actionID]; }; + if (isNil{_vehicle getVariable "ASL_ActionID_ExtendTG"}) then { + _actionID = _vehicle addAction [ + format[localize "STR_ASL_EXTEND_TG"], // Title + {[_this select 0, _this select 1, true] call ASL_Extend_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this, true] call ASL_Extend_Ropes_Action_Check" // Condition + ]; + _vehicle setVariable ["ASL_ActionID_ExtendTG", _actionID]; + }; if (isNil{_vehicle getVariable "ASL_ActionID_Shorten"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_SHORTEN"], // Title - {[_this select 0, _this select 1] call ASL_Shorten_Ropes_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Shorten_Ropes_Action_Check" // Condition + format[localize "STR_ASL_SHORTEN"], // Title + {[_this select 0, _this select 1] call ASL_Shorten_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Shorten_Ropes_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Shorten", _actionID]; }; if (isNil{_vehicle getVariable "ASL_ActionID_Release"}) then { _actionID = _vehicle addAction [ - format[localize "STR_ASL_RELEASE"], // Title - {[_this select 0, _this select 1] call ASL_Release_Cargo_Action;}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_target, _this] call ASL_Release_Cargo_Action_Check" // Condition + format[localize "STR_ASL_RELEASE"], // Title + {[_this select 0, _this select 1] call ASL_Release_Cargo_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_target, _this] call ASL_Release_Cargo_Action_Check" // Condition ]; _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; }; - + ASL_Remove_Actions = { params [["_object", objNull], ["_actions", []]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; - if (isNull _object) exitWith {false}; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; + if (isNull _object || count _actions == 0) exitWith {}; private ["_actionID"]; { - _actionID = _object getVariable _x; - if !(isNil{_actionID}) then { + _actionID = _object getVariable [_x, -1]; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) removing _actionID: ", _actionID]; + if (_actionID > -1) then { _object removeAction _actionID; _object setVariable [_x, nil]; }; @@ -1367,14 +1521,14 @@ ASL_Advanced_Sling_Loading_Install = { }; if (isServer) then { - if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter + if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter (As of Arma v2.04, this limit is hardcoded. No ropes longer than 100 m can be created or unwound) if (isNil "ASL_MinRopeLength") then {ASL_MinRopeLength = 2}; // minimum rope length in meter if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // gunners authorized to manipulate ropes if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes - if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum rope deploy height in meter + if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum height in meter the action 'Deploy Cargo Ropes' is available if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // maximum distance in meter a unit has to be from a rope end to be able to pick up the rope if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed @@ -1382,5 +1536,6 @@ if (isServer) then { if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) if (isNil "ASL_MinRopeLengthDropCargo") then {ASL_MinRopeLengthDropCargo = false}; // drop cargo, when minimum rope length is reached, and ropes are shortened once more + if (isNil "ASL_RopeMessagesAuthorized") then {ASL_RopeMessagesAuthorized = true}; // hint players informations about rope changes [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 632063d..eeca88b 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -3,8 +3,9 @@ "SLIDER", // setting type [format[localize "STR_ASL_MAX_LENGTH"], format[localize "STR_ASL_MAX_LENGTH_TIP"]], // [setting name, tooltip] format[localize "STR_ASL_TITLE"], // pretty name of the category where the setting can be found. Can be stringtable entry. - [30, 150, 100, 0], // data for this setting: [_min, _max, _default, _trailingDecimals] - true // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer + [30, 100, 100, 0], // data for this setting: [_min, _max, _default, _trailingDecimals] + true, // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer + {ASL_MaxRopeLength = round(ASL_MaxRopeLength)} // code executed on option changed AND on init ] call CBA_fnc_addSetting; [ "ASL_MaxDeployRetractDistance", @@ -12,7 +13,8 @@ [format[localize "STR_ASL_MAX_DIST"], format[localize "STR_ASL_MAX_DIST_TIP"]], format[localize "STR_ASL_TITLE"], [3, 30, 10, 0], - true + true, + {ASL_MaxDeployRetractDistance = round(ASL_MaxDeployRetractDistance)} ] call CBA_fnc_addSetting; [ "ASL_PilotsAuthorized", @@ -52,7 +54,8 @@ [format[localize "STR_ASL_MAX_DEPLOY_HEIGHT"], format[localize "STR_ASL_MAX_DEPLOY_HEIGHT_TIP"]], format[localize "STR_ASL_TITLE"], [0, 1000, 100, 0], - true + true, + {ASL_MaxRopeDeployHeight = round(ASL_MaxRopeDeployHeight)} ] call CBA_fnc_addSetting; [ "ASL_MinVehicleMass", @@ -61,15 +64,24 @@ format[localize "STR_ASL_TITLE"], [0, 2000, 0, 0], true, - {[] call ASL_Switch_Vehicles_Actions} // code executed on option changed AND on init + { + if (time < 3) exitWith {}; // the switch function is ment to run only on changes made by players, not on game init + [] call ASL_Switch_Vehicles_Actions + } ] call CBA_fnc_addSetting; [ "ASL_InitialDeployRopeLength", "SLIDER", [format[localize "STR_ASL_INITIAL_DEPLOY"], format[localize "STR_ASL_INITIAL_DEPLOY_TIP"]], format[localize "STR_ASL_TITLE"], - [5, 100, 15, 0], - true + [5, ASL_MaxRopeLength - 10, 15, 0], + true, + { + if (ASL_InitialDeployRopeLength > ASL_MaxRopeLength - 10) then { + ASL_InitialDeployRopeLength = ASL_MaxRopeLength - 10; + }; + ASL_InitialDeployRopeLength = round(ASL_InitialDeployRopeLength); + } ] call CBA_fnc_addSetting; [ "ASL_ExtendShortenRopeLength", @@ -77,7 +89,8 @@ [format[localize "STR_ASL_EXTEND_SHORTEN"], format[localize "STR_ASL_EXTEND_SHORTEN_TIP"]], format[localize "STR_ASL_TITLE"], [1, 25, 5, 0], - true + true, + {ASL_ExtendShortenRopeLength = round(ASL_ExtendShortenRopeLength)} ] call CBA_fnc_addSetting; [ "ASL_DefaultLiftableMass", @@ -93,7 +106,8 @@ [format[localize "STR_ASL_MAX_MASS"], format[localize "STR_ASL_MAX_MASS_TIP"]], format[localize "STR_ASL_TITLE"], [1, 20, 8, 0], - true + true, + {ASL_MaxLiftableMassFactor = round(ASL_MaxLiftableMassFactor)} ] call CBA_fnc_addSetting; [ "ASL_MinRopeLengthDropCargo", @@ -109,5 +123,14 @@ [format[localize "STR_ROPE_HANDLING_DIST"], format[localize "STR_ROPE_HANDLING_DIST_TIP"]], format[localize "STR_ASL_TITLE"], [2, 20, 5, 0], + true, + {ASL_RopeHandlingDistance = round(ASL_RopeHandlingDistance)} +] call CBA_fnc_addSetting; +[ + "ASL_RopeMessagesAuthorized", + "CHECKBOX", + [format[localize "STR_ROPE_MESSAGES"], format[localize "STR_ROPE_MESSAGES_TIP"]], + format[localize "STR_ASL_TITLE"], + true, true ] call CBA_fnc_addSetting; diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index 99e7ecb..b42357c 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -14,12 +14,12 @@ Maximale Seillänge in Meter vom Fahrzeug bis zur Ladung. - Maximal Deploy / Retract Range - Maximale Ausfahr- / Einfahrreichweite + Maximal Deploy / Retract Manipulation Range + Maximale Ausfahr- / Einfahrmanipulationsreichweite - When player is on foot, maximal range in meter from player to vehicle, up to whitch deploying / retracting ropes is possible. - Wenn Spieler zu Fuß ist, maximale Reichweite in Meter von Spieler zu Fahrzeug, bis zu welcher Seile Aus- oder Eingefahren werden können. + When player is on foot, maximal range in meter from player to vehicle, up to whitch external maipulation of ropes is possible (deploying / retracting). + Wenn Spieler zu Fuß ist, maximale Reichweite in Meter von Spieler zu Fahrzeug, bis zu der Seile von außerhalb manipulert werden können (Aus- oder Eingefahren). Pilots @@ -228,10 +228,18 @@ Ropes extended Seile verlängert + + + %1 to Ground + %1 auf Grund Ropes extended to %1 m Seile auf %1 m verlängert + + + Ropes extended to ground (%1 m) + Seile auf Grund verlängert (%1 m) %1 ropes %2 m @@ -280,6 +288,23 @@ Rope hanling distance in meter from a unit to a rope end. Seilmanipulationsentfernung in meter von einer Einheit zu einem Seilende. + + + Ropes Retracted + Seile Eingefahren + + + Extend Cargo Ropes To Ground + Frachtseile Bis Grund Verlängern + + + + Rope Change Messages + Seilveränderungsbenachrichtigungen + + + Show rope changes to players via hints (rope length, etc.). + Spieler erhalten per Hinweise Informationen über Seilveränderungen (Seillänge, etc.). \ No newline at end of file From a174ccf6928641b7c544f2ffe12776b26345ba13 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Fri, 21 May 2021 12:51:54 +0200 Subject: [PATCH 18/24] weekend work version --- addons/NIC_AdvancedSlingLoading/config.cpp | 33 +- .../functions/fn_advancedSlingLoadingInit.sqf | 691 ++++++++++++------ .../scripts/XEH_preInit.sqf | 43 +- .../NIC_AdvancedSlingLoading/stringtable.xml | 69 +- mod.cpp | 2 +- 5 files changed, 596 insertions(+), 242 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/config.cpp b/addons/NIC_AdvancedSlingLoading/config.cpp index 3140ca0..3d3c2a9 100644 --- a/addons/NIC_AdvancedSlingLoading/config.cpp +++ b/addons/NIC_AdvancedSlingLoading/config.cpp @@ -40,11 +40,38 @@ class CfgFunctions { }; class Extended_PreInit_EventHandlers { class SA { - init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration + init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_preInit.sqf'"; // CBA_a3 integration }; }; class Extended_PostInit_EventHandlers { class SA { - init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_postInit.sqf'"; // CBA key binding integration + init = "call compile preprocessFileLineNumbers '\SA_AdvancedSlingLoading\scripts\XEH_postInit.sqf'"; // CBA key binding integration }; -}; \ No newline at end of file +}; +class CfgSounds { + sounds[] = {}; + class SA_SlingLoadDownExt { + sound[] = {"A3\Sounds_F\vehicles\air\noises\SL_engineDownEXT", 1.2589254, 1, 500}; // filename, volume, pitch, distance (optional) + titles[] = {}; + frequency = 1; + volume = "camPos * (slingLoadActive factor [0, -1])"; + }; + class SA_SlingLoadUpExt { + sound[] = {"A3\Sounds_F\vehicles\air\noises\SL_engineUpEXT", 1.2589254, 1, 500}; + titles[] = {}; + frequency = 1; + volume = "camPos * (slingLoadActive factor [0, 1])"; + }; + class SA_SlingLoadDownInt { + sound[] = {"A3\Sounds_F\vehicles\air\noises\SL_engineDownINT", 1, 1, 500}; + titles[] = {}; + frequency = 1; + volume = "(1 - camPos) * (slingLoadActive factor [0, -1])"; + }; + class SA_SlingLoadUpInt { + sound[] = {"A3\Sounds_F\vehicles\air\noises\SL_engineUpINT", 1, 1, 500}; + titles[] = {}; + frequency = 1; + volume = "(1 - camPos) * (slingLoadActive factor [0, 1])"; + }; +}; diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 38b034c..21e4ebf 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -25,23 +25,13 @@ ASL_Advanced_Sling_Loading_Install = { diag_log "Advanced Sling Loading Loading..."; - ASL_Rope_Get_Lift_Capability = { - params [["_vehicle", objNull]]; - if (isNull _vehicle) exitWith {}; - private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); - if (_slingLoadMaxCargoMass <= 0) then { - _slingLoadMaxCargoMass = ASL_DefaultLiftableMass; - }; - _slingLoadMaxCargoMass; - }; - - ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ - ["All", [-0.05, -0.05, -0.05]], + ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET = [ ["CUP_CH47F_base", [-0.05, -2, -0.05]], ["CUP_AW159_Unarmed_Base", [-0.05, -0.06, -0.05]], ["RHS_CH_47F", [-0.75, -2.6, -0.75]], - ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], - ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]] + ["rhsusf_CH53E_USMC", [-0.8, -1, -1.1]], + ["rhsusf_CH53E_USMC_D", [-0.8, -1, -1.1]], + ["OWP_MI26_base", [-3.7, -4.4, -3.45]] // due to model geometry, front and central ropes will be 'sucked' into the vehicle, while vehicle is on the ground; there is nothing that prevents this behaviour except correction of the model itself ]; ASL_Get_Sling_Load_Points = { @@ -49,16 +39,17 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {}; private _slingLoadPointsArray = []; private _cornerPoints = [_vehicle] call ASL_Get_Corner_Points; - private _frontCenterPoint = (((_cornerPoints select 2) vectorDiff (_cornerPoints select 3)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 3); - private _rearCenterPoint = (((_cornerPoints select 0) vectorDiff (_cornerPoints select 1)) vectorMultiply 0.5) vectorAdd (_cornerPoints select 1); + private _frontCenterPoint = (((_cornerPoints #2) vectorDiff (_cornerPoints #3)) vectorMultiply 0.5) vectorAdd (_cornerPoints #3); + private _rearCenterPoint = (((_cornerPoints #0) vectorDiff (_cornerPoints #1)) vectorMultiply 0.5) vectorAdd (_cornerPoints #1); _rearCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.2) vectorAdd _rearCenterPoint; _frontCenterPoint = ((_rearCenterPoint vectorDiff _frontCenterPoint) vectorMultiply 0.2) vectorAdd _frontCenterPoint; private _middleCenterPoint = ((_frontCenterPoint vectorDiff _rearCenterPoint) vectorMultiply 0.5) vectorAdd _rearCenterPoint; private _vehicleUnitVectorUp = vectorNormalized (vectorUp _vehicle); - private _slingLoadPointHeightOffset = 0; + private _slingLoadPointHeightOffset = [-0.05, -0.05, -0.05]; { - if (_vehicle isKindOf (_x select 0)) exitWith { - _slingLoadPointHeightOffset = (_x select 1); + if (_vehicle isKindOf _x #0) exitWith { + _slingLoadPointHeightOffset = _x #1; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Sling_Load_Points) _vehicle ", _vehicle, " isKindOf ", _x #0, ", _slingLoadPointHeightOffsetfset: ", _slingLoadPointHeightOffset]; }; } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; private _slingLoadPoints = []; @@ -84,11 +75,11 @@ ASL_Advanced_Sling_Loading_Install = { // Determine if the surface intersection line crosses below ground level // If if does, move surfaceIntersectStartASL above ground level (lineIntersectsSurfaces - // doesn't work if starting below ground level for some reason + // doesn't work if starting below ground level for some reason) // See: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection _la = ASLToAGL _surfaceIntersectStartASL; _lb = ASLToAGL _surfaceIntersectEndASL; - if (_la select 2 < 0 && _lb select 2 > 0) then { + if (_la #2 < 0 && _lb #2 > 0) then { _n = [0, 0, 1]; _p0 = [0, 0, 0.1]; _l = (_la vectorFromTo _lb); @@ -101,26 +92,26 @@ ASL_Advanced_Sling_Loading_Install = { _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, objNull, objNull, true, 100]; _intersectionASL = []; { - _intersectionObject = _x select 2; + _intersectionObject = _x #2; if (_intersectionObject == _vehicle) exitWith { - _intersectionASL = _x select 0; + _intersectionASL = _x #0; }; } forEach _surfaces; if (count _intersectionASL > 0) then { - _intersectionASL = _intersectionASL vectorAdd ((_surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL) vectorMultiply (_slingLoadPointHeightOffset select (count _slingLoadPoints))); + _intersectionASL = _intersectionASL vectorAdd ((_surfaceIntersectStartASL vectorFromTo _surfaceIntersectEndASL) vectorMultiply (_slingLoadPointHeightOffset #(count _slingLoadPoints))); _slingLoadPoints pushBack (_vehicle worldToModelVisual (ASLToAGL _intersectionASL)); } else { _slingLoadPoints pushBack []; }; } forEach [_frontCenterPoint, _middleCenterPoint, _rearCenterPoint]; - if (count (_slingLoadPoints select 1) > 0) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 1]; - if (count (_slingLoadPoints select 0) > 0 && count (_slingLoadPoints select 2) > 0) then { - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 2)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 2]; - if (((_slingLoadPoints select 0) distance (_slingLoadPoints select 1)) > 3) then { - _slingLoadPointsArray pushBack [_slingLoadPoints select 0, _slingLoadPoints select 1, _slingLoadPoints select 2]; + if (count (_slingLoadPoints #1) > 0) then { + _slingLoadPointsArray pushBack [_slingLoadPoints #1]; + if (count (_slingLoadPoints #0) > 0 && count (_slingLoadPoints #2) > 0) then { + if (((_slingLoadPoints #0) distance (_slingLoadPoints #2)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints #0, _slingLoadPoints #2]; + if (((_slingLoadPoints #0) distance (_slingLoadPoints #1)) > 3) then { + _slingLoadPointsArray pushBack [_slingLoadPoints #0, _slingLoadPoints #1, _slingLoadPoints #2]; }; }; }; @@ -142,68 +133,116 @@ ASL_Advanced_Sling_Loading_Install = { }; private _centerOfMass = getCenterOfMass _vehicle; private _bbr = boundingBoxReal _vehicle; - private _p1 = _bbr select 0; - private _p2 = _bbr select 1; - private _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); - private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass select 0)) * _widthFactor; - private _maxLength = abs ((_p2 select 1) - (_p1 select 1)); - private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1)) * _lengthFactor; - private _maxHeight = abs ((_p2 select 2) - (_p1 select 2)); + private _p1 = _bbr #0; + private _p2 = _bbr #1; + private _maxWidth = abs ((_p2 #0) - (_p1 #0)); + private _widthOffset = ((_maxWidth / 2) - abs (_centerOfMass #0)) * _widthFactor; + private _maxLength = abs ((_p2 #1) - (_p1 #1)); + private _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass #1)) * _lengthFactor; + private _maxHeight = abs ((_p2 #2) - (_p1 #2)); private _heightOffset = _maxHeight / 6; - private _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; - private _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, (_centerOfMass select 2) + _heightOffset]; + private _rearCorner = [(_centerOfMass #0) + _widthOffset, (_centerOfMass #1) - _lengthOffset, (_centerOfMass #2) + _heightOffset]; + private _rearCorner2 = [(_centerOfMass #0) - _widthOffset, (_centerOfMass #1) - _lengthOffset, (_centerOfMass #2) + _heightOffset]; + private _frontCorner = [(_centerOfMass #0) + _widthOffset, (_centerOfMass #1) + _lengthOffset, (_centerOfMass #2) + _heightOffset]; + private _frontCorner2 = [(_centerOfMass #0) - _widthOffset, (_centerOfMass #1) + _lengthOffset, (_centerOfMass #2) + _heightOffset]; [_rearCorner, _rearCorner2, _frontCorner, _frontCorner2]; }; + /* some of the vehicles have maximal sling load values differing frome the ones + given by their "slingLoadMaxCargoMass" config entries; + values in the list below were obzained by experimentation */ + ASL_SLING_LOAD_LIFT_CAPABILITY = [ + ["UAV_01_base_F", 50], + ["UAV_06_base_F", 260], + ["Heli_Light_01_base_F", 1700], + ["Heli_Light_02_base_F", 2500], + ["UAV_03_base_F", 2900], + ["uh60", 3000], + ["Heli_light_03_base_F", 3300], + ["Heli_Transport_01_base_F", 3300], + ["RHS_Mi8_base", 3500], + ["Heli_Attack_01_base_F", 5600], + ["Heli_Transport_02_base_F", 5700], + ["VTOL_01_base_F", 6700], + ["RHS_AH64_base", 6900], + ["VTOL_02_base_F", 7000], + ["RHS_CH_47F_base", 11900], + ["OWP_MI26_base", 48000] + ]; + + ASL_Rope_Get_Lift_Capability = { + params [["_vehicle", objNull]]; + if (isNull _vehicle) exitWith {}; + private _slingLoadMaxCargoMass = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "slingLoadMaxCargoMass"); + if (_slingLoadMaxCargoMass <= 0) then { + _slingLoadMaxCargoMass = ASL_DefaultLiftableMass; + }; + { + if (_vehicle isKindOf _x #0) exitWith {_slingLoadMaxCargoMass = _x #1}; + } forEach ASL_SLING_LOAD_LIFT_CAPABILITY; + _slingLoadMaxCargoMass; + }; + ASL_Rope_Set_Mass = { - private _object = [_this, 0] call BIS_fnc_param; - private _mass = [_this, 1] call BIS_fnc_param; - _object setMass _mass; + params [["_cargo", objNull], ["_mass", 0]]; + if (isNull _cargo || _mass == 0) exitWith {}; + _cargo setMass _mass; }; - + ASL_Rope_Adjust_Mass = { - params [["_object", objNull], ["_vehicle", objNull], ["_ropes", []]]; - if (isNull _object || isNull _vehicle) exitWith {}; + params [["_vehicle", objNull], ["_cargo", objNull], ["_ropes", []]]; + if (isNull _vehicle || isNull _cargo) exitWith {}; private _lift = [_vehicle] call ASL_Rope_Get_Lift_Capability; - private _maxLiftableMass = _lift * ASL_MaxLiftableMassFactor; - private _originalMass = getMass _object; + private _maxLiftableMass = _lift; + if (ASL_HeavyLiftAuthorized) then {_maxLiftableMass = _maxLiftableMass * ASL_MaxLiftableMassFactor}; + private _originalMass = getMass _cargo; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; - // diag_log formatText [ - // "%1%2%3%4%5%6%7%8%9%10%11", time, - // "s (ASL_Rope_Adjust_Mass) _object: ", _object, - // " _originalMass: ", _originalMass, - // " _vehicle: ", _vehicle, - // " _lift: ", _lift, - // " _heavyLiftMinLift: ", _heavyLiftMinLift - // ]; - if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass) then { - private _originalMassSet = (getMass _object) == _originalMass; - private ["_ends", "_endDistance", "_ropeLength"]; - while {_object in (ropeAttachedObjects _vehicle) && _originalMassSet} do { - { - _ends = ropeEndPosition _x; - _endDistance = (_ends select 0) distance (_ends select 1); - _ropeLength = ropeLength _x; - if ((_ropeLength - 2) <= _endDistance && ((position _vehicle) select 2) > 0) then { - [[_object, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _object, true] call ASL_RemoteExec; - _originalMassSet = false; - }; - } forEach _ropes; - sleep 0.1; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11", time, + "s (ASL_Rope_Adjust_Mass) _cargo: ", _cargo, + " _originalMass: ", _originalMass, + " _vehicle: ", _vehicle, + " _lift: ", _lift, + " _heavyLiftMinLift: ", _heavyLiftMinLift + ]; + if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass && ASL_HeavyLiftAuthorized) then { + [[_cargo, _originalMass], "ASL_Rope_Set_Mass", _cargo, true] call ASL_RemoteExec; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Adjust_Mass) Mass is being adjusted!"]; + [_vehicle, _cargo, _originalMass, _lift, _maxLiftableMass] spawn { + params [["_vehicle", objNull], ["_cargo", objNull], ["_originalMass", 0], ["_lift", 0], ["_maxLiftableMass", 0]]; + if (isNull _vehicle || isNull _cargo || _originalMass == 0 || _lift == 0 || _maxLiftableMass == 0) exitWith {}; + [[_cargo, (_lift * 0.8 + ((_originalMass / _maxLiftableMass) * (_lift * 0.2)))], "ASL_Rope_Set_Mass", _cargo, true] call ASL_RemoteExec; + while {alive _vehicle && alive _cargo && _cargo in ropeAttachedObjects _vehicle} do { + sleep 0.2; + }; }; - while {_object in (ropeAttachedObjects _vehicle)} do { - sleep 0.5; + }; + if (!ASL_RopeMessagesAuthorized) exitWith {}; + sleep 0.3; + [_vehicle, _originalMass, _lift] spawn { + params [["_vehicle", objNull], ["_originalMass", 0], ["_lift", 0]]; + if (isNull _vehicle || _originalMass == 0 || _lift == 0) exitWith {}; + sleep 0.2; + // private _messageText = format[localize "STR_ASL_SLING_MASS", (_originalMass / 1000) toFixed 2]; + private _messageText = format[localize "STR_ASL_SLING_MASS"]; + private _totalSlingMass = 0; + { + _totalSlingMass = _totalSlingMass + getMass _x; + } forEach ropeAttachedObjects _vehicle; + if (_totalSlingMass > _lift) then { + // private _vehicleName = getText (configfile >> "CfgVehicles" >> typeOf _vehicle >> "displayName"); + // _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD", _vehicleName]]; + _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD"]]; + _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD_MASS", (_totalSlingMass / 1000) toFixed 2, (_lift / 1000) toFixed 2]]; + } else { + _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_SLING_MASS_REMAINING", ((_lift - _totalSlingMass) / 1000) toFixed 2, (_lift / 1000) toFixed 2]]; }; - [[_object, _originalMass], "ASL_Rope_Set_Mass", _obj, true] call ASL_RemoteExec; + hint _messageText; }; }; - /* - Constructs an array of all active (or inactive) rope indexes and position labels - (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle - */ + /* Constructs an array of all active (or inactive) rope indexes and position labels + (e.g. [[rope index,"Front"], [rope index,"Rear"]]) for a specified vehicle */ ASL_Get_Active_Ropes = { params [["_vehicle", objNull], ["_active", false]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Get_Ropes) _vehicle: ", _vehicle, " _active: ", _active]; @@ -219,8 +258,8 @@ ASL_Advanced_Sling_Loading_Install = { private ["_ropeLabels"]; { if ((_active && count _x > 0) || (!_active && count _x == 0)) then { - _ropeLabels = _ropeLabelSets select (_totalExistingRopes - 1); - _activeRopes pushBack [_foreachindex, _ropeLabels select _foreachindex]; + _ropeLabels = _ropeLabelSets #(_totalExistingRopes - 1); + _activeRopes pushBack [_foreachindex, _ropeLabels #_foreachindex]; }; } forEach _existingRopes; _activeRopes; @@ -234,7 +273,7 @@ ASL_Advanced_Sling_Loading_Install = { private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; private ["_cargo"]; { - _cargo = _existingCargo select (_x select 0); + _cargo = _existingCargo select (_x #0); if (!isNull _cargo) then { if (!alive _cargo || ropeAttachedTo _cargo != _vehicle) exitWith { [_vehicle, _unit, _foreachindex] call ASL_Release_Cargo; // in case cargo destroyed @@ -254,7 +293,7 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Active_Ropes_Without_Cargo) _vehicle: ", _vehicle, ", _existingCargo: ", _existingCargo, ", _activeRopes: ", _activeRopes]; private ["_cargo"]; { - _cargo = _existingCargo select (_x select 0); + _cargo = _existingCargo select (_x #0); if (isNull _cargo) then { _activeRopesWithoutCargo pushBack _x; }; @@ -269,7 +308,7 @@ ASL_Advanced_Sling_Loading_Install = { private _selectedRopes = []; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; if (count _allRopes > _ropesIndex) then { - _selectedRopes = _allRopes select _ropesIndex; + _selectedRopes = _allRopes #_ropesIndex; }; _selectedRopes; }; @@ -286,7 +325,7 @@ ASL_Advanced_Sling_Loading_Install = { private _selectedCargo = objNull; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; if (count _allCargo > _ropesIndex) then { - _selectedCargo = _allCargo select _ropesIndex; + _selectedCargo = _allCargo #_ropesIndex; }; _selectedCargo; }; @@ -323,8 +362,9 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) exitWith {true}; if !(ASL_CopilotsAuthorized) exitWith {false}; - private _cfg = configFile >> "CfgVehicles" >> typeOf(_vehicle); - private _turrets = _cfg >> "turrets"; + // private _cfg = configFile >> "CfgVehicles" >> typeOf _vehicle; + // private _turrets = _cfg >> "turrets"; + private _turrets = configFile >> "CfgVehicles" >> typeOf _vehicle >> "turrets"; private _isCopilot = false; for "_i" from 0 to (count _turrets - 1) do { private _turret = _turrets select _i; @@ -369,13 +409,15 @@ ASL_Advanced_Sling_Loading_Install = { if (count _activeRopes == 1) exitWith { private _ropeLength = [_vehicle, _activeRopes #0 #0, _toGround] call ASL_Extend_Ropes; if (_ropeLength <= ASL_MaxRopeLength) exitWith { - // private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; - _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; - if (_toGround) then {_messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO_G", _ropeLength]}; - if (_ropeLength == ASL_MaxRopeLength) then { - _messageText = formatText ["%1%2", _messageText, " (max)"]; + if (ASL_RopeMessagesAuthorized) then { + // private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; + if (_toGround) then {_messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO_G", _ropeLength]}; + if (_ropeLength == ASL_MaxRopeLength) then { + _messageText = formatText ["%1%2", _messageText, " (max)"]; + }; + hint _messageText; }; - if (ASL_RopeMessagesAuthorized) then {hint _messageText}; diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; if (_toGround && _canReleaseCargo) then { private _rope = (_vehicle getVariable "ASL_Ropes") #0 #0; @@ -404,11 +446,11 @@ ASL_Advanced_Sling_Loading_Install = { if (_x #1 == ASL_MaxRopeLength) then { _messageText = formatText ["%1%2", _messageText, " (max)"]; }; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9", time, - "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo, - ", _extendedRopeIndex: ", _extendedRopeIndex - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9", time, + // "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo, + // ", _extendedRopeIndex: ", _extendedRopeIndex + // ]; if (_toGround && _canReleaseCargo) then { private _rope = (_vehicle getVariable "ASL_Ropes") #_extendedRopeIndex #0; private _cargo = (_vehicle getVariable "ASL_Cargo") #_extendedRopeIndex; @@ -418,23 +460,26 @@ ASL_Advanced_Sling_Loading_Install = { _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ALREADY_MAX_LENGTH", ASL_MaxRopeLength]]; }; } forEach _extendedRopes; - _messageText setAttributes ["align", "left"]; - if (ASL_RopeMessagesAuthorized) then {hint composeText [_messageText]}; + if (ASL_RopeMessagesAuthorized) then { + _messageText setAttributes ["align", "left"]; + hint composeText [_messageText]; + }; _vehicle setVariable ["ASL_Ropes_Change", nil]; }; ASL_Release_Cargo_Near_Ground = { params [["_vehicle", objNull], ["_unit", objNull], ["_rope", objNull], ["_ropeLength", 0], ["_cargo", objNull], ["_ropesIndex", 0]]; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, - "s (ASL_Release_Cargo_Near_Ground) _vehicle: ", _vehicle, - ", _unit: ", _unit, - ", _rope: ", _rope, - ", _ropeLength: ", _ropeLength, - ", _cargo: ", _cargo - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + // "s (ASL_Release_Cargo_Near_Ground) _vehicle: ", _vehicle, + // ", _unit: ", _unit, + // ", _rope: ", _rope, + // ", _ropeLength: ", _ropeLength, + // ", _cargo: ", _cargo + // ]; if (isNull _vehicle || isNull _unit || isNull _rope || _ropeLength == 0 || isNull _cargo) exitWith {}; - private _future = time + 60; + // private _future = time + 60; + private _future = time + 20 + 100 / ASL_RopeUnwindSpeed; sleep 1; while { !ropeUnwound _rope && @@ -444,17 +489,16 @@ ASL_Advanced_Sling_Loading_Install = { alive _cargo && getPos _cargo #2 > 1 } do {sleep 1}; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, - "s (ASL_Release_Cargo_Near_Ground) EXIT LOOP! ropeUnwound: ", !ropeUnwound _rope, - ", alive _vehicle: ", alive _vehicle, - ", time < _future: ", time < _future, - ", ropeLength _rope < _ropeLength: ", ropeLength _rope < _ropeLength, - ", alive _cargo: ", alive _cargo, - ", getPos _cargo #2 > 1: ", getPos _cargo #2 > 1 - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + // "s (ASL_Release_Cargo_Near_Ground) EXIT LOOP! ropeUnwound: ", !ropeUnwound _rope, + // ", alive _vehicle: ", alive _vehicle, + // ", time < _future: ", time < _future, + // ", ropeLength _rope < _ropeLength: ", ropeLength _rope < _ropeLength, + // ", alive _cargo: ", alive _cargo, + // ", getPos _cargo #2 > 1: ", getPos _cargo #2 > 1 + // ]; if (!alive _vehicle || (getPos _cargo #2 > 5 && alive _cargo)) exitWith {}; - // [_vehicle, _unit] call ASL_Release_Cargo_Action; [_ropesIndex, _vehicle, _unit] call ASL_Release_Cargo_Index_Action; }; @@ -467,7 +511,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Unit = _unit; ASL_toGround = _toGround; { - ASL_Show_Select_Ropes_Menu_Array pushBack [(_x #1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x select 0))+", ASL_Vehicle, ASL_Unit, ASL_toGround] call " + _functionName]], "1", "1"]; + ASL_Show_Select_Ropes_Menu_Array pushBack [(_x #1) + " " + _ropesLabel, [0], "", -5, [["expression", "["+(str (_x #0))+", ASL_Vehicle, ASL_Unit, ASL_toGround] call " + _functionName]], "1", "1"]; } forEach _ropesIndexAndLabelArray; ASL_Show_Select_Ropes_Menu_Array pushBack [format[localize "STR_ASL_ALL"] + " " + _ropesLabel, [0], "", -5, [["expression", "{[_x, ASL_Vehicle, ASL_Unit, ASL_toGround] call " + _functionName + "} forEach [0, 1, 2];"]], "1", "1"]; showCommandingMenu ""; @@ -502,11 +546,11 @@ ASL_Advanced_Sling_Loading_Install = { if !(local _vehicle) exitWith {[_this, "ASL_Extend_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (count _existingRopes == 0) exitWith {0}; - private _ropeLength = ropeLength (_existingRopes select 0); + private _ropeLength = ropeLength (_existingRopes #0); if (_ropeLength >= ASL_MaxRopeLength) exitWith {ASL_MaxRopeLength + 1}; private _unwindLength = ASL_ExtendShortenRopeLength; if (_toGround) then { - _unwindLength = ceil((getPos _vehicle select 2) - _ropeLength + 5); + _unwindLength = ceil((getPos _vehicle #2) - _ropeLength + 5); /* 'getPos' will return the height of the vehicle above the next object underneath. So, if the vehicle has a sling load, it is likely the height will be measured false @@ -516,7 +560,7 @@ ASL_Advanced_Sling_Loading_Install = { private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; private _cargo = _allCargo #_ropesIndex; if (isNull _cargo) exitWith {}; - _unwindLength = ceil(getPos _cargo select 2) + 3; + _unwindLength = ceil(getPos _cargo #2) + 3; }; if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { _unwindLength = ASL_MaxRopeLength - _ropeLength; @@ -524,18 +568,38 @@ ASL_Advanced_Sling_Loading_Install = { diag_log formatText [ "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, "s (ASL_Extend_Ropes) _unwindLength: ", _unwindLength, - ", vehicle height: ", getPos _vehicle select 2, + ", vehicle height: ", getPos _vehicle #2, ", ASL_MaxRopeLength: ", ASL_MaxRopeLength, ", _ropeLength: ", _ropeLength, ", _ropesIndex: ", _ropesIndex ]; - { - ropeUnwind [_x, 3, _unwindLength, true]; - } forEach _existingRopes; + [_vehicle, _existingRopes, ASL_RopeUnwindSpeed, _unwindLength] spawn ASL_Unwind_Ropes; _ropeLength = _ropeLength + _unwindLength; _ropeLength }; - + + ASL_Unwind_Ropes = { + params [["_vehicle", objNull], ["_ropes", []], ["_speed", 3], ["_length", 0], ["_relative", true]]; + diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Unwind_Ropes) _vehicle: ", _vehicle, ", _ropes: ", _ropes, ", _length: ", _length, ", _relative: ", _relative]; + if (isNull _vehicle) exitWith {}; + private _sound = "SA_SlingLoadUpExt"; + if (_length > 0) then {_sound = "SA_SlingLoadDownExt"}; + { + ropeUnwind [_x, _speed, _length, _relative]; + private _dummy = "#particlesource" createVehicleLocal ropeEndPosition _x #0; + _dummy attachTo [_vehicle, _vehicle worldToModelVisual ropeEndPosition _x #0]; + [_vehicle, _dummy, _x, _sound] spawn { + params [["_vehicle", objNull], ["_dummy", objNull], ["_rope", objNull], ["_sound", ""]]; + if (isNull _vehicle || isNull _dummy || isNull _rope) exitWith {}; + while {!ropeUnwound _rope && alive _vehicle && alive _rope} do { + _dummy say3D _sound; + sleep 1; + }; + deleteVehicle _dummy; + }; + } forEach _ropes; + }; + ASL_Shorten_Ropes_Action_Check = { params [["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; @@ -563,7 +627,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Shorten_Ropes_Action = { params [["_vehicle", objNull], ["_unit", objNull]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Shorten_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle || isNull _unit) exitWith {false}; if !([_vehicle] call ASL_Can_Shorten_Ropes) exitWith {false}; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; @@ -587,7 +651,7 @@ ASL_Advanced_Sling_Loading_Install = { { if (_x #1 >= ASL_MinRopeLength) then { _shortenedRopesIndex = _x#0; - // _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes select _x select 0 select 1, _x select 1]]; + // _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes #_x #0 #1, _x #1]]; _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", (_activeRopes select {_x#0 == _shortenedRopesIndex})#0#1, _x#1]]; if (_x #1 == ASL_MinRopeLength) then { _messageText = formatText ["%1%2", _messageText, " (min)"]; @@ -618,7 +682,7 @@ ASL_Advanced_Sling_Loading_Install = { private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; private _ropeLength = -1; if (count _existingRopes > 0) then { - _ropeLength = ropeLength (_existingRopes select 0); + _ropeLength = ropeLength (_existingRopes #0); if (_ropeLength <= ASL_MinRopeLength) exitWith { if (ASL_MinRopeLengthDropCargo) then { _this call ASL_Release_Cargo; @@ -630,9 +694,7 @@ ASL_Advanced_Sling_Loading_Install = { _unwindLength = _ropeLength - 5; }; if (_ropeLength < 10) then {_unwindLength = 1}; - { - ropeUnwind [_x, 3, -_unwindLength, true]; - } forEach _existingRopes; + [_vehicle, _existingRopes, ASL_RopeUnwindSpeed, -_unwindLength] spawn ASL_Unwind_Ropes; _ropeLength = _ropeLength - _unwindLength; }; _ropeLength @@ -681,7 +743,7 @@ ASL_Advanced_Sling_Loading_Install = { if !([_vehicle, _unit] call ASL_Can_Release_Cargo) exitWith {false}; private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; if (count _activeRopes == 1) exitWith { - [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Release_Cargo + [_vehicle, _unit, (_activeRopes #0) #0] call ASL_Release_Cargo }; [format[localize "STR_ASL_RELEASE"], "ASL_Release_Cargo_Index_Action", _activeRopes, format[localize "STR_ASL_CARGO"], _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; }; @@ -700,12 +762,14 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _existingRopesAndCargo: ", _existingRopesAndCargo]; + private _existingRopes = _existingRopesAndCargo #0; + private _existingCargo = _existingRopesAndCargo #1; { _existingCargo ropeDetach _x; } forEach _existingRopes; - _existingCargo setVariable ["ASL_RopesIndex", nil, true]; + // _existingCargo setVariable ["ASL_RopesIndex", nil, true]; + // _existingCargo setVariable ["ASL_CarrierVehicle", nil, true]; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [_ropesIndex, objNull]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; @@ -762,7 +826,7 @@ ASL_Advanced_Sling_Loading_Install = { private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; if (count _activeRopes == 1) exitWith { diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) inactive ropes: ", [_vehicle] call ASL_Get_Active_Ropes, ", existing ropes: ", _vehicle getVariable ["ASL_Ropes", []]]; - [_vehicle, _unit, (_activeRopes select 0) select 0] call ASL_Retract_Ropes; + [_vehicle, _unit, (_activeRopes #0) #0] call ASL_Retract_Ropes; if (!ASL_RopeMessagesAuthorized) exitWith {}; hint format[localize "STR_ASL_ROPES_RETRACTED"]; [] spawn { @@ -777,24 +841,22 @@ ASL_Advanced_Sling_Loading_Install = { params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Retract_Ropes_Index_Action) _unit: ", _unit, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; if (isNull _vehicle || isNull _unit) exitWith {}; - // if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Retract_Ropes) then { if (_ropesIndex >= 0) then { [_vehicle, _unit, _ropesIndex] call ASL_Retract_Ropes; }; }; ASL_Retract_Ropes = { - // params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0], ["_hadCargo", false]]; params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Retract_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; + private _existingRopes = _existingRopesAndCargo #0; + private _existingCargo = _existingRopesAndCargo #1; private _cargoArray = ropeAttachedObjects _vehicle; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _vehicle: ", _vehicle, " _cargoArray: ", _cargoArray]; if (count _cargoArray > 0) then { - private _helper = (_cargoArray select {_x getVariable ["ASL_Ropes_Pick_Up_Helper", false]}) select 0; + private _helper = (_cargoArray select {_x getVariable ["ASL_Ropes_Pick_Up_Helper", false]}) #0; if (isNil {_helper}) exitWith {}; // if (!isNull _helper) then { private _ropeHolder = attachedTo _helper; @@ -812,13 +874,26 @@ ASL_Advanced_Sling_Loading_Install = { ", _activeRopes: ", [_vehicle, true] call ASL_Get_Active_Ropes, ", _inactiveRopes: ", [_vehicle] call ASL_Get_Active_Ropes ]; + [_vehicle, _existingRopes, ASL_RopeUnwindSpeed, 0, false] spawn ASL_Unwind_Ropes; { - [_x, _vehicle] spawn { - params ["_rope", "_vehicle"]; + // [_x, _vehicle] spawn { + // params ["_rope", "_vehicle"]; + [_vehicle, _x] spawn { + params [["_vehicle", objNull], ["_rope", objNull]]; + if (isNull _vehicle || isNull _rope) exitWith {false}; + sleep 1; if (isNull _rope || isNull _vehicle) exitWith {}; - private _future = time + 25; - ropeUnwind [_rope, 3, 0]; + // private _future = time + 60; + private _future = time + 20 + 100 / ASL_RopeUnwindSpeed; + // ropeUnwind [_rope, 3, 0]; + // [_vehicle, [_rope]] spawn ASL_Unwind_Ropes; while {!ropeUnwound _rope && alive _vehicle && time < _future} do {sleep 1}; + diag_log formatText [ + "%1%2%3%4%5%6%7%8%9%10%11%12", time, + "s (ASL_Retract_Ropes) Rope destroyed! !ropeUnwound _rope: ", !ropeUnwound _rope, + ", vehicle alive: ", alive _vehicle, + ", time < _future: ", time < _future + ]; ropeDestroy _rope; }; } forEach _existingRopes; @@ -836,7 +911,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_UAV", objNull], ["_unit", objNull]]; if (isNull _UAV || isNull _unit) exitWith {false}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) _UAV: ", _UAV, " _unit: ", _unit]; - if (UAVControl _UAV select 0 == _unit && (UAVControl _UAV select 1 == "GUNNER" || UAVControl _UAV select 1 == "DRIVER")) exitWith { + if (UAVControl _UAV #0 == _unit && (UAVControl _UAV #1 == "GUNNER" || UAVControl _UAV #1 == "DRIVER")) exitWith { // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Vehicle_Is_UAV_And_Currently_Operatied_By_Unit) EXIT 1: unit is UAV gunner or driver"]; true }; @@ -878,7 +953,7 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 3"]; false }; - if (getPos _vehicle select 2 > ASL_MaxRopeDeployHeight) exitWith { + if (getPos _vehicle #2 > ASL_MaxRopeDeployHeight) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 4"]; false }; @@ -909,7 +984,7 @@ ASL_Advanced_Sling_Loading_Install = { if (count _inactiveRopes > 1) then { [format[localize "STR_ASL_DEPLOY"], "ASL_Deploy_Ropes_Index_Action", _inactiveRopes, _vehicle, _unit] call ASL_Show_Select_Ropes_Menu; } else { - [_vehicle, _unit, (_inactiveRopes select 0) select 0] call ASL_Deploy_Ropes_Index; + [_vehicle, _unit, (_inactiveRopes #0) #0] call ASL_Deploy_Ropes_Index; }; }; private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; @@ -986,18 +1061,19 @@ ASL_Advanced_Sling_Loading_Install = { private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; private _cargoRopes = []; for "_i" from 1 to 4 do { - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) select _ropesIndex, 0]; + _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; }; { _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - ropeUnwind [_x, 5, ASL_InitialDeployRopeLength]; } forEach _cargoRopes; + [_vehicle, _cargoRopes, ASL_RopeUnwindSpeed + 2, ASL_InitialDeployRopeLength, false] spawn ASL_Unwind_Ropes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; _allRopes set [_ropesIndex, _cargoRopes]; _vehicle setVariable ["ASL_Ropes", _allRopes, true]; [_vehicle] spawn ASL_Rope_Monitor_Vehicle; - if (!ASL_RopeMessagesAuthorized) exitWith {}; - hint format[localize "STR_ASL_ROPES_DEPLOYED", ASL_InitialDeployRopeLength]; + if (ASL_RopeMessagesAuthorized) then { + hint format[localize "STR_ASL_ROPES_DEPLOYED", ASL_InitialDeployRopeLength]; + }; }; ASL_Rope_Monitor_Vehicle = { @@ -1014,7 +1090,7 @@ ASL_Advanced_Sling_Loading_Install = { _ropeBundle = _x; { _rope = _x; - _nearbyUnits = ((ropeEndPosition _rope select 1) nearObjects (ASL_RopeHandlingDistance + 10)) select {_x isKindOf "CAManBase" && side _x == side player && vehicle _x == _x}; + _nearbyUnits = ((ropeEndPosition _rope #1) nearObjects (ASL_RopeHandlingDistance + 10)) select {_x isKindOf "CAManBase" && side _x == side player && vehicle _x == _x}; // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Monitor_Vehicle) _nearbyUnits: ", _nearbyUnits]; { _unitRopes = _x getVariable ["ASL_Ropes_Near_Unit", []]; @@ -1041,7 +1117,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_unit getVariable "ASL_ActionID_Pickup"}) then { // add pickup action to unit private _actionID = _unit addAction [ format[localize "STR_ASL_PICKUP"], // Title - {[_this select 0] call ASL_Pickup_Ropes_Action;}, // Script + {[_this #0] call ASL_Pickup_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1061,7 +1137,7 @@ ASL_Advanced_Sling_Loading_Install = { _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; }; { - if (!alive _x || (_unit distance (ropeEndPosition _x select 1) > (ASL_RopeHandlingDistance + 15) && _unitRopes find _x != -1)) then { + if (!alive _x || (_unit distance (ropeEndPosition _x #1) > (ASL_RopeHandlingDistance + 15) && _unitRopes find _x != -1)) then { _index = _unitRopes find _x; if (_index == -1) exitWith {}; _unitRopes deleteAt _index; @@ -1091,7 +1167,7 @@ ASL_Advanced_Sling_Loading_Install = { private _ropeHandlingDistance = ASL_RopeHandlingDistance; if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; { - if (alive _x && (_unit distance (ropeEndPosition _x select 1) < _ropeHandlingDistance)) exitWith {_pickup = true}; + if (alive _x && (_unit distance (ropeEndPosition _x #1) < _ropeHandlingDistance)) exitWith {_pickup = true}; } forEach _unitRopes; _pickup }; @@ -1107,27 +1183,20 @@ ASL_Advanced_Sling_Loading_Install = { private _ropeHandlingDistance = ASL_RopeHandlingDistance; if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; private _closestDistance = _ropeHandlingDistance + 100; + private ["_distance"]; { - _distance = _unit distance (ropeEndPosition _x select 1); + _distance = _unit distance (ropeEndPosition _x #1); if (_x != objNull && _distance < _ropeHandlingDistance && _distance < _closestDistance) then { _closestRope = _x; }; } forEach _unitRopes; - - // private _closestDistance = ASL_RopeHandlingDistance + 100; - // { - // _distance = _unit distance (ropeEndPosition _x select 1); - // if (_x != objNull && _distance < ASL_RopeHandlingDistance && _distance < _closestDistance) then { - // _closestRope = _x; - // }; - // } forEach _unitRopes; if (isNull _closestRope) exitWith {}; - private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") select 0; + private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") #0; if (isNull _vehicle) exitWith {}; if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; }; - private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") select 1; + private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") #1; [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; }; @@ -1136,8 +1205,8 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; - private _existingRopes = _existingRopesAndCargo select 0; - private _existingCargo = _existingRopesAndCargo select 1; + private _existingRopes = _existingRopesAndCargo #0; + private _existingCargo = _existingRopesAndCargo #1; if (!isNull _existingCargo) then { { _existingCargo ropeDetach _x; @@ -1156,10 +1225,10 @@ ASL_Advanced_Sling_Loading_Install = { _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; private ["_actionID"]; - if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { + if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes format[localize "STR_ASL_ATTACH"], // Title - {[_this select 0] call ASL_Attach_Ropes_Action;}, // Script + {[_this #0] call ASL_Attach_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1169,10 +1238,10 @@ ASL_Advanced_Sling_Loading_Install = { ]; _unit setVariable ["ASL_ActionID_Attach", _actionID]; }; - if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { + if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes format[localize "STR_ASL_DROP"], // Title - {[_this select 0] call ASL_Drop_Ropes_Action;}, // Script + {[_this #0] call ASL_Drop_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1182,30 +1251,156 @@ ASL_Advanced_Sling_Loading_Install = { ]; _unit setVariable ["ASL_ActionID_Drop", _actionID]; }; + if (isNil{_unit getVariable "ASL_ActionID_AttachSelf"}) then { + _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes + format[localize "STR_ASL_SELF_ATTACH"], // Title + {[_this #0, true] call ASL_Attach_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this, true] call ASL_Attach_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_AttachSelf", _actionID]; + }; }; + + // ASL_Pickup_Ropes_Action_Check = { + // params [["_vehicle", objNull], ["_unit", objNull]]; + // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; + // if (isNull _vehicle || isNull _unit) exitWith {false}; + // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) vehicle _unit != _unit: ", vehicle _unit != _unit]; + // if (vehicle _unit != _unit) exitWith {false}; + // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) ASL_Ropes_Pick_Up_Helper: ", isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}]; + // if !(isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}) exitWith {false}; + // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _allRopes: ", _allRopes]; + // if (count _allRopes == 0) exitWith {false}; + // private _pickup = false; + // private _ropeHandlingDistance = ASL_RopeHandlingDistance; + // if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; + // private ["_ropeBundle"]; + // { + // _ropeBundle = _x; + // { + // if (alive _x && (_unit distance (ropeEndPosition _x #1)) < _ropeHandlingDistance) exitWith {_pickup = true}; + // } forEach _ropeBundle; + // } forEach _allRopes; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Pickup_Ropes_Action_Check) _ropeHandlingDistance: ", _ropeHandlingDistance, "m , dist to end: ", (_unit distance (ropeEndPosition (_allRopes #0 #0) #1)), "m , _pickup: ", _pickup]; + // _pickup + // }; + + // ASL_Pickup_Ropes_Action = { + // params [["_vehicle", objNull], ["_unit", objNull]]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + // if (isNull _vehicle || isNull _unit) exitWith {false}; + // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _allRopes: ", _allRopes]; + // if (count _allRopes == 0) exitWith {}; + // private _ropeHandlingDistance = ASL_RopeHandlingDistance; + // if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; + // private _unitRopes = _unit getVariable ["ASL_Ropes_Near_Unit", []]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _unitRopes: ", _unitRopes, ", _ropeHandlingDistance: ", _ropeHandlingDistance]; + // private ["_ropeBundle"]; + // { + // _ropeBundle = _x; + // { + // if (alive _x && (_unit distance (ropeEndPosition _x #1)) < _ropeHandlingDistance) then {_unitRopes pushBack _x}; + // } forEach _ropeBundle; + // } forEach _allRopes; + // _unitRopes = _unitRopes - [objNull]; // remove any no longer existing ropes + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _unitRopes: ", _unitRopes]; + // _unitRopes = [_unitRopes, [], {_unit distance (ropeEndPosition _x #1)}, "ASCEND"] call BIS_fnc_sortBy; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) distance rope ends to unit ", _unit, ":"]; + // { + // diag_log formatText ["%1%2%3%4%5%6", time, "s (ASL_Pickup_Ropes_Action) rope ", _x, ": ", _unit distance (ropeEndPosition _x #1), " m"]; + // } forEach _unitRopes; + // _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; // save array on unit in case more than one vehicle have ropes deployed + // if (count _unitRopes == 0) exitWith {}; + // private _closestRope = _unitRopes #0; + // private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") #0; + // if (isNull _vehicle) exitWith {}; + // if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { + // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; + // }; + // private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") #1; + // [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; + // }; + + // ASL_Pickup_Ropes = { + // params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + // if (isNull _vehicle || isNull _unit) exitWith {}; + // if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; + // private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; + // private _existingRopes = _existingRopesAndCargo #0; + // private _existingCargo = _existingRopesAndCargo #1; + // if (!isNull _existingCargo) then { + // { + // _existingCargo ropeDetach _x; + // } forEach _existingRopes; + // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + // _allCargo set [_ropesIndex, objNull]; + // _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + // }; + // private _helper = "Land_Can_V2_F" createVehicle position _unit; + // _helper setVariable ["ASL_Ropes_Pick_Up_Helper", true, true]; + // { + // [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; + // _helper attachTo [_unit, [-0.1, 0.1, 0.15], "Pelvis"]; + // } forEach _existingRopes; + // hideObjectGlobal _helper; + // _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; + // _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; + // private ["_actionID"]; + // if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { + // _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes + // format[localize "STR_ASL_ATTACH"], // Title + // {[_this #0] call ASL_Attach_Ropes_Action}, // Script + // nil, // Arguments + // 0, // Priority + // false, // showWindow + // true, // hideOnUse + // "", // Shortcut + // "[_this] call ASL_Attach_Ropes_Action_Check" // Condition + // ]; + // _unit setVariable ["ASL_ActionID_Attach", _actionID]; + // }; + // if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { + // _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes + // format[localize "STR_ASL_DROP"], // Title + // {[_this #0] call ASL_Drop_Ropes_Action}, // Script + // nil, // Arguments + // 0, // Priority + // false, // showWindow + // true, // hideOnUse + // "", // Shortcut + // "[_this] call ASL_Drop_Ropes_Action_Check" // Condition + // ]; + // _unit setVariable ["ASL_ActionID_Drop", _actionID]; + // }; + // }; ASL_Attach_Ropes_Action_Check = { - params [["_unit", objNull]]; + params [["_unit", objNull], ["_self", false]]; if (isNull _unit) exitWith {false}; private _cargo = cursorTarget; - private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + if (_self && ASL_SelfAttachAuthorized) then {_cargo = _unit}; + private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) #0; private _ropeHandlingDistance = ASL_RopeHandlingDistance; - if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; // AI gets a higher range, as AI's do not get close enough to vehicles - // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && vehicle _unit == _unit && _unit distance _cargo < ASL_RopeHandlingDistance && _vehicle != _cargo; + if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; // AIs get higher range, as AIs sometimes can't get close enough to vehicles if (vehicle _unit != _unit || _unit distance _cargo > _ropeHandlingDistance || _vehicle == _cargo || !alive _cargo) exitWith {false}; + if (_vehicle == _cargo getVariable ["ASL_CarrierVehicle", objNull]) exitWith {false}; // let's not attach another rope from same vehicle to same cargo + if (_self && ASL_SelfAttachAuthorized) exitWith {true}; [_vehicle, _cargo] call ASL_Is_Supported_Cargo - // [_vehicle, _cargo] call ASL_Is_Supported_Cargo && - // vehicle _unit == _unit && - // _unit distance _cargo < _ropeHandlingDistance && - // _vehicle != _cargo && - // alive _cargo; }; ASL_Attach_Ropes_Action = { - params [["_unit", objNull]]; + params [["_unit", objNull], ["_self", false]]; if (isNull _unit) exitWith {}; private _cargo = cursorTarget; - private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) select 0; + if (_self) then {_cargo = _unit}; + private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) #0; if (locked _cargo > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { [format[localize "STR_ASL_CANT_ATTACH"], false] call ASL_Hint; }; @@ -1219,40 +1414,78 @@ ASL_Advanced_Sling_Loading_Install = { }; }; if (_canBeAttached) then { - [_cargo, _unit] call ASL_Attach_Ropes; + [_cargo, _unit, _self] call ASL_Attach_Ropes; }; }; ASL_Attach_Ropes = { - params [["_cargo", objNull], ["_unit", objNull]]; + params [["_cargo", objNull], ["_unit", objNull], ["_self", false]]; if (isNull _cargo || isNull _unit) exitWith {}; private _vehicleWithIndex = _unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]; - private _vehicle = _vehicleWithIndex select 0; + private _vehicle = _vehicleWithIndex #0; if (isNull _vehicle) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Attach_Ropes", _vehicle, true] call ASL_RemoteExec}; - private _ropes = [_vehicle, _vehicleWithIndex select 1] call ASL_Get_Ropes; + private _ropes = [_vehicle, _vehicleWithIndex #1] call ASL_Get_Ropes; if (count _ropes != 4) exitWith {}; private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - private _ropeLength = (ropeLength (_ropes select 0)); + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _attachmentPoints: ", _attachmentPoints, ", _self: ", _self]; + if (_self) then {_attachmentPoints = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]}; + private _ropeLength = (ropeLength (_ropes #0)); private _objDistance = (_cargo distance _vehicle) + 2; if (_objDistance > _ropeLength) then { [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; } else { - private _ropesIndex = _vehicleWithIndex select 1; - _cargo setVariable ["ASL_RopesIndex", _ropesIndex, true]; - [_vehicle, _unit] call ASL_Drop_Ropes; - for "_i" from 0 to 3 do { - [_cargo, _attachmentPoints select _i, [0, 0, -1]] ropeAttachTo (_ropes select _i); + private _ropesIndex = _vehicleWithIndex #1; + _cargo setVariable ["ASL_CarrierVehicle", _vehicle, true]; + [_vehicle, _cargo] spawn { + params [["_vehicle", objNull], ["_cargo", objNull]]; + if (isNull _vehicle || isNull _cargo) exitWith {}; + while {alive _vehicle && alive _cargo && _cargo in ropeAttachedObjects _vehicle} do { + sleep 1; + }; + _cargo setVariable ["ASL_CarrierVehicle", nil, true]; }; + [_vehicle, _unit] call ASL_Drop_Ropes; + + + + + // for "_i" from 0 to 3 do { + // [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); + // }; + + + + // for "_i" from 0 to 3 do { + // [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); + // }; + + + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [(_vehicleWithIndex select 1), _cargo]; + _allCargo set [(_vehicleWithIndex #1), _cargo]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { - [_cargo, _vehicle, _ropes] spawn ASL_Rope_Adjust_Mass; + [_vehicle, _cargo, _ropes] spawn ASL_Rope_Adjust_Mass; }; - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo - _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_AttachSelf"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; + if (_self) exitWith { + if (isNil{_unit getVariable "ASL_ActionID_Detach"}) then { + _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes + format[localize "STR_ASL_DETACH"], // Title + {[_this #0, true] call ASL_Drop_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Drop_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_Detach", _actionID]; + }; + }; + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; }; }; @@ -1263,29 +1496,33 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Drop_Ropes_Action = { - params [["_unit", objNull]]; + params [["_unit", objNull], ["_self", false]]; if (isNull _unit) exitWith {false}; private _vehicleAndIndex = _unit getVariable ["ASL_Ropes_Vehicle", []]; if (count _vehicleAndIndex == 2) then { - [_vehicleAndIndex select 0, _unit, _vehicleAndIndex select 1] call ASL_Drop_Ropes; + [_vehicleAndIndex #0, _unit, _vehicleAndIndex #1, _self] call ASL_Drop_Ropes; }; }; ASL_Drop_Ropes = { - params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0], ["_self", false]]; if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); + // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + if (_self) then {_helper = _unit}; if (!isNull _helper) then { - private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; + private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; { _helper ropeDetach _x; } forEach _existingRopes; detach _helper; + if (_self) exitWith { + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + }; deleteVehicle _helper; }; - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo - _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; @@ -1314,7 +1551,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle || isNull _cargo) exitWith {false}; private _canSling = false; { - if (_vehicle isKindOf (_x select 0) && _cargo isKindOf (_x select 2) && (toUpper (_x select 1)) == "CAN_SLING") exitWith {_canSling = true}; + if (_vehicle isKindOf (_x #0) && _cargo isKindOf (_x #2) && (toUpper (_x #1)) == "CAN_SLING") exitWith {_canSling = true}; } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); _canSling }; @@ -1341,19 +1578,17 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Add_Vehicle_Actions = { params [["_vehicle", objNull]]; if (isNull _vehicle) exitWith {}; - private _exit = true; - { - if (_vehicle isKindOf _x && getMass _vehicle > ASL_MinVehicleMass) exitWith {_exit = false}; - } foreach ASL_SUPPORTED_VEHICLES; + if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {}; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Add_Vehicle_Actions) _vehicle: ", _vehicle, ", mass: ", getMass _vehicle, ", min: ", ASL_MinVehicleMass]; - if (_exit) exitWith { + if (getMass _vehicle < ASL_MinVehicleMass) exitWith { + // [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release", "ASL_ActionID_Pickup"]] call ASL_Remove_Actions; [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release"]] call ASL_Remove_Actions; }; private ["_actionID"]; if (isNil{_vehicle getVariable "ASL_ActionID_Deploy"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_DEPLOY"], // Title - {[_this select 0, _this select 1] call ASL_Deploy_Ropes_Action}, // Script + {[_this #0, _this #1] call ASL_Deploy_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1366,7 +1601,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_vehicle getVariable "ASL_ActionID_Retract"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_RETRACT"], // Title - {[_this select 0, _this select 1] call ASL_Retract_Ropes_Action;}, // Script + {[_this #0, _this #1] call ASL_Retract_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1379,7 +1614,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_vehicle getVariable "ASL_ActionID_Extend"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_EXTEND"], // Title - {[_this select 0, _this select 1] call ASL_Extend_Ropes_Action}, // Script + {[_this #0, _this #1] call ASL_Extend_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1392,7 +1627,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_vehicle getVariable "ASL_ActionID_ExtendTG"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_EXTEND_TG"], // Title - {[_this select 0, _this select 1, true] call ASL_Extend_Ropes_Action}, // Script + {[_this #0, _this #1, true] call ASL_Extend_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1405,7 +1640,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_vehicle getVariable "ASL_ActionID_Shorten"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_SHORTEN"], // Title - {[_this select 0, _this select 1] call ASL_Shorten_Ropes_Action}, // Script + {[_this #0, _this #1] call ASL_Shorten_Ropes_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1418,7 +1653,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNil{_vehicle getVariable "ASL_ActionID_Release"}) then { _actionID = _vehicle addAction [ format[localize "STR_ASL_RELEASE"], // Title - {[_this select 0, _this select 1] call ASL_Release_Cargo_Action}, // Script + {[_this #0, _this #1] call ASL_Release_Cargo_Action}, // Script nil, // Arguments 0, // Priority false, // showWindow @@ -1428,6 +1663,19 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; + // if (isNil{_vehicle getVariable "ASL_ActionID_Pickup"}) then { + // _actionID = _vehicle addAction [ + // format[localize "STR_ASL_PICKUP"], // Title + // {[_this #0, _this #1] call ASL_Pickup_Ropes_Action}, // Script + // nil, // Arguments + // 0, // Priority + // false, // showWindow + // true, // hideOnUse + // "", // Shortcut + // "[_target, _this] call ASL_Pickup_Ropes_Action_Check" // Condition + // ]; + // _vehicle setVariable ["ASL_ActionID_Pickup", _actionID]; + // }; }; ASL_Remove_Actions = { @@ -1534,8 +1782,11 @@ if (isServer) then { if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted - if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) if (isNil "ASL_MinRopeLengthDropCargo") then {ASL_MinRopeLengthDropCargo = false}; // drop cargo, when minimum rope length is reached, and ropes are shortened once more if (isNil "ASL_RopeMessagesAuthorized") then {ASL_RopeMessagesAuthorized = true}; // hint players informations about rope changes + if (isNil "ASL_RopeUnwindSpeed") then {ASL_RopeUnwindSpeed = 3}; // ropes unwinding speed + if (isNil "ASL_HeavyLiftAuthorized") then {ASL_HeavyLiftAuthorized = true}; // heavy lifting allowed + if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) + if (isNil "ASL_SelfAttachAuthorized") then {ASL_SelfAttachAuthorized = true}; // allow self attachment to cargo ropes [] call ASL_Advanced_Sling_Loading_Install; }; diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index eeca88b..9a668f0 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -100,15 +100,6 @@ [500, 10000, 4000, 0], true ] call CBA_fnc_addSetting; -[ - "ASL_MaxLiftableMassFactor", - "SLIDER", - [format[localize "STR_ASL_MAX_MASS"], format[localize "STR_ASL_MAX_MASS_TIP"]], - format[localize "STR_ASL_TITLE"], - [1, 20, 8, 0], - true, - {ASL_MaxLiftableMassFactor = round(ASL_MaxLiftableMassFactor)} -] call CBA_fnc_addSetting; [ "ASL_MinRopeLengthDropCargo", "CHECKBOX", @@ -134,3 +125,37 @@ true, true ] call CBA_fnc_addSetting; +[ + "ASL_RopeUnwindSpeed", + "SLIDER", + [format[localize "STR_ROPE_UNWIND_SPEED"], format[localize "STR_ROPE_UNWIND_SPEED_TIP"]], + format[localize "STR_ASL_TITLE"], + [1, 10, 3, 0], + true, + {ASL_RopeUnwindSpeed = round(ASL_RopeUnwindSpeed)} +] call CBA_fnc_addSetting; +[ + "ASL_HeavyLiftAuthorized", + "CHECKBOX", + [format[localize "STR_HEAVY_LIFTING"], format[localize "STR_HEAVY_LIFTING_TIP"]], + format[localize "STR_ASL_TITLE"], + true, + true +] call CBA_fnc_addSetting; +[ + "ASL_MaxLiftableMassFactor", + "SLIDER", + [format[localize "STR_ASL_MAX_MASS"], format[localize "STR_ASL_MAX_MASS_TIP"]], + format[localize "STR_ASL_TITLE"], + [2, 20, 8, 0], + true, + {ASL_MaxLiftableMassFactor = round(ASL_MaxLiftableMassFactor)} +] call CBA_fnc_addSetting; +[ + "ASL_SelfAttachAuthorized", + "CHECKBOX", + [format[localize "STR_ASL_SELF_ATTACH"], format[localize "STR_ASL_SELF_ATTACH_TIP"]], + format[localize "STR_ASL_TITLE"], + true, + true +] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index b42357c..e74a2b6 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -100,14 +100,6 @@ Default liftable mass in kg a vehicle can lift. Standardschlinglastmasse in kg, die ein Fahrzeug anheben kann. - - - Maximum Liftable Mass Factor - Maximalschlinglastmassenfaktor - - - Maximum liftable mass factor a vehicle can lift (factor * vehicle lift capabilty). - Faktor, der die Maximalschlinglastmasse bestimmt (Faktor * Fahrzeughebekapazität). Deploy Cargo Ropes @@ -140,6 +132,10 @@ Attach To Cargo Ropes An Frachtseile Befestigen + + + Self Attach To Cargo Ropes + Sich Selbst An Frachtseile Befestigen Cannot deploy cargo ropes from locked vehicle @@ -297,7 +293,6 @@ Extend Cargo Ropes To Ground Frachtseile Bis Grund Verlängern - Rope Change Messages Seilveränderungsbenachrichtigungen @@ -306,5 +301,61 @@ Show rope changes to players via hints (rope length, etc.). Spieler erhalten per Hinweise Informationen über Seilveränderungen (Seillänge, etc.). + + + Load attached. + Ladung befestigt. + + + %1 t of %2 t remaining. + Verbleibend: %1 t von %2 t. + + + WARNING! Vehicle overloaded! + WARNUNG! Fahrzeug überladen! + + + Total load: %1 t, Max load: %2 t. + Gesammtlast: %1 t, Maximallast %2 t. + + + Rope Unwind Speed + Seillängenänderungsgeschwindigkeit + + + Speed of rope length changes in merter per second. + Geschwindigkeit von Seillängenveränderungen in Meter pro Sekunde. + + + Heavy Lifting + Schwerlast + + + Allow lifting of masses heavyer than default lifting capability. + Heben schwererer Massen erlauben, als die Standardmaximalschlinglast. + + + Heavy Lifting Max Mass Factor + Schwerlast Maximalschlinglastmassenfaktor + + + Maximum liftable mass factor a vehicle can lift (e.g. CH-47 has a default of 12t max mass. A factor of 5 would result: 5 * 12 = 60t max liftable mass. Only valid with 'Heavy Lifting Max Mass Factor' allowed). + Faktor, der die Maximalschlinglastmasse bestimmt (z.b. hat der CH-47 eine Standardmaximalschlinglast von 12t. Ein Faktor von 5 heißt: 5 * 12 = 60t Maximalschlinglast. Nur gültig wenn 'Schwerlast Maximalschlinglastmassenfaktor' erlaubt). + + + Allow Self Attach + Erlaube Selbstbefestigung + + + Allow self attachment to cargo ropes. + Selbstbefestigung an Lastseile erlauben. + + + Detach From Ropes + Von Seilen Loslösen + \ No newline at end of file diff --git a/mod.cpp b/mod.cpp index 8f7e93e..bf26b1d 100644 --- a/mod.cpp +++ b/mod.cpp @@ -3,7 +3,7 @@ picture = "logo.paa"; description = "NIC Advanced Sling Loading"; logo = "logo.paa"; logoOver = "logo.paa"; -tooltip = "NIC Advanced Sling Loading v2.1.1c"; +tooltip = "NIC Advanced Sling Loading v2.1.1d"; tooltipOwned = "NIC Advanced Sling Loading Owned"; overview = "NIC Advanced Sling Loading"; author = "[SA] Duda"; From fdc37154e215da4bd374427ae22a966826d6c945 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Mon, 24 May 2021 23:11:48 +0200 Subject: [PATCH 19/24] Weekend changes --- .../functions/fn_advancedSlingLoadingInit.sqf | 169 ++++++++++-------- 1 file changed, 95 insertions(+), 74 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 21e4ebf..2248230 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -934,6 +934,7 @@ ASL_Advanced_Sling_Loading_Install = { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Deploy_Ropes_Action_Check) EXIT 3"]; [_vehicle, _unit] call ASL_Can_Deploy_Ropes }; + false }; @@ -1060,12 +1061,22 @@ ASL_Advanced_Sling_Loading_Install = { private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; private _cargoRopes = []; + // for "_i" from 1 to 4 do { + // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; + // }; + // { + // _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope + // } forEach _cargoRopes; + private ["_rope"]; for "_i" from 1 to 4 do { - _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; - }; - { - _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - } forEach _cargoRopes; + _rope = ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; + _rope allowDamage false; + _rope setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope + _cargoRopes pushBack _rope; + }; + // { + // _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope + // } forEach _cargoRopes; [_vehicle, _cargoRopes, ASL_RopeUnwindSpeed + 2, ASL_InitialDeployRopeLength, false] spawn ASL_Unwind_Ropes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; _allRopes set [_ropesIndex, _cargoRopes]; @@ -1176,7 +1187,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; private _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; + diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; private _closestRope = objNull; @@ -1251,19 +1262,19 @@ ASL_Advanced_Sling_Loading_Install = { ]; _unit setVariable ["ASL_ActionID_Drop", _actionID]; }; - if (isNil{_unit getVariable "ASL_ActionID_AttachSelf"}) then { - _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes - format[localize "STR_ASL_SELF_ATTACH"], // Title - {[_this #0, true] call ASL_Attach_Ropes_Action}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_this, true] call ASL_Attach_Ropes_Action_Check" // Condition - ]; - _unit setVariable ["ASL_ActionID_AttachSelf", _actionID]; - }; + // if (isNil{_unit getVariable "ASL_ActionID_AttachSelf"}) then { + // _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes + // format[localize "STR_ASL_SELF_ATTACH"], // Title + // {[_this #0, true] call ASL_Attach_Ropes_Action}, // Script + // nil, // Arguments + // 0, // Priority + // false, // showWindow + // true, // hideOnUse + // "", // Shortcut + // "[_this, true] call ASL_Attach_Ropes_Action_Check" // Condition + // ]; + // _unit setVariable ["ASL_ActionID_AttachSelf", _actionID]; + // }; }; // ASL_Pickup_Ropes_Action_Check = { @@ -1429,64 +1440,71 @@ ASL_Advanced_Sling_Loading_Install = { if (count _ropes != 4) exitWith {}; private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _attachmentPoints: ", _attachmentPoints, ", _self: ", _self]; - if (_self) then {_attachmentPoints = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]}; + // if (_self) then {_attachmentPoints = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]}; private _ropeLength = (ropeLength (_ropes #0)); private _objDistance = (_cargo distance _vehicle) + 2; - if (_objDistance > _ropeLength) then { - [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; - } else { - private _ropesIndex = _vehicleWithIndex #1; - _cargo setVariable ["ASL_CarrierVehicle", _vehicle, true]; - [_vehicle, _cargo] spawn { - params [["_vehicle", objNull], ["_cargo", objNull]]; - if (isNull _vehicle || isNull _cargo) exitWith {}; - while {alive _vehicle && alive _cargo && _cargo in ropeAttachedObjects _vehicle} do { - sleep 1; - }; - _cargo setVariable ["ASL_CarrierVehicle", nil, true]; + // if (_objDistance > _ropeLength) then { + // [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; + // } else { + if (_objDistance > _ropeLength) exitWith {[[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; + private _ropesIndex = _vehicleWithIndex #1; + _cargo setVariable ["ASL_CarrierVehicle", _vehicle, true]; + [_vehicle, _cargo] spawn { + params [["_vehicle", objNull], ["_cargo", objNull]]; + if (isNull _vehicle || isNull _cargo) exitWith {}; + while {alive _vehicle && alive _cargo && _cargo in ropeAttachedObjects _vehicle} do { + sleep 1; }; - [_vehicle, _unit] call ASL_Drop_Ropes; - - - - - // for "_i" from 0 to 3 do { - // [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); - // }; - - - - // for "_i" from 0 to 3 do { - // [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); - // }; - - + _cargo setVariable ["ASL_CarrierVehicle", nil, true]; + }; + [_vehicle, _unit] call ASL_Drop_Ropes; + + // if (_self) then { + // for "_i" from 0 to 3 do { + // [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); + // }; + // } else { + // for "_i" from 0 to 3 do { + // [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); + // }; + // }; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - _allCargo set [(_vehicleWithIndex #1), _cargo]; - _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { - [_vehicle, _cargo, _ropes] spawn ASL_Rope_Adjust_Mass; + if (_self) then { + for "_i" from 0 to 3 do { + [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); + [_cargo, _ropes #_i] remoteExecCall ["disableCollisionWith", 0, _cargo]; }; - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_AttachSelf"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo - _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; - if (_self) exitWith { - if (isNil{_unit getVariable "ASL_ActionID_Detach"}) then { - _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes - format[localize "STR_ASL_DETACH"], // Title - {[_this #0, true] call ASL_Drop_Ropes_Action}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_this] call ASL_Drop_Ropes_Action_Check" // Condition - ]; - _unit setVariable ["ASL_ActionID_Detach", _actionID]; - }; + } else { + for "_i" from 0 to 3 do { + [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); }; - _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; }; + + private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; + _allCargo set [(_vehicleWithIndex #1), _cargo]; + _vehicle setVariable ["ASL_Cargo", _allCargo, true]; + if (missionNamespace getVariable ["ASL_HEAVY_LIFTING_ENABLED", true]) then { + [_vehicle, _cargo, _ropes] spawn ASL_Rope_Adjust_Mass; + }; + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_AttachSelf"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo + _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; + if (_self) exitWith { + if (isNil{_unit getVariable "ASL_ActionID_Detach"}) then { + _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes + format[localize "STR_ASL_DETACH"], // Title + {[_this #0, true] call ASL_Drop_Ropes_Action}, // Script + nil, // Arguments + 0, // Priority + false, // showWindow + true, // hideOnUse + "", // Shortcut + "[_this] call ASL_Drop_Ropes_Action_Check" // Condition + ]; + _unit setVariable ["ASL_ActionID_Detach", _actionID]; + }; + }; + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + // }; }; ASL_Drop_Ropes_Action_Check = { @@ -1499,6 +1517,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull], ["_self", false]]; if (isNull _unit) exitWith {false}; private _vehicleAndIndex = _unit getVariable ["ASL_Ropes_Vehicle", []]; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Drop_Ropes_Action) _unit: ", _unit, ", _self: ", _self, ", _vehicleAndIndex: ", _vehicleAndIndex]; if (count _vehicleAndIndex == 2) then { [_vehicleAndIndex #0, _unit, _vehicleAndIndex #1, _self] call ASL_Drop_Ropes; }; @@ -1511,18 +1530,20 @@ ASL_Advanced_Sling_Loading_Install = { private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (_self) then {_helper = _unit}; + diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Drop_Ropes) _unit: ", _unit, ", _self: ", _self, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; if (!isNull _helper) then { private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; { _helper ropeDetach _x; } forEach _existingRopes; detach _helper; - if (_self) exitWith { - _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; - }; + // if (_self) exitWith { + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + // }; deleteVehicle _helper; }; - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes + // [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; From 5fad3c26ce3cbe9a9227ed67f7b05d284e06448f Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Tue, 10 Aug 2021 08:16:50 +0200 Subject: [PATCH 20/24] minor changes --- .../functions/fn_advancedSlingLoadingInit.sqf | 314 ++++-------------- 1 file changed, 68 insertions(+), 246 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 2248230..278da64 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -150,7 +150,7 @@ ASL_Advanced_Sling_Loading_Install = { /* some of the vehicles have maximal sling load values differing frome the ones given by their "slingLoadMaxCargoMass" config entries; - values in the list below were obzained by experimentation */ + values in the list below were obzained by empiricism */ ASL_SLING_LOAD_LIFT_CAPABILITY = [ ["UAV_01_base_F", 50], ["UAV_06_base_F", 260], @@ -197,17 +197,17 @@ ASL_Advanced_Sling_Loading_Install = { if (ASL_HeavyLiftAuthorized) then {_maxLiftableMass = _maxLiftableMass * ASL_MaxLiftableMassFactor}; private _originalMass = getMass _cargo; private _heavyLiftMinLift = missionNamespace getVariable ["ASL_HEAVY_LIFTING_MIN_LIFT_OVERRIDE", 5000]; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11", time, - "s (ASL_Rope_Adjust_Mass) _cargo: ", _cargo, - " _originalMass: ", _originalMass, - " _vehicle: ", _vehicle, - " _lift: ", _lift, - " _heavyLiftMinLift: ", _heavyLiftMinLift - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11", time, + // "s (ASL_Rope_Adjust_Mass) _cargo: ", _cargo, + // " _originalMass: ", _originalMass, + // " _vehicle: ", _vehicle, + // " _lift: ", _lift, + // " _heavyLiftMinLift: ", _heavyLiftMinLift + // ]; if (_originalMass >= _lift * 0.8 && _lift >= _heavyLiftMinLift && _originalMass <= _maxLiftableMass && ASL_HeavyLiftAuthorized) then { [[_cargo, _originalMass], "ASL_Rope_Set_Mass", _cargo, true] call ASL_RemoteExec; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Adjust_Mass) Mass is being adjusted!"]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Rope_Adjust_Mass) Mass is being adjusted!"]; [_vehicle, _cargo, _originalMass, _lift, _maxLiftableMass] spawn { params [["_vehicle", objNull], ["_cargo", objNull], ["_originalMass", 0], ["_lift", 0], ["_maxLiftableMass", 0]]; if (isNull _vehicle || isNull _cargo || _originalMass == 0 || _lift == 0 || _maxLiftableMass == 0) exitWith {}; @@ -223,15 +223,12 @@ ASL_Advanced_Sling_Loading_Install = { params [["_vehicle", objNull], ["_originalMass", 0], ["_lift", 0]]; if (isNull _vehicle || _originalMass == 0 || _lift == 0) exitWith {}; sleep 0.2; - // private _messageText = format[localize "STR_ASL_SLING_MASS", (_originalMass / 1000) toFixed 2]; private _messageText = format[localize "STR_ASL_SLING_MASS"]; private _totalSlingMass = 0; { _totalSlingMass = _totalSlingMass + getMass _x; } forEach ropeAttachedObjects _vehicle; if (_totalSlingMass > _lift) then { - // private _vehicleName = getText (configfile >> "CfgVehicles" >> typeOf _vehicle >> "displayName"); - // _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD", _vehicleName]]; _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD"]]; _messageText = formatText ["%1%2%3", _messageText, lineBreak, format[localize "STR_ASL_OVERLOAD_MASS", (_totalSlingMass / 1000) toFixed 2, (_lift / 1000) toFixed 2]]; } else { @@ -303,10 +300,11 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Ropes = { - params [["_vehicle", objNull], "_ropesIndex"]; + params [["_vehicle", objNull], ["_ropesIndex", 0]]; if (isNull _vehicle) exitWith {}; private _selectedRopes = []; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Is_Unit_Authorized) _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex], ", _allRopes: ", _allRopes; if (count _allRopes > _ropesIndex) then { _selectedRopes = _allRopes #_ropesIndex; }; @@ -320,7 +318,7 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Cargo = { - params [["_vehicle", objNull], "_ropesIndex"]; + params [["_vehicle", objNull], ["_ropesIndex", 0]]; if (isNull _vehicle) exitWith {}; private _selectedCargo = objNull; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; @@ -331,7 +329,7 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Get_Ropes_And_Cargo = { - params [["_vehicle", objNull], "_ropesIndex"]; + params [["_vehicle", objNull], ["_ropesIndex", 0]]; if (isNull _vehicle) exitWith {}; private _selectedCargo = (_this call ASL_Get_Cargo); private _selectedRopes = (_this call ASL_Get_Ropes); @@ -362,8 +360,6 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle getCargoIndex _unit > -1 && ASL_PassengersAuthorized) exitWith {true}; if !(ASL_CopilotsAuthorized) exitWith {false}; - // private _cfg = configFile >> "CfgVehicles" >> typeOf _vehicle; - // private _turrets = _cfg >> "turrets"; private _turrets = configFile >> "CfgVehicles" >> typeOf _vehicle >> "turrets"; private _isCopilot = false; for "_i" from 0 to (count _turrets - 1) do { @@ -384,9 +380,6 @@ ASL_Advanced_Sling_Loading_Install = { if (count ([_vehicle, true] call ASL_Get_Active_Ropes) == 0) exitWith {false}; private _exit = false; if (_toGround) then { - // private _ropeEndHeight = ropeEndPosition (_allRopes #0 #0) #1 #2; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Extend_Ropes) _vehicleHeight: ", _vehicleHeight, ", _ropeEndHeight: ", _ropeEndHeight]; - // if (_ropeEndHeight < ASL_ExtendShortenRopeLength) exitWith {_exit = true}; if (ropeEndPosition (_allRopes #0 #0) #1 #2 < ASL_ExtendShortenRopeLength) exitWith {_exit = true}; private _vehicleHeight = getPos _vehicle #2; if (_vehicleHeight < ASL_ExtendShortenRopeLength || _vehicleHeight > ASL_MaxRopeLength) then {_exit = true}; @@ -410,7 +403,6 @@ ASL_Advanced_Sling_Loading_Install = { private _ropeLength = [_vehicle, _activeRopes #0 #0, _toGround] call ASL_Extend_Ropes; if (_ropeLength <= ASL_MaxRopeLength) exitWith { if (ASL_RopeMessagesAuthorized) then { - // private _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO", _ropeLength]; if (_toGround) then {_messageText = format[localize "STR_ASL_ROPES_EXTENDED_TO_G", _ropeLength]}; if (_ropeLength == ASL_MaxRopeLength) then { @@ -418,7 +410,7 @@ ASL_Advanced_Sling_Loading_Install = { }; hint _messageText; }; - diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Extend_Ropes_Action) can release cargo: ", [_vehicle, _unit] call ASL_Can_Release_Cargo]; if (_toGround && _canReleaseCargo) then { private _rope = (_vehicle getVariable "ASL_Ropes") #0 #0; private _cargo = (_vehicle getVariable "ASL_Cargo") #0; @@ -434,8 +426,7 @@ ASL_Advanced_Sling_Loading_Install = { if (count _extendedRopes == 0) exitWith {}; private ["_extendedRopeIndex", "_activeCargoRopes"]; _messageText = format[localize "STR_ASL_ROPES_EXTENDED"]; - if (_toGround) then { - // _messageText = formatText ["%1%2%3", _messageText, " ", format[localize "STR_ASL_ROPES_EXTENDED_TG"]]; + if (_toGround) then { _messageText = format[localize "STR_ASL_ROPES_EXTENDED_TG", _messageText]; _activeCargoRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; }; @@ -478,7 +469,6 @@ ASL_Advanced_Sling_Loading_Install = { // ", _cargo: ", _cargo // ]; if (isNull _vehicle || isNull _unit || isNull _rope || _ropeLength == 0 || isNull _cargo) exitWith {}; - // private _future = time + 60; private _future = time + 20 + 100 / ASL_RopeUnwindSpeed; sleep 1; while { @@ -498,7 +488,7 @@ ASL_Advanced_Sling_Loading_Install = { // ", alive _cargo: ", alive _cargo, // ", getPos _cargo #2 > 1: ", getPos _cargo #2 > 1 // ]; - if (!alive _vehicle || (getPos _cargo #2 > 5 && alive _cargo)) exitWith {}; + if (!alive _vehicle || (getPos _cargo #2 > 5 && getPosASL _cargo #2 > 5 && alive _cargo)) exitWith {}; [_ropesIndex, _vehicle, _unit] call ASL_Release_Cargo_Index_Action; }; @@ -565,14 +555,14 @@ ASL_Advanced_Sling_Loading_Install = { if (_ropeLength + _unwindLength > ASL_MaxRopeLength) then { _unwindLength = ASL_MaxRopeLength - _ropeLength; }; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, - "s (ASL_Extend_Ropes) _unwindLength: ", _unwindLength, - ", vehicle height: ", getPos _vehicle #2, - ", ASL_MaxRopeLength: ", ASL_MaxRopeLength, - ", _ropeLength: ", _ropeLength, - ", _ropesIndex: ", _ropesIndex - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11%12%13", time, + // "s (ASL_Extend_Ropes) _unwindLength: ", _unwindLength, + // ", vehicle height: ", getPos _vehicle #2, + // ", ASL_MaxRopeLength: ", ASL_MaxRopeLength, + // ", _ropeLength: ", _ropeLength, + // ", _ropesIndex: ", _ropesIndex + // ]; [_vehicle, _existingRopes, ASL_RopeUnwindSpeed, _unwindLength] spawn ASL_Unwind_Ropes; _ropeLength = _ropeLength + _unwindLength; _ropeLength @@ -580,7 +570,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Unwind_Ropes = { params [["_vehicle", objNull], ["_ropes", []], ["_speed", 3], ["_length", 0], ["_relative", true]]; - diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Unwind_Ropes) _vehicle: ", _vehicle, ", _ropes: ", _ropes, ", _length: ", _length, ", _relative: ", _relative]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Unwind_Ropes) _vehicle: ", _vehicle, ", _ropes: ", _ropes, ", _length: ", _length, ", _relative: ", _relative]; if (isNull _vehicle) exitWith {}; private _sound = "SA_SlingLoadUpExt"; if (_length > 0) then {_sound = "SA_SlingLoadDownExt"}; @@ -651,8 +641,7 @@ ASL_Advanced_Sling_Loading_Install = { { if (_x #1 >= ASL_MinRopeLength) then { _shortenedRopesIndex = _x#0; - // _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", _activeRopes #_x #0 #1, _x #1]]; - _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", (_activeRopes select {_x#0 == _shortenedRopesIndex})#0#1, _x#1]]; + _messageText = formatText ["%1%2%3%4%5%6", _messageText, lineBreak, format[localize "STR_ASL_ROPES_SHORTENED_TO_IND", (_activeRopes select {_x #0 == _shortenedRopesIndex}) #0 #1, _x #1]]; if (_x #1 == ASL_MinRopeLength) then { _messageText = formatText ["%1%2", _messageText, " (min)"]; }; @@ -667,7 +656,7 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Shorten_Ropes_Index_Action = { - params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; + params [["_ropesIndex", 0], ["_vehicle", objNull], ["_unit", objNull]]; if (isNull _vehicle || isNull _unit) exitWith {}; if (_ropesIndex >= 0 && !isNull _vehicle && [_vehicle] call ASL_Can_Shorten_Ropes) then { private _ropeLength = [_vehicle, _ropesIndex] call ASL_Shorten_Ropes; @@ -749,7 +738,7 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Release_Cargo_Index_Action = { - params ["_ropesIndex", ["_vehicle", objNull], ["_unit", objNull]]; + params [["_ropesIndex", 0], ["_vehicle", objNull], ["_unit", objNull]]; diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo_Index_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; if (isNull _vehicle || isNull _unit) exitWith {}; if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Release_Cargo) then { @@ -768,8 +757,6 @@ ASL_Advanced_Sling_Loading_Install = { { _existingCargo ropeDetach _x; } forEach _existingRopes; - // _existingCargo setVariable ["ASL_RopesIndex", nil, true]; - // _existingCargo setVariable ["ASL_CarrierVehicle", nil, true]; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [_ropesIndex, objNull]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; @@ -858,42 +845,35 @@ ASL_Advanced_Sling_Loading_Install = { if (count _cargoArray > 0) then { private _helper = (_cargoArray select {_x getVariable ["ASL_Ropes_Pick_Up_Helper", false]}) #0; if (isNil {_helper}) exitWith {}; - // if (!isNull _helper) then { private _ropeHolder = attachedTo _helper; if (!isNull _ropeHolder) then {_unit = _ropeHolder}; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes) _helper: ", _helper, " _ropeHolder: ", _ropeHolder]; - // }; }; if (isNull _existingCargo) then { [_vehicle, _unit, _ropesIndex] call ASL_Drop_Ropes; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11%12", time, - "s (ASL_Retract_Ropes) _existingRopes: ", _existingRopes, - // ", Ropes_Without_Cargo: ", [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo, - // ", _allRopes: ", _vehicle getVariable ["ASL_Ropes", []], - ", _activeRopes: ", [_vehicle, true] call ASL_Get_Active_Ropes, - ", _inactiveRopes: ", [_vehicle] call ASL_Get_Active_Ropes - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11%12", time, + // "s (ASL_Retract_Ropes) _existingRopes: ", _existingRopes, + // // ", Ropes_Without_Cargo: ", [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo, + // // ", _allRopes: ", _vehicle getVariable ["ASL_Ropes", []], + // ", _activeRopes: ", [_vehicle, true] call ASL_Get_Active_Ropes, + // ", _inactiveRopes: ", [_vehicle] call ASL_Get_Active_Ropes + // ]; [_vehicle, _existingRopes, ASL_RopeUnwindSpeed, 0, false] spawn ASL_Unwind_Ropes; { - // [_x, _vehicle] spawn { - // params ["_rope", "_vehicle"]; [_vehicle, _x] spawn { params [["_vehicle", objNull], ["_rope", objNull]]; if (isNull _vehicle || isNull _rope) exitWith {false}; sleep 1; if (isNull _rope || isNull _vehicle) exitWith {}; - // private _future = time + 60; private _future = time + 20 + 100 / ASL_RopeUnwindSpeed; - // ropeUnwind [_rope, 3, 0]; - // [_vehicle, [_rope]] spawn ASL_Unwind_Ropes; while {!ropeUnwound _rope && alive _vehicle && time < _future} do {sleep 1}; - diag_log formatText [ - "%1%2%3%4%5%6%7%8%9%10%11%12", time, - "s (ASL_Retract_Ropes) Rope destroyed! !ropeUnwound _rope: ", !ropeUnwound _rope, - ", vehicle alive: ", alive _vehicle, - ", time < _future: ", time < _future - ]; + // diag_log formatText [ + // "%1%2%3%4%5%6%7%8%9%10%11%12", time, + // "s (ASL_Retract_Ropes) Rope destroyed! !ropeUnwound _rope: ", !ropeUnwound _rope, + // ", vehicle alive: ", alive _vehicle, + // ", time < _future: ", time < _future + // ]; ropeDestroy _rope; }; } forEach _existingRopes; @@ -1061,12 +1041,6 @@ ASL_Advanced_Sling_Loading_Install = { private _existingRopesCount = [_vehicle] call ASL_Get_Ropes_Count; private _slingLoadPoints = [_vehicle] call ASL_Get_Sling_Load_Points; private _cargoRopes = []; - // for "_i" from 1 to 4 do { - // _cargoRopes pushBack ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; - // }; - // { - // _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - // } forEach _cargoRopes; private ["_rope"]; for "_i" from 1 to 4 do { _rope = ropeCreate [_vehicle, (_slingLoadPoints select (_existingRopesCount - 1)) #_ropesIndex, 0]; @@ -1074,9 +1048,6 @@ ASL_Advanced_Sling_Loading_Install = { _rope setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope _cargoRopes pushBack _rope; }; - // { - // _x setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; // memory vehicle and rope index on each rope - // } forEach _cargoRopes; [_vehicle, _cargoRopes, ASL_RopeUnwindSpeed + 2, ASL_InitialDeployRopeLength, false] spawn ASL_Unwind_Ropes; private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; _allRopes set [_ropesIndex, _cargoRopes]; @@ -1276,121 +1247,6 @@ ASL_Advanced_Sling_Loading_Install = { // _unit setVariable ["ASL_ActionID_AttachSelf", _actionID]; // }; }; - - // ASL_Pickup_Ropes_Action_Check = { - // params [["_vehicle", objNull], ["_unit", objNull]]; - // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _vehicle: ", _vehicle, " _unit: ", _unit]; - // if (isNull _vehicle || isNull _unit) exitWith {false}; - // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) vehicle _unit != _unit: ", vehicle _unit != _unit]; - // if (vehicle _unit != _unit) exitWith {false}; - // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) ASL_Ropes_Pick_Up_Helper: ", isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}]; - // if !(isNil{_unit getVariable "ASL_Ropes_Pick_Up_Helper"}) exitWith {false}; - // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - // // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action_Check) _allRopes: ", _allRopes]; - // if (count _allRopes == 0) exitWith {false}; - // private _pickup = false; - // private _ropeHandlingDistance = ASL_RopeHandlingDistance; - // if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; - // private ["_ropeBundle"]; - // { - // _ropeBundle = _x; - // { - // if (alive _x && (_unit distance (ropeEndPosition _x #1)) < _ropeHandlingDistance) exitWith {_pickup = true}; - // } forEach _ropeBundle; - // } forEach _allRopes; - // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Pickup_Ropes_Action_Check) _ropeHandlingDistance: ", _ropeHandlingDistance, "m , dist to end: ", (_unit distance (ropeEndPosition (_allRopes #0 #0) #1)), "m , _pickup: ", _pickup]; - // _pickup - // }; - - // ASL_Pickup_Ropes_Action = { - // params [["_vehicle", objNull], ["_unit", objNull]]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; - // if (isNull _vehicle || isNull _unit) exitWith {false}; - // private _allRopes = _vehicle getVariable ["ASL_Ropes", []]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _allRopes: ", _allRopes]; - // if (count _allRopes == 0) exitWith {}; - // private _ropeHandlingDistance = ASL_RopeHandlingDistance; - // if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; - // private _unitRopes = _unit getVariable ["ASL_Ropes_Near_Unit", []]; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _unitRopes: ", _unitRopes, ", _ropeHandlingDistance: ", _ropeHandlingDistance]; - // private ["_ropeBundle"]; - // { - // _ropeBundle = _x; - // { - // if (alive _x && (_unit distance (ropeEndPosition _x #1)) < _ropeHandlingDistance) then {_unitRopes pushBack _x}; - // } forEach _ropeBundle; - // } forEach _allRopes; - // _unitRopes = _unitRopes - [objNull]; // remove any no longer existing ropes - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) _unitRopes: ", _unitRopes]; - // _unitRopes = [_unitRopes, [], {_unit distance (ropeEndPosition _x #1)}, "ASCEND"] call BIS_fnc_sortBy; - // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) distance rope ends to unit ", _unit, ":"]; - // { - // diag_log formatText ["%1%2%3%4%5%6", time, "s (ASL_Pickup_Ropes_Action) rope ", _x, ": ", _unit distance (ropeEndPosition _x #1), " m"]; - // } forEach _unitRopes; - // _unit setVariable ["ASL_Ropes_Near_Unit", _unitRopes]; // save array on unit in case more than one vehicle have ropes deployed - // if (count _unitRopes == 0) exitWith {}; - // private _closestRope = _unitRopes #0; - // private _vehicle = (_closestRope getVariable "ASL_Ropes_Vehicle") #0; - // if (isNull _vehicle) exitWith {}; - // if (locked _vehicle > 1 && !(missionNamespace getVariable ["ASL_LOCKED_VEHICLES_ENABLED", false])) exitWith { - // [format[localize "STR_ASL_CANT_PICKUP"], false] call ASL_Hint; - // }; - // private _ropesIndex = (_closestRope getVariable "ASL_Ropes_Vehicle") #1; - // [_vehicle, _unit, _ropesIndex] call ASL_Pickup_Ropes; - // }; - - // ASL_Pickup_Ropes = { - // params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; - // if (isNull _vehicle || isNull _unit) exitWith {}; - // if !(local _vehicle) exitWith {[_this, "ASL_Pickup_Ropes", _vehicle, true] call ASL_RemoteExec}; - // private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; - // private _existingRopes = _existingRopesAndCargo #0; - // private _existingCargo = _existingRopesAndCargo #1; - // if (!isNull _existingCargo) then { - // { - // _existingCargo ropeDetach _x; - // } forEach _existingRopes; - // private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; - // _allCargo set [_ropesIndex, objNull]; - // _vehicle setVariable ["ASL_Cargo", _allCargo, true]; - // }; - // private _helper = "Land_Can_V2_F" createVehicle position _unit; - // _helper setVariable ["ASL_Ropes_Pick_Up_Helper", true, true]; - // { - // [_helper, [0, 0, 0], [0, 0, -1]] ropeAttachTo _x; - // _helper attachTo [_unit, [-0.1, 0.1, 0.15], "Pelvis"]; - // } forEach _existingRopes; - // hideObjectGlobal _helper; - // _unit setVariable ["ASL_Ropes_Vehicle", [_vehicle, _ropesIndex], true]; - // _unit setVariable ["ASL_Ropes_Pick_Up_Helper", _helper, true]; - // private ["_actionID"]; - // if (isNil{_unit getVariable "ASL_ActionID_Attach"}) then { - // _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes - // format[localize "STR_ASL_ATTACH"], // Title - // {[_this #0] call ASL_Attach_Ropes_Action}, // Script - // nil, // Arguments - // 0, // Priority - // false, // showWindow - // true, // hideOnUse - // "", // Shortcut - // "[_this] call ASL_Attach_Ropes_Action_Check" // Condition - // ]; - // _unit setVariable ["ASL_ActionID_Attach", _actionID]; - // }; - // if (isNil{_unit getVariable "ASL_ActionID_Drop"}) then { - // _actionID = _unit addAction [ // add 'drop ropes' action, once unit has picked up some ropes - // format[localize "STR_ASL_DROP"], // Title - // {[_this #0] call ASL_Drop_Ropes_Action}, // Script - // nil, // Arguments - // 0, // Priority - // false, // showWindow - // true, // hideOnUse - // "", // Shortcut - // "[_this] call ASL_Drop_Ropes_Action_Check" // Condition - // ]; - // _unit setVariable ["ASL_ActionID_Drop", _actionID]; - // }; - // }; ASL_Attach_Ropes_Action_Check = { params [["_unit", objNull], ["_self", false]]; @@ -1440,13 +1296,9 @@ ASL_Advanced_Sling_Loading_Install = { if (count _ropes != 4) exitWith {}; private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _attachmentPoints: ", _attachmentPoints, ", _self: ", _self]; - // if (_self) then {_attachmentPoints = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]}; private _ropeLength = (ropeLength (_ropes #0)); private _objDistance = (_cargo distance _vehicle) + 2; - // if (_objDistance > _ropeLength) then { - // [[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec; - // } else { - if (_objDistance > _ropeLength) exitWith {[[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; + if (_objDistance > _ropeLength && !_self) exitWith {[[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; private _ropesIndex = _vehicleWithIndex #1; _cargo setVariable ["ASL_CarrierVehicle", _vehicle, true]; [_vehicle, _cargo] spawn { @@ -1457,29 +1309,15 @@ ASL_Advanced_Sling_Loading_Install = { }; _cargo setVariable ["ASL_CarrierVehicle", nil, true]; }; - [_vehicle, _unit] call ASL_Drop_Ropes; - - // if (_self) then { - // for "_i" from 0 to 3 do { - // [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); - // }; - // } else { - // for "_i" from 0 to 3 do { - // [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); - // }; - // }; - + [_vehicle, _unit, _ropesIndex, _self] call ASL_Drop_Ropes; + diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Attach_Ropes) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; if (_self) then { - for "_i" from 0 to 3 do { - [_cargo, [0.1, 0.1, 0.15], "Pelvis"] ropeAttachTo (_ropes #_i); - [_cargo, _ropes #_i] remoteExecCall ["disableCollisionWith", 0, _cargo]; - }; + [_vehicle, _unit, _ropesIndex] spawn ASL_Self_Attach; } else { for "_i" from 0 to 3 do { [_cargo, _attachmentPoints #_i, [0, 0, -1]] ropeAttachTo (_ropes #_i); }; }; - private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [(_vehicleWithIndex #1), _cargo]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; @@ -1488,23 +1326,23 @@ ASL_Advanced_Sling_Loading_Install = { }; [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_AttachSelf"]] call ASL_Remove_Actions; // remove 'drop ropes' and 'attach ropes' actions, once unit has attached ropes to some cargo _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; - if (_self) exitWith { - if (isNil{_unit getVariable "ASL_ActionID_Detach"}) then { - _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes - format[localize "STR_ASL_DETACH"], // Title - {[_this #0, true] call ASL_Drop_Ropes_Action}, // Script - nil, // Arguments - 0, // Priority - false, // showWindow - true, // hideOnUse - "", // Shortcut - "[_this] call ASL_Drop_Ropes_Action_Check" // Condition - ]; - _unit setVariable ["ASL_ActionID_Detach", _actionID]; - }; - }; + // if (_self) exitWith { + // if (isNil{_unit getVariable "ASL_ActionID_Detach"}) then { + // _actionID = _unit addAction [ // add 'attach to' action, once unit has picked up some ropes + // format[localize "STR_ASL_DETACH"], // Title + // // {[_this #0, true] call ASL_Drop_Ropes_Action}, // Script + // {[_this #0] call ASL_Drop_Ropes_Action}, // Script + // nil, // Arguments + // 0, // Priority + // false, // showWindow + // true, // hideOnUse + // "", // Shortcut + // "[_this] call ASL_Drop_Ropes_Action_Check" // Condition + // ]; + // _unit setVariable ["ASL_ActionID_Detach", _actionID]; + // }; + // }; _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; - // }; }; ASL_Drop_Ropes_Action_Check = { @@ -1528,7 +1366,6 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle || isNull _unit) exitWith {}; if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); - // private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; if (_self) then {_helper = _unit}; diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Drop_Ropes) _unit: ", _unit, ", _self: ", _self, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; if (!isNull _helper) then { @@ -1537,13 +1374,12 @@ ASL_Advanced_Sling_Loading_Install = { _helper ropeDetach _x; } forEach _existingRopes; detach _helper; - // if (_self) exitWith { - _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; - // }; + if (!_self) then { + _unit setVariable ["ASL_Ropes_Vehicle", nil, true]; + }; deleteVehicle _helper; }; - // [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes - [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes + [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; @@ -1602,7 +1438,6 @@ ASL_Advanced_Sling_Loading_Install = { if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {}; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Add_Vehicle_Actions) _vehicle: ", _vehicle, ", mass: ", getMass _vehicle, ", min: ", ASL_MinVehicleMass]; if (getMass _vehicle < ASL_MinVehicleMass) exitWith { - // [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release", "ASL_ActionID_Pickup"]] call ASL_Remove_Actions; [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release"]] call ASL_Remove_Actions; }; private ["_actionID"]; @@ -1684,19 +1519,6 @@ ASL_Advanced_Sling_Loading_Install = { ]; _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; - // if (isNil{_vehicle getVariable "ASL_ActionID_Pickup"}) then { - // _actionID = _vehicle addAction [ - // format[localize "STR_ASL_PICKUP"], // Title - // {[_this #0, _this #1] call ASL_Pickup_Ropes_Action}, // Script - // nil, // Arguments - // 0, // Priority - // false, // showWindow - // true, // hideOnUse - // "", // Shortcut - // "[_target, _this] call ASL_Pickup_Ropes_Action_Check" // Condition - // ]; - // _vehicle setVariable ["ASL_ActionID_Pickup", _actionID]; - // }; }; ASL_Remove_Actions = { @@ -1808,6 +1630,6 @@ if (isServer) then { if (isNil "ASL_RopeUnwindSpeed") then {ASL_RopeUnwindSpeed = 3}; // ropes unwinding speed if (isNil "ASL_HeavyLiftAuthorized") then {ASL_HeavyLiftAuthorized = true}; // heavy lifting allowed if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) - if (isNil "ASL_SelfAttachAuthorized") then {ASL_SelfAttachAuthorized = true}; // allow self attachment to cargo ropes + // if (isNil "ASL_SelfAttachAuthorized") then {ASL_SelfAttachAuthorized = true}; // allow self attachment to cargo ropes [] call ASL_Advanced_Sling_Loading_Install; }; From 9724978d1fc8c081932d2e8dc70d2e4e80578f40 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Mon, 23 Aug 2021 12:33:45 +0200 Subject: [PATCH 21/24] 2.1.1e - added hint when cargo gets released - Deploy ropes: added check, if vehicle is destroyed --- .../functions/fn_advancedSlingLoadingInit.sqf | 28 +++++++++++++++++-- .../NIC_AdvancedSlingLoading/stringtable.xml | 8 +++--- mod.cpp | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 278da64..6d4687f 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -727,7 +727,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo_Action = { params [["_vehicle", objNull], ["_unit", objNull]]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Release_Cargo_Action) _vehicle: ", _vehicle, " _unit: ", _unit]; if (isNull _vehicle || isNull _unit) exitWith {false}; if !([_vehicle, _unit] call ASL_Can_Release_Cargo) exitWith {false}; private _activeRopes = [_vehicle, _unit] call ASL_Get_Active_Ropes_With_Cargo; @@ -739,7 +739,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Release_Cargo_Index_Action = { params [["_ropesIndex", 0], ["_vehicle", objNull], ["_unit", objNull]]; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo_Index_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo_Index_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; if (isNull _vehicle || isNull _unit) exitWith {}; if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Release_Cargo) then { [_vehicle, _unit, _ropesIndex] call ASL_Release_Cargo; @@ -757,12 +757,33 @@ ASL_Advanced_Sling_Loading_Install = { { _existingCargo ropeDetach _x; } forEach _existingRopes; + private _displayName = [_existingCargo] call ASL_Get_Display_Name; + if (_displayName != "") then { + _unit groupChat format[localize "STR_ASL_FREIGHT_GROUND", _displayName]; + }; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; _allCargo set [_ropesIndex, objNull]; _vehicle setVariable ["ASL_Cargo", _allCargo, true]; _this call ASL_Retract_Ropes; }; + ASL_Get_Display_Name = { + params [["_object", objNull]]; + if (isNull _object || !alive _object) exitWith {""}; + private ["_type"]; + if ((typeName _object) == "OBJECT") then { + _type = (typeof _object); + } else { + _type = _object; + }; + private _cfg_type = "CfgVehicles"; + { + if (isClass(configFile >> _x >> _type)) exitWith {_cfg_type = _x}; + } forEach ["CfgMagazines", "CfgWeapons", "CfgGlasses"]; + private _return = getText (configFile >> _cfg_type >> _type >> "displayName"); + _return + }; + ASL_Retract_Ropes_Action_Check = { params [["_vehicle", objNull], ["_unit", objNull]]; if (isNull _vehicle || isNull _unit) exitWith {false}; @@ -1008,6 +1029,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_vehicle", objNull], ["_unit", objNull], ["_cargoCount", 1]]; if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Deploy_Ropes", _vehicle, true] call ASL_RemoteExec}; + if (!alive _vehicle) exitWith {[_vehicle] call ASL_Add_Vehicle_Actions}; private _existingRopes = _vehicle getVariable ["ASL_Ropes", []]; if (count _existingRopes > 0) exitWith { if (_unit == player) then {[[format[localize "STR_ASL_ALREADY"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; @@ -1437,7 +1459,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle) exitWith {}; if !([_vehicle] call ASL_Is_Supported_Vehicle) exitWith {}; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Add_Vehicle_Actions) _vehicle: ", _vehicle, ", mass: ", getMass _vehicle, ", min: ", ASL_MinVehicleMass]; - if (getMass _vehicle < ASL_MinVehicleMass) exitWith { + if (getMass _vehicle < ASL_MinVehicleMass || !alive _vehicle) exitWith { [_vehicle, ["ASL_ActionID_Deploy", "ASL_ActionID_Retract", "ASL_ActionID_Extend", "ASL_ActionID_Shorten", "ASL_ActionID_Release"]] call ASL_Remove_Actions; }; private ["_actionID"]; diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index e74a2b6..7a53e15 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -301,10 +301,6 @@ Show rope changes to players via hints (rope length, etc.). Spieler erhalten per Hinweise Informationen über Seilveränderungen (Seillänge, etc.). - Load attached. Ladung befestigt. @@ -356,6 +352,10 @@ Detach From Ropes Von Seilen Loslösen + + + %1 on ground + %1 auf grund \ No newline at end of file diff --git a/mod.cpp b/mod.cpp index bf26b1d..39d4393 100644 --- a/mod.cpp +++ b/mod.cpp @@ -3,7 +3,7 @@ picture = "logo.paa"; description = "NIC Advanced Sling Loading"; logo = "logo.paa"; logoOver = "logo.paa"; -tooltip = "NIC Advanced Sling Loading v2.1.1d"; +tooltip = "NIC Advanced Sling Loading v2.1.1e"; tooltipOwned = "NIC Advanced Sling Loading Owned"; overview = "NIC Advanced Sling Loading"; author = "[SA] Duda"; From 08f64b6418416b5465a5ed89d353e535ecf3714a Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Sun, 29 May 2022 12:49:25 +0200 Subject: [PATCH 22/24] Fix Message 'cargo on ground' only when ropes are extended to ground --- .../functions/fn_advancedSlingLoadingInit.sqf | 50 +++++++++---------- .../scripts/XEH_preInit.sqf | 16 +++--- .../NIC_AdvancedSlingLoading/stringtable.xml | 24 ++++----- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 6d4687f..fbb4ac7 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -49,7 +49,7 @@ ASL_Advanced_Sling_Loading_Install = { { if (_vehicle isKindOf _x #0) exitWith { _slingLoadPointHeightOffset = _x #1; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Sling_Load_Points) _vehicle ", _vehicle, " isKindOf ", _x #0, ", _slingLoadPointHeightOffsetfset: ", _slingLoadPointHeightOffset]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Get_Sling_Load_Points) _vehicle ", _vehicle, " isKindOf ", _x #0, ", _slingLoadPointHeightOffsetfset: ", _slingLoadPointHeightOffset]; }; } forEach ASL_SLING_LOAD_POINT_CLASS_HEIGHT_OFFSET; private _slingLoadPoints = []; @@ -391,7 +391,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Extend_Ropes_Action = { params [["_vehicle", objNull], ["_unit", objNull], ["_toGround", false]]; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _toGround: ", _toGround]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Extend_Ropes_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _toGround: ", _toGround]; if (isNull _vehicle || isNull _unit) exitWith {}; private _activeRopes = [_vehicle, true] call ASL_Get_Active_Ropes; private _canReleaseCargo = false; @@ -489,7 +489,7 @@ ASL_Advanced_Sling_Loading_Install = { // ", getPos _cargo #2 > 1: ", getPos _cargo #2 > 1 // ]; if (!alive _vehicle || (getPos _cargo #2 > 5 && getPosASL _cargo #2 > 5 && alive _cargo)) exitWith {}; - [_ropesIndex, _vehicle, _unit] call ASL_Release_Cargo_Index_Action; + [_ropesIndex, _vehicle, _unit, true] call ASL_Release_Cargo_Index_Action; }; ASL_Show_Select_Ropes_Menu = { @@ -738,27 +738,27 @@ ASL_Advanced_Sling_Loading_Install = { }; ASL_Release_Cargo_Index_Action = { - params [["_ropesIndex", 0], ["_vehicle", objNull], ["_unit", objNull]]; + params [["_ropesIndex", 0], ["_vehicle", objNull], ["_unit", objNull], ["_chat", false]]; // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo_Index_Action) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; if (isNull _vehicle || isNull _unit) exitWith {}; if (_ropesIndex >= 0 && [_vehicle, _unit] call ASL_Can_Release_Cargo) then { - [_vehicle, _unit, _ropesIndex] call ASL_Release_Cargo; + [_vehicle, _unit, _ropesIndex, _chat] call ASL_Release_Cargo; }; }; ASL_Release_Cargo = { - params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0]]; + params [["_vehicle", objNull], ["_unit", objNull], ["_ropesIndex", 0], ["_chat", false]]; if (isNull _vehicle || isNull _unit) exitWith {false}; if !(local _vehicle) exitWith {[_this, "ASL_Release_Cargo", _vehicle, true] call ASL_RemoteExec}; private _existingRopesAndCargo = [_vehicle, _ropesIndex] call ASL_Get_Ropes_And_Cargo; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _existingRopesAndCargo: ", _existingRopesAndCargo]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Release_Cargo) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _existingRopesAndCargo: ", _existingRopesAndCargo]; private _existingRopes = _existingRopesAndCargo #0; private _existingCargo = _existingRopesAndCargo #1; { _existingCargo ropeDetach _x; } forEach _existingRopes; private _displayName = [_existingCargo] call ASL_Get_Display_Name; - if (_displayName != "") then { + if (_displayName != "" && _chat) then { _unit groupChat format[localize "STR_ASL_FREIGHT_GROUND", _displayName]; }; private _allCargo = _vehicle getVariable ["ASL_Cargo", []]; @@ -833,7 +833,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _vehicle || isNull _unit) exitWith {}; private _activeRopes = [_vehicle] call ASL_Get_Active_Ropes_Without_Cargo; if (count _activeRopes == 1) exitWith { - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) inactive ropes: ", [_vehicle] call ASL_Get_Active_Ropes, ", existing ropes: ", _vehicle getVariable ["ASL_Ropes", []]]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Retract_Ropes_Action) inactive ropes: ", [_vehicle] call ASL_Get_Active_Ropes, ", existing ropes: ", _vehicle getVariable ["ASL_Ropes", []]]; [_vehicle, _unit, (_activeRopes #0) #0] call ASL_Retract_Ropes; if (!ASL_RopeMessagesAuthorized) exitWith {}; hint format[localize "STR_ASL_ROPES_RETRACTED"]; @@ -1117,7 +1117,7 @@ ASL_Advanced_Sling_Loading_Install = { if (isNull _unit) exitWith {}; if (_unit getVariable ["ASL_Unit_Rope_Monitor", false]) exitWith {}; // leave, if unit is already monitoring ror rope ends _unit setVariable ["ASL_Unit_Rope_Monitor", true]; // raise unit rope monitor flag - diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9%10", time, "s (ASL_Rope_Monitor_Unit) _unit: ", _unit, ", started rope end monitoring"]; if (isNil{_unit getVariable "ASL_ActionID_Pickup"}) then { // add pickup action to unit private _actionID = _unit addAction [ format[localize "STR_ASL_PICKUP"], // Title @@ -1180,7 +1180,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull]]; if (isNull _unit) exitWith {}; private _unitRopes = _unit getVariable "ASL_Ropes_Near_Unit"; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; // hintSilent formatText ["%1%2%3%4%5", time, "s (ASL_Pickup_Ropes_Action) unit: ", _unit, ", _unitRopes: ", _unitRopes]; private _closestRope = objNull; @@ -1317,7 +1317,7 @@ ASL_Advanced_Sling_Loading_Install = { private _ropes = [_vehicle, _vehicleWithIndex #1] call ASL_Get_Ropes; if (count _ropes != 4) exitWith {}; private _attachmentPoints = [_cargo] call ASL_Get_Corner_Points; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _attachmentPoints: ", _attachmentPoints, ", _self: ", _self]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _attachmentPoints: ", _attachmentPoints, ", _self: ", _self]; private _ropeLength = (ropeLength (_ropes #0)); private _objDistance = (_cargo distance _vehicle) + 2; if (_objDistance > _ropeLength && !_self) exitWith {[[format[localize "STR_ASL_TOO_SHORT"], false], "ASL_Hint", _unit] call ASL_RemoteExec}; @@ -1332,7 +1332,7 @@ ASL_Advanced_Sling_Loading_Install = { _cargo setVariable ["ASL_CarrierVehicle", nil, true]; }; [_vehicle, _unit, _ropesIndex, _self] call ASL_Drop_Ropes; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Attach_Ropes) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Attach_Ropes) _vehicle: ", _vehicle, ", _unit: ", _unit, ", _ropesIndex: ", _ropesIndex]; if (_self) then { [_vehicle, _unit, _ropesIndex] spawn ASL_Self_Attach; } else { @@ -1377,7 +1377,7 @@ ASL_Advanced_Sling_Loading_Install = { params [["_unit", objNull], ["_self", false]]; if (isNull _unit) exitWith {false}; private _vehicleAndIndex = _unit getVariable ["ASL_Ropes_Vehicle", []]; - diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Drop_Ropes_Action) _unit: ", _unit, ", _self: ", _self, ", _vehicleAndIndex: ", _vehicleAndIndex]; + // diag_log formatText ["%1%2%3%4%5%6%7", time, "s (ASL_Drop_Ropes_Action) _unit: ", _unit, ", _self: ", _self, ", _vehicleAndIndex: ", _vehicleAndIndex]; if (count _vehicleAndIndex == 2) then { [_vehicleAndIndex #0, _unit, _vehicleAndIndex #1, _self] call ASL_Drop_Ropes; }; @@ -1389,7 +1389,7 @@ ASL_Advanced_Sling_Loading_Install = { if !(local _vehicle) exitWith {[_this, "ASL_Drop_Ropes", _vehicle, true] call ASL_RemoteExec}; private _helper = (_unit getVariable ["ASL_Ropes_Pick_Up_Helper", objNull]); if (_self) then {_helper = _unit}; - diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Drop_Ropes) _unit: ", _unit, ", _self: ", _self, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; + // diag_log formatText ["%1%2%3%4%5%6%7%8%9", time, "s (ASL_Drop_Ropes) _unit: ", _unit, ", _self: ", _self, ", _vehicle: ", _vehicle, ", _ropesIndex: ", _ropesIndex]; if (!isNull _helper) then { private _existingRopes = [_vehicle, _ropesIndex] call ASL_Get_Ropes; { @@ -1545,12 +1545,12 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Remove_Actions = { params [["_object", objNull], ["_actions", []]]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; if (isNull _object || count _actions == 0) exitWith {}; private ["_actionID"]; { _actionID = _object getVariable [_x, -1]; - diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) removing _actionID: ", _actionID]; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) removing _actionID: ", _actionID]; if (_actionID > -1) then { _object removeAction _actionID; _object setVariable [_x, nil]; @@ -1636,19 +1636,19 @@ ASL_Advanced_Sling_Loading_Install = { if (isServer) then { if (isNil "ASL_MaxRopeLength") then {ASL_MaxRopeLength = 100}; // maximum rope length in meter (As of Arma v2.04, this limit is hardcoded. No ropes longer than 100 m can be created or unwound) if (isNil "ASL_MinRopeLength") then {ASL_MinRopeLength = 2}; // minimum rope length in meter - if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) - if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes - if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes + if (isNil "ASL_MaxDeployRetractDistance") then {ASL_MaxDeployRetractDistance = 10}; // maximum rope deploy, retract distance in meter (when player is on foot) + if (isNil "ASL_PilotsAuthorized") then {ASL_PilotsAuthorized = true}; // pilots authorized to manipulate ropes + if (isNil "ASL_CopilotsAuthorized") then {ASL_CopilotsAuthorized = true}; // copilots authorized to manipulate ropes if (isNil "ASL_GunnersAuthorized") then {ASL_GunnersAuthorized = false}; // gunners authorized to manipulate ropes - if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes + if (isNil "ASL_PassengersAuthorized") then {ASL_PassengersAuthorized = false}; // passengers authorized to manipulate ropes if (isNil "ASL_MaxRopeDeployHeight") then {ASL_MaxRopeDeployHeight = 100}; // maximum height in meter the action 'Deploy Cargo Ropes' is available - if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes - if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // maximum distance in meter a unit has to be from a rope end to be able to pick up the rope + if (isNil "ASL_MinVehicleMass") then {ASL_MinVehicleMass = 0}; // minimum mass a vehicle has to have to be able to deploy ropes + if (isNil "ASL_RopeHandlingDistance") then {ASL_RopeHandlingDistance = 5}; // maximum distance in meter a unit has to be from a rope end to be able to pick up the rope if (isNil "ASL_InitialDeployRopeLength") then {ASL_InitialDeployRopeLength = 15}; // initial rope length in meter, when rope is deployed if (isNil "ASL_ExtendShortenRopeLength") then {ASL_ExtendShortenRopeLength = 5}; // rope length in meter, when rope is extended / shortened if (isNil "ASL_DefaultLiftableMass") then {ASL_DefaultLiftableMass = 4000}; // default mass in kg, which can be lifted - if (isNil "ASL_MinRopeLengthDropCargo") then {ASL_MinRopeLengthDropCargo = false}; // drop cargo, when minimum rope length is reached, and ropes are shortened once more - if (isNil "ASL_RopeMessagesAuthorized") then {ASL_RopeMessagesAuthorized = true}; // hint players informations about rope changes + if (isNil "ASL_MinRopeLengthDropCargo") then {ASL_MinRopeLengthDropCargo = false}; // drop cargo, when minimum rope length is reached, and ropes are shortened once more + if (isNil "ASL_RopeMessagesAuthorized") then {ASL_RopeMessagesAuthorized = true}; // hint players informations about rope changes if (isNil "ASL_RopeUnwindSpeed") then {ASL_RopeUnwindSpeed = 3}; // ropes unwinding speed if (isNil "ASL_HeavyLiftAuthorized") then {ASL_HeavyLiftAuthorized = true}; // heavy lifting allowed if (isNil "ASL_MaxLiftableMassFactor") then {ASL_MaxLiftableMassFactor = 8}; // maximum liftable mass factor (ASL_Rope_Get_Lift_Capability * ASL_MaxLiftableMassFactor) diff --git a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf index 9a668f0..62621c1 100644 --- a/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/scripts/XEH_preInit.sqf @@ -151,11 +151,11 @@ true, {ASL_MaxLiftableMassFactor = round(ASL_MaxLiftableMassFactor)} ] call CBA_fnc_addSetting; -[ - "ASL_SelfAttachAuthorized", - "CHECKBOX", - [format[localize "STR_ASL_SELF_ATTACH"], format[localize "STR_ASL_SELF_ATTACH_TIP"]], - format[localize "STR_ASL_TITLE"], - true, - true -] call CBA_fnc_addSetting; \ No newline at end of file +// [ + // "ASL_SelfAttachAuthorized", + // "CHECKBOX", + // [format[localize "STR_ASL_SELF_ATTACH"], format[localize "STR_ASL_SELF_ATTACH_TIP"]], + // format[localize "STR_ASL_TITLE"], + // true, + // true +// ] call CBA_fnc_addSetting; \ No newline at end of file diff --git a/addons/NIC_AdvancedSlingLoading/stringtable.xml b/addons/NIC_AdvancedSlingLoading/stringtable.xml index 7a53e15..c098d09 100644 --- a/addons/NIC_AdvancedSlingLoading/stringtable.xml +++ b/addons/NIC_AdvancedSlingLoading/stringtable.xml @@ -133,10 +133,10 @@ Attach To Cargo Ropes An Frachtseile Befestigen - - Self Attach To Cargo Ropes - Sich Selbst An Frachtseile Befestigen - + + + + Cannot deploy cargo ropes from locked vehicle Frachtseile können nicht von verschlossenen Fahrzeugen aus ausgefahren werden @@ -337,14 +337,14 @@ Heavy Lifting Max Mass Factor Schwerlast Maximalschlinglastmassenfaktor - - Maximum liftable mass factor a vehicle can lift (e.g. CH-47 has a default of 12t max mass. A factor of 5 would result: 5 * 12 = 60t max liftable mass. Only valid with 'Heavy Lifting Max Mass Factor' allowed). - Faktor, der die Maximalschlinglastmasse bestimmt (z.b. hat der CH-47 eine Standardmaximalschlinglast von 12t. Ein Faktor von 5 heißt: 5 * 12 = 60t Maximalschlinglast. Nur gültig wenn 'Schwerlast Maximalschlinglastmassenfaktor' erlaubt). - - - Allow Self Attach - Erlaube Selbstbefestigung - + + + + + + + + Allow self attachment to cargo ropes. Selbstbefestigung an Lastseile erlauben. From 88fb02ed61c5db46cd3984c3854e1c04b34c994c Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Sat, 4 Jun 2022 17:18:16 +0200 Subject: [PATCH 23/24] Changed ASL_SLING_RULES - changed sling load rules - minor code cleaning --- .../functions/fn_advancedSlingLoadingInit.sqf | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index fbb4ac7..802368f 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -1404,7 +1404,7 @@ ASL_Advanced_Sling_Loading_Install = { [_unit, ["ASL_ActionID_Attach", "ASL_ActionID_Drop", "ASL_ActionID_Detach"]] call ASL_Remove_Actions; // remove 'attach ropes', 'drop ropes' and 'detach ropes' actions, once unit has dropped ropes _unit setVariable ["ASL_Ropes_Pick_Up_Helper", nil, true]; }; - + ASL_SUPPORTED_VEHICLES = [ "Helicopter", "VTOL_Base_F" @@ -1417,11 +1417,19 @@ ASL_Advanced_Sling_Loading_Install = { { if (_vehicle isKindOf _x) exitWith {_isSupported = true}; } forEach (missionNamespace getVariable ["ASL_SUPPORTED_VEHICLES_OVERRIDE", ASL_SUPPORTED_VEHICLES]); - _isSupported; + _isSupported }; + // ASL_SLING_RULES = [ + // ["All", "CAN_SLING", "All"] + // ]; + ASL_SLING_RULES = [ - ["All", "CAN_SLING", "All"] + ["Air", "CAN_SLING", "Car"], + ["Air", "CAN_SLING", "Tank"], + ["Air", "CAN_SLING", "Air"], + ["Air", "CAN_SLING", "Boat_F"], + ["Air", "CAN_SLING", "ReammoBox_F"] ]; ASL_Is_Supported_Cargo = { @@ -1437,23 +1445,20 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Hint = { params ["_msg", ["_isSuccess", true]]; - if (!isNil "ExileClient_gui_notification_event_addNotification") then { - if (_isSuccess) then { - [format[localize "STR_ASL_SUCCESS"], [_msg]] call ExileClient_gui_notification_event_addNotification; - } else { - [format[localize "STR_ASL_WHOOPS"], [_msg]] call ExileClient_gui_notification_event_addNotification; - }; + if (isNil "ExileClient_gui_notification_event_addNotification") exitWith {hint _msg}; + if (_isSuccess) then { + [format[localize "STR_ASL_SUCCESS"], [_msg]] call ExileClient_gui_notification_event_addNotification; } else { - hint _msg; + [format[localize "STR_ASL_WHOOPS"], [_msg]] call ExileClient_gui_notification_event_addNotification; }; }; - + ASL_Switch_Vehicles_Actions = { { [_x] call ASL_Add_Vehicle_Actions; } foreach vehicles; }; - + ASL_Add_Vehicle_Actions = { params [["_vehicle", objNull]]; if (isNull _vehicle) exitWith {}; @@ -1542,7 +1547,7 @@ ASL_Advanced_Sling_Loading_Install = { _vehicle setVariable ["ASL_ActionID_Release", _actionID]; }; }; - + ASL_Remove_Actions = { params [["_object", objNull], ["_actions", []]]; // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Remove_Actions) _object: ", _object, " _actions: ", _actions]; @@ -1564,28 +1569,20 @@ ASL_Advanced_Sling_Loading_Install = { ASL_RemoteExec = { params ["_params", "_functionName", "_target", ["_isCall", false]]; - if (!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecClient", [_params, _functionName, _target, _isCall]] call ExileClient_system_network_send; - } else { - if (_isCall) then { - _params remoteExecCall [_functionName, _target]; - } else { - _params remoteExec [_functionName, _target]; - }; + if (isNil "ExileClient_system_network_send") exitWith { + if (_isCall) exitWith {_params remoteExecCall [_functionName, _target]}; + _params remoteExec [_functionName, _target]; }; + ["AdvancedSlingLoadingRemoteExecClient", [_params, _functionName, _target, _isCall]] call ExileClient_system_network_send; }; ASL_RemoteExecServer = { params ["_params", "_functionName", ["_isCall", false]]; - if (!isNil "ExileClient_system_network_send") then { - ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; - } else { - if (_isCall) then { - _params remoteExecCall [_functionName, 2]; - } else { - _params remoteExec [_functionName, 2]; - }; + if (isNil "ExileClient_system_network_send") exitWith { + if (_isCall) exitWith {_params remoteExecCall [_functionName, 2]}; + _params remoteExec [_functionName, 2]; }; + ["AdvancedSlingLoadingRemoteExecServer", [_params, _functionName, _isCall]] call ExileClient_system_network_send; }; if (isServer) then { From ce338793a90f291c67624f6af33fec6ce5e3d822 Mon Sep 17 00:00:00 2001 From: nicoman35 Date: Sat, 11 Jun 2022 10:45:24 +0200 Subject: [PATCH 24/24] Changed rope manipulation distance Added model size dependency to rope manipulation distance --- .../functions/fn_advancedSlingLoadingInit.sqf | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf index 802368f..6e8a051 100644 --- a/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf +++ b/addons/NIC_AdvancedSlingLoading/functions/fn_advancedSlingLoadingInit.sqf @@ -806,7 +806,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Retract_Ropes = { params [["_vehicle", objNull], ["_unit", objNull], ["_distanceCheck", false]]; if (isNull _vehicle || isNull _unit) exitWith {}; - if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { + if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance + (sizeOf typeOf _cargo / 10 max 1)) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Retract_Ropes) EXIT 1"]; false }; @@ -942,7 +942,7 @@ ASL_Advanced_Sling_Loading_Install = { ASL_Can_Deploy_Ropes = { params [["_vehicle", objNull], ["_unit", objNull], ["_distanceCheck", false]]; if (isNull _vehicle || isNull _unit) exitWith {false}; - if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance) exitWith { + if (_distanceCheck && _unit distance _vehicle > ASL_MaxDeployRetractDistance + (sizeOf typeOf _cargo / 10 max 1)) exitWith { // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Can_Deploy_Ropes) EXIT 1"]; false }; @@ -1276,10 +1276,15 @@ ASL_Advanced_Sling_Loading_Install = { private _cargo = cursorTarget; if (_self && ASL_SelfAttachAuthorized) then {_cargo = _unit}; private _vehicle = (_unit getVariable ["ASL_Ropes_Vehicle", [objNull, 0]]) #0; - private _ropeHandlingDistance = ASL_RopeHandlingDistance; - if (_unit != player) then {_ropeHandlingDistance = _ropeHandlingDistance + 5}; // AIs get higher range, as AIs sometimes can't get close enough to vehicles - if (vehicle _unit != _unit || _unit distance _cargo > _ropeHandlingDistance || _vehicle == _cargo || !alive _cargo) exitWith {false}; + // private _ropeAttachDistance = ASL_RopeHandlingDistance; + // private _ropeAttachDistance = ASL_RopeHandlingDistance + (sizeOf typeOf _cargo / 10 max 2); + private _ropeAttachDistance = ASL_MaxDeployRetractDistance + (sizeOf typeOf _cargo / 10 max 1); + if (_unit != player) then {_ropeAttachDistance = _ropeAttachDistance + 5}; // AIs get higher range, as AIs sometimes can't get close enough to vehicles + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes_Action_Check) check 1"]; + if (vehicle _unit != _unit || _unit distance _cargo > _ropeAttachDistance || _vehicle == _cargo || !alive _cargo) exitWith {false}; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes_Action_Check) check 2"]; if (_vehicle == _cargo getVariable ["ASL_CarrierVehicle", objNull]) exitWith {false}; // let's not attach another rope from same vehicle to same cargo + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes_Action_Check) check 2"]; if (_self && ASL_SelfAttachAuthorized) exitWith {true}; [_vehicle, _cargo] call ASL_Is_Supported_Cargo }; @@ -1302,6 +1307,7 @@ ASL_Advanced_Sling_Loading_Install = { }; }; }; + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Attach_Ropes) _unit: ", _unit, ", _self: ", _self]; if (_canBeAttached) then { [_cargo, _unit, _self] call ASL_Attach_Ropes; }; @@ -1439,7 +1445,8 @@ ASL_Advanced_Sling_Loading_Install = { private _canSling = false; { if (_vehicle isKindOf (_x #0) && _cargo isKindOf (_x #2) && (toUpper (_x #1)) == "CAN_SLING") exitWith {_canSling = true}; - } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); + } forEach (missionNamespace getVariable ["ASL_SLING_RULES_OVERRIDE", ASL_SLING_RULES]); + // diag_log formatText ["%1%2%3%4%5", time, "s (ASL_Is_Supported_Cargo) _canSling: ", _canSling]; _canSling };