├── .gitattributes ├── .gitignore ├── README.md ├── addons └── SA_AdvancedTowing │ ├── $PBOPREFIX$ │ ├── config.cpp │ └── functions │ └── fn_advancedTowingInit.sqf ├── keys └── AdvancedTowing.bikey ├── logo.paa ├── logo.png ├── logo.psd ├── mod.cpp ├── steamLogo.jpg └── steamLogo.psd /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | 19 | *.sqf eol=crlf 20 | *.sqm eol=crlf 21 | *.ext eol=crlf 22 | *.hpp eol=crlf 23 | *.cpp eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | *.pbo 49 | addons/SA_AdvancedTowing.pbo.AdvancedTowing.bisign 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Advanced Towing 2 | 3 | Adds support for towing vehicles using ropes. Works in both SP and MP. Supports Exile. 4 | 5 | Also check out my Advanced Sling Loading addon for more rope features! 6 | 7 | **Features:** 8 | 9 | - Tow other vehicles behind Ships, Cars, Trucks and Tanks 10 | - The size of the vehicle impacts it's towing capability 11 | - Other players (including AI) can tow other players 12 | - Supports towing damaged / destroyed vehicles 13 | - Supports towing "trains" of vehicles (limited to 2 by default - see below) 14 | 15 | **Installation:** 16 | 17 | 1. Subscrive via steam: http://steamcommunity.com/sharedfiles/filedetails/?id=639837898 or dowload latest release from https://github.com/sethduda/AdvancedTowing/releases 18 | 2. If installing this on a server, add the addon to the -serverMod command line option 19 | 3. Optionally, this can be installed directly in the mission PBO by calling the advanced towing script via initServer.sqf. You'll find the sqf script (fn_advancedTowingInit.sqf) in the addons directory inside the downloaded addon. 20 | 21 | **Default Towing Rules:** 22 | 23 | - Tanks can tow tanks, cars, ships and air 24 | - Cars can tow cars, ships and air 25 | - Trucks can tow cars, ships and air 26 | - Ships can only tow ships 27 | - You can't tow locked vehicles (see settings below) 28 | - You can only tow up to two vehicles at a time (see settings below) 29 | 30 | **Notes for Mission Makers:** 31 | 32 | You can enable "trains" of vehicles by defining the SA_MAX_TOWED_CARGO varible in your init.sqf file. By default, this is set to 2. When set, vehicles can tow up to the max number of specified vehicles. If you try to tow more, your vehicle won't be able to move. Note, however, mass of all vehicles will be taken into account. It's going to be slower to two vehicles vs one. 33 | 34 | ```SA_MAX_TOWED_CARGO = 3; ``` 35 | 36 | You can customize which classes of objects can "deploy" tow ropes by overriding the SA_TOW_SUPPORTED_VEHICLES_OVERRIDE variable in an init.sqf file. 37 | 38 | ```SA_TOW_SUPPORTED_VEHICLES_OVERRIDE = [ "Air", "Ship" ]; ``` 39 | 40 | This will only allow objects of class Air and Ship deploy tow ropes. 41 | 42 | You can customize what can and can't be towed by defining the SA_TOW_RULES_OVERRIDE variable in the init.sqf file. 43 | 44 | ```SA_TOW_RULES_OVERRIDE = 45 | [ ["Air", "CAN_TOW", "Ship"], 46 | ["Air", "CAN_TOW", "Air"], 47 | ["Ship", "CANT_TOW", "Air"], 48 | ["Ship", "CAN_TOW", "Ship"] 49 | ]; ``` 50 | 51 | In this example, all objects of class Air can tow Ships and Air. However, Ships can only tow ships. 52 | 53 | You can allow towing of locked vehicles by defining SA_TOW_LOCKED_VEHICLES_ENABLED in your init.sqf file. It defaults to false. 54 | 55 | ```SA_TOW_LOCKED_VEHICLES_ENABLED = true; ``` 56 | 57 | You can allow towing in an Exile safe zone by defining SA_TOW_IN_EXILE_SAFEZONE_ENABLED in your init.sqf file. It default to false. 58 | 59 | ```SA_TOW_IN_EXILE_SAFEZONE_ENABLED = true; ``` 60 | 61 | **Not working on your server?** 62 | 63 | Make sure you have the mod listed in the -mod or -serverMod command line option. Only -serverMod is required for this addon. If still not working, check your server log to make sure the addon is found. 64 | 65 | **FAQ** 66 | 67 | *This addon is only required on the server - is it going to slow down my server?* 68 | 69 | No - while this addon is server-side only, it installs itself on all clients without them downloading the addon. Most of the time, the towing code actually runs client-side, even though you installed the addon only on the server. Magic! 70 | 71 | *Why is the vehicle I'm towing jumpy/laggy?* 72 | 73 | If you're towing a vehicle that another player is driving, it's slower to transmit position updates for the towed vehicle. This will result in laggy looking towing. Have the player move to the passenger seat and then re-attach the tow ropes. 74 | 75 | Also, when using this in MP, all other players watching someone tow something will also notice the towed vehicle isn't moving as smoothly. This is also due to network delay. Usually this isn't too noticeable unless moving very fast. 76 | 77 | *Battleye kicks me when I try to do xyz. What do I do?* 78 | 79 | You need to configure Battleye rules on your server. Below are the files you need to configure: 80 | 81 | setvariable.txt 82 | 83 | Add the following exclusions to the end of all lines starting with 4, 5, 6, or 7 if they contain "" (meaning applies to all values): 84 | 85 | !="SA_Cargo" !="SA_Tow_Ropes" !="SA_Tow_Ropes_Vehicle" !="SA_Tow_Ropes_Pick_Up_Helper" 86 | 87 | setvariableval.txt 88 | 89 | If you have any lines starting with 4, 5, 6, or 7 and they contain "" (meaning applies to all values) it's not going to work. Either remove the line or explicitly define the values you want to kick. Since the values of the variables above can vary, I don't know of a good way to define an exclusion rule. 90 | 91 | Also, it's possible there are other battleye filter files that can cause issues. If you check your battleye logs you can figure out which file is causing a problem. 92 | 93 | *The tow actions appear when looking at a vehicle, but do nothing when I select them. How do I fix that?* 94 | 95 | Most likely your server is setup with a white list for remote executions. In order to fix this, you need to modify your mission's description.ext file, adding the following CfgRemoteExec rules. If using InfiStar you should edit your cfgremoteexec.hpp instead of the description.ext file. See https://community.bistudio.com/wiki/Arma_3_Remote_Execution for more details on CfgRemoteExec. 96 | 97 | ``` 98 | class CfgRemoteExec 99 | { 100 | class Functions 101 | { 102 | class SA_Simulate_Towing { allowedTargets=0; }; 103 | class SA_Attach_Tow_Ropes { allowedTargets=0; }; 104 | class SA_Take_Tow_Ropes { allowedTargets=0; }; 105 | class SA_Put_Away_Tow_Ropes { allowedTargets=0; }; 106 | class SA_Pickup_Tow_Ropes { allowedTargets=0; }; 107 | class SA_Drop_Tow_Ropes { allowedTargets=0; }; 108 | class SA_Set_Owner { allowedTargets=2; }; 109 | class SA_Hint { allowedTargets=1; }; 110 | class SA_Hide_Object_Global { allowedTargets=2; }; 111 | }; 112 | }; 113 | ``` 114 | 115 | **Issues & Feature Requests** 116 | 117 | https://github.com/sethduda/AdvancedTowing/issues 118 | 119 | If anyone wants to help fix any of these, please let me know. You can fork the repo and create a pull request. 120 | 121 | **Special Thanks for Testing & Support:** 122 | 123 | - Stay Alive Tactical Team (http://sa.clanservers.com) 124 | - BI forum community: diesel tech jc, TeTeT, belbo 125 | - Crimson Gaming for testing on exile (http://crimsongamingau.com) 126 | - DirtySanchez & XLD (exilemod.com) for his great ideas & work to make this functional with Exile 127 | 128 | 129 | --- 130 | 131 | The MIT License (MIT) 132 | 133 | Copyright (c) 2016 Seth Duda 134 | 135 | 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: 136 | 137 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 138 | 139 | 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. 140 | -------------------------------------------------------------------------------- /addons/SA_AdvancedTowing/$PBOPREFIX$: -------------------------------------------------------------------------------- 1 | SA_AdvancedTowing -------------------------------------------------------------------------------- /addons/SA_AdvancedTowing/config.cpp: -------------------------------------------------------------------------------- 1 | class CfgPatches 2 | { 3 | class SA_AdvancedTowing 4 | { 5 | units[] = {"SA_AdvancedTowing"}; 6 | requiredVersion = 1.0; 7 | requiredAddons[] = {"A3_Modules_F"}; 8 | }; 9 | }; 10 | 11 | class CfgNetworkMessages 12 | { 13 | 14 | class AdvancedTowingRemoteExecClient 15 | { 16 | module = "AdvancedTowing"; 17 | parameters[] = {"ARRAY","STRING","OBJECT","BOOL"}; 18 | }; 19 | 20 | class AdvancedTowingRemoteExecServer 21 | { 22 | module = "AdvancedTowing"; 23 | parameters[] = {"ARRAY","STRING","BOOL"}; 24 | }; 25 | 26 | }; 27 | 28 | class CfgFunctions 29 | { 30 | class SA 31 | { 32 | class AdvancedTowing 33 | { 34 | file = "\SA_AdvancedTowing\functions"; 35 | class advancedTowingInit{postInit=1}; 36 | }; 37 | }; 38 | }; -------------------------------------------------------------------------------- /addons/SA_AdvancedTowing/functions/fn_advancedTowingInit.sqf: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2016 Seth Duda 5 | 6 | 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: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | 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. 11 | */ 12 | 13 | #define SA_Find_Surface_ASL_Under_Position(_object,_positionAGL,_returnSurfaceASL,_canFloat) \ 14 | _objectASL = AGLToASL (_object modelToWorldVisual (getCenterOfMass _object)); \ 15 | _surfaceIntersectStartASL = [_positionAGL select 0, _positionAGL select 1, (_objectASL select 2) + 1]; \ 16 | _surfaceIntersectEndASL = [_positionAGL select 0, _positionAGL select 1, (_objectASL select 2) - 5]; \ 17 | _surfaces = lineIntersectsSurfaces [_surfaceIntersectStartASL, _surfaceIntersectEndASL, _object, objNull, true, 5]; \ 18 | _returnSurfaceASL = AGLToASL _positionAGL; \ 19 | { \ 20 | scopeName "surfaceLoop"; \ 21 | if( isNull (_x select 2) ) then { \ 22 | _returnSurfaceASL = _x select 0; \ 23 | breakOut "surfaceLoop"; \ 24 | } else { \ 25 | if!((_x select 2) isKindOf "RopeSegment") then { \ 26 | _objectFileName = str (_x select 2); \ 27 | if((_objectFileName find " t_") == -1 && (_objectFileName find " b_") == -1) then { \ 28 | _returnSurfaceASL = _x select 0; \ 29 | breakOut "surfaceLoop"; \ 30 | }; \ 31 | }; \ 32 | }; \ 33 | } forEach _surfaces; \ 34 | if(_canFloat && (_returnSurfaceASL select 2) < 0) then { \ 35 | _returnSurfaceASL set [2,0]; \ 36 | }; \ 37 | 38 | #define SA_Find_Surface_ASL_Under_Model(_object,_modelOffset,_returnSurfaceASL,_canFloat) \ 39 | SA_Find_Surface_ASL_Under_Position(_object, (_object modelToWorldVisual _modelOffset), _returnSurfaceASL,_canFloat); 40 | 41 | #define SA_Find_Surface_AGL_Under_Model(_object,_modelOffset,_returnSurfaceAGL,_canFloat) \ 42 | SA_Find_Surface_ASL_Under_Model(_object,_modelOffset,_returnSurfaceAGL,_canFloat); \ 43 | _returnSurfaceAGL = ASLtoAGL _returnSurfaceAGL; 44 | 45 | #define SA_Get_Cargo(_vehicle,_cargo) \ 46 | if( count (ropeAttachedObjects _vehicle) == 0 ) then { \ 47 | _cargo = objNull; \ 48 | } else { \ 49 | _cargo = ((ropeAttachedObjects _vehicle) select 0) getVariable ["SA_Cargo",objNull]; \ 50 | }; 51 | 52 | SA_Advanced_Towing_Install = { 53 | 54 | // Prevent advanced towing from installing twice 55 | if(!isNil "SA_TOW_INIT") exitWith {}; 56 | SA_TOW_INIT = true; 57 | 58 | diag_log "Advanced Towing Loading..."; 59 | 60 | SA_Simulate_Towing_Speed = { 61 | 62 | params ["_vehicle"]; 63 | 64 | private ["_runSimulation","_currentCargo","_maxVehicleSpeed","_maxTowedVehicles","_vehicleMass"]; 65 | 66 | _maxVehicleSpeed = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "maxSpeed"); 67 | _vehicleMass = 1000 max (getMass _vehicle); 68 | _maxTowedCargo = missionNamespace getVariable ["SA_MAX_TOWED_CARGO",2]; 69 | _runSimulation = true; 70 | 71 | private ["_currentVehicle","_totalCargoMass","_totalCargoCount","_findNextCargo","_towRopes","_ropeLength"]; 72 | private ["_ends","_endsDistance","_currentMaxSpeed","_newMaxSpeed"]; 73 | 74 | while {_runSimulation} do { 75 | 76 | // Calculate total mass and count of cargo being towed (only takes into account 77 | // cargo that's actively being towed (e.g. there's no slack in the rope) 78 | 79 | _currentVehicle = _vehicle; 80 | _totalCargoMass = 0; 81 | _totalCargoCount = 0; 82 | _findNextCargo = true; 83 | while {_findNextCargo} do { 84 | _findNextCargo = false; 85 | SA_Get_Cargo(_currentVehicle,_currentCargo); 86 | if(!isNull _currentCargo) then { 87 | _towRopes = _currentVehicle getVariable ["SA_Tow_Ropes",[]]; 88 | if(count _towRopes > 0) then { 89 | _ropeLength = ropeLength (_towRopes select 0); 90 | _ends = ropeEndPosition (_towRopes select 0); 91 | _endsDistance = (_ends select 0) distance (_ends select 1); 92 | if( _endsDistance >= _ropeLength - 2 ) then { 93 | _totalCargoMass = _totalCargoMass + (1000 max (getMass _currentCargo)); 94 | _totalCargoCount = _totalCargoCount + 1; 95 | _currentVehicle = _currentCargo; 96 | _findNextCargo = true; 97 | }; 98 | }; 99 | }; 100 | }; 101 | 102 | _newMaxSpeed = _maxVehicleSpeed / (1 max ((_totalCargoMass / _vehicleMass) * 2)); 103 | _newMaxSpeed = (_maxVehicleSpeed * 0.75) min _newMaxSpeed; 104 | 105 | // Prevent vehicle from moving if trying to move more cargo than pre-defined max 106 | if(_totalCargoCount > _maxTowedCargo) then { 107 | _newMaxSpeed = 0; 108 | }; 109 | 110 | _currentMaxSpeed = _vehicle getVariable ["SA_Max_Tow_Speed",_maxVehicleSpeed]; 111 | 112 | if(_currentMaxSpeed != _newMaxSpeed) then { 113 | _vehicle setVariable ["SA_Max_Tow_Speed",_newMaxSpeed]; 114 | }; 115 | 116 | sleep 0.1; 117 | 118 | }; 119 | }; 120 | 121 | SA_Simulate_Towing = { 122 | 123 | params ["_vehicle","_vehicleHitchModelPos","_cargo","_cargoHitchModelPos","_ropeLength"]; 124 | 125 | private ["_lastCargoHitchPosition","_lastCargoVectorDir","_cargoLength","_maxDistanceToCargo","_lastMovedCargoPosition","_cargoHitchPoints"]; 126 | private ["_vehicleHitchPosition","_cargoHitchPosition","_newCargoHitchPosition","_cargoVector","_movedCargoVector","_attachedObjects","_currentCargo"]; 127 | private ["_newCargoDir","_lastCargoVectorDir","_newCargoPosition","_doExit","_cargoPosition","_vehiclePosition","_maxVehicleSpeed","_vehicleMass","_cargoMass","_cargoCanFloat"]; 128 | private ["_cargoCorner1AGL","_cargoCorner1ASL","_cargoCorner2AGL","_cargoCorner2ASL","_cargoCorner3AGL","_cargoCorner3ASL","_cargoCorner4AGL","_cargoCorner4ASL","_surfaceNormal1","_surfaceNormal2","_surfaceNormal"]; 129 | private ["_cargoCenterASL","_surfaceHeight","_surfaceHeight2","_maxSurfaceHeight"]; 130 | 131 | _maxVehicleSpeed = getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "maxSpeed"); 132 | _cargoCanFloat = if( getNumber (configFile >> "CfgVehicles" >> typeOf _cargo >> "canFloat") == 1 ) then { true } else { false }; 133 | 134 | private ["_cargoCenterOfMassAGL","_cargoModelCenterGroundPosition"]; 135 | SA_Find_Surface_AGL_Under_Model(_cargo,getCenterOfMass _cargo,_cargoCenterOfMassAGL,_cargoCanFloat); 136 | _cargoModelCenterGroundPosition = _cargo worldToModelVisual _cargoCenterOfMassAGL; 137 | _cargoModelCenterGroundPosition set [0,0]; 138 | _cargoModelCenterGroundPosition set [1,0]; 139 | _cargoModelCenterGroundPosition set [2, (_cargoModelCenterGroundPosition select 2) - 0.05]; // Adjust height so that it doesn't ride directly on ground 140 | 141 | // Calculate cargo model corner points 142 | private ["_cargoCornerPoints"]; 143 | _cargoCornerPoints = [_cargo] call SA_Get_Corner_Points; 144 | _corner1 = _cargoCornerPoints select 0; 145 | _corner2 = _cargoCornerPoints select 1; 146 | _corner3 = _cargoCornerPoints select 2; 147 | _corner4 = _cargoCornerPoints select 3; 148 | 149 | 150 | // Try to set cargo owner if the towing client doesn't own the cargo 151 | if(local _vehicle && !local _cargo) then { 152 | [[_cargo, clientOwner],"SA_Set_Owner"] call SA_RemoteExecServer; 153 | }; 154 | 155 | _vehicleHitchModelPos set [2,0]; 156 | _cargoHitchModelPos set [2,0]; 157 | 158 | _lastCargoHitchPosition = _cargo modelToWorld _cargoHitchModelPos; 159 | _lastCargoVectorDir = vectorDir _cargo; 160 | _lastMovedCargoPosition = getPos _cargo; 161 | 162 | _cargoHitchPoints = [_cargo] call SA_Get_Hitch_Points; 163 | _cargoLength = (_cargoHitchPoints select 0) distance (_cargoHitchPoints select 1); 164 | 165 | _vehicleMass = 1 max (getMass _vehicle); 166 | _cargoMass = getMass _cargo; 167 | if(_cargoMass == 0) then { 168 | _cargoMass = _vehicleMass; 169 | }; 170 | 171 | _maxDistanceToCargo = _ropeLength; 172 | 173 | _doExit = false; 174 | 175 | // Start vehicle speed simulation 176 | [_vehicle] spawn SA_Simulate_Towing_Speed; 177 | 178 | while {!_doExit} do { 179 | 180 | _vehicleHitchPosition = _vehicle modelToWorld _vehicleHitchModelPos; 181 | _vehicleHitchPosition set [2,0]; 182 | _cargoHitchPosition = _lastCargoHitchPosition; 183 | _cargoHitchPosition set [2,0]; 184 | 185 | _cargoPosition = getPos _cargo; 186 | _vehiclePosition = getPos _vehicle; 187 | 188 | if(_vehicleHitchPosition distance _cargoHitchPosition > _maxDistanceToCargo) then { 189 | 190 | // Calculated simulated towing position + direction 191 | _newCargoHitchPosition = _vehicleHitchPosition vectorAdd ((_vehicleHitchPosition vectorFromTo _cargoHitchPosition) vectorMultiply _ropeLength); 192 | _cargoVector = _lastCargoVectorDir vectorMultiply _cargoLength; 193 | _movedCargoVector = _newCargoHitchPosition vectorDiff _lastCargoHitchPosition; 194 | _newCargoDir = vectorNormalized (_cargoVector vectorAdd _movedCargoVector); 195 | //if(_isRearCargoHitch) then { 196 | // _newCargoDir = _newCargoDir vectorMultiply -1; 197 | //}; 198 | _lastCargoVectorDir = _newCargoDir; 199 | _newCargoPosition = _newCargoHitchPosition vectorAdd (_newCargoDir vectorMultiply -(vectorMagnitude (_cargoHitchModelPos))); 200 | 201 | SA_Find_Surface_ASL_Under_Position(_cargo,_newCargoPosition,_newCargoPosition,_cargoCanFloat); 202 | 203 | // Calculate surface normal (up) (more realistic than surfaceNormal function) 204 | SA_Find_Surface_ASL_Under_Model(_cargo,_corner1,_cargoCorner1ASL,_cargoCanFloat); 205 | SA_Find_Surface_ASL_Under_Model(_cargo,_corner2,_cargoCorner2ASL,_cargoCanFloat); 206 | SA_Find_Surface_ASL_Under_Model(_cargo,_corner3,_cargoCorner3ASL,_cargoCanFloat); 207 | SA_Find_Surface_ASL_Under_Model(_cargo,_corner4,_cargoCorner4ASL,_cargoCanFloat); 208 | _surfaceNormal1 = (_cargoCorner1ASL vectorFromTo _cargoCorner3ASL) vectorCrossProduct (_cargoCorner1ASL vectorFromTo _cargoCorner2ASL); 209 | _surfaceNormal2 = (_cargoCorner4ASL vectorFromTo _cargoCorner2ASL) vectorCrossProduct (_cargoCorner4ASL vectorFromTo _cargoCorner3ASL); 210 | _surfaceNormal = _surfaceNormal1 vectorAdd _surfaceNormal2; 211 | 212 | if(missionNamespace getVariable ["SA_TOW_DEBUG_ENABLED", false]) then { 213 | if(isNil "sa_tow_debug_arrow_1") then { 214 | sa_tow_debug_arrow_1 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 215 | sa_tow_debug_arrow_2 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 216 | sa_tow_debug_arrow_3 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 217 | sa_tow_debug_arrow_4 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 218 | }; 219 | sa_tow_debug_arrow_1 setPosASL _cargoCorner1ASL; 220 | sa_tow_debug_arrow_1 setVectorUp _surfaceNormal; 221 | sa_tow_debug_arrow_2 setPosASL _cargoCorner2ASL; 222 | sa_tow_debug_arrow_2 setVectorUp _surfaceNormal; 223 | sa_tow_debug_arrow_3 setPosASL _cargoCorner3ASL; 224 | sa_tow_debug_arrow_3 setVectorUp _surfaceNormal; 225 | sa_tow_debug_arrow_4 setPosASL _cargoCorner4ASL; 226 | sa_tow_debug_arrow_4 setVectorUp _surfaceNormal; 227 | }; 228 | 229 | // Calculate adjusted surface height based on surface normal (prevents vehicle from clipping into ground) 230 | _cargoCenterASL = AGLtoASL (_cargo modelToWorldVisual [0,0,0]); 231 | _cargoCenterASL set [2,0]; 232 | _surfaceHeight = ((_cargoCorner1ASL vectorAdd ( _cargoCenterASL vectorMultiply -1)) vectorDotProduct _surfaceNormal1) / ([0,0,1] vectorDotProduct _surfaceNormal1); 233 | _surfaceHeight2 = ((_cargoCorner1ASL vectorAdd ( _cargoCenterASL vectorMultiply -1)) vectorDotProduct _surfaceNormal2) / ([0,0,1] vectorDotProduct _surfaceNormal2); 234 | _maxSurfaceHeight = (_newCargoPosition select 2) max _surfaceHeight max _surfaceHeight2; 235 | _newCargoPosition set [2, _maxSurfaceHeight ]; 236 | 237 | _newCargoPosition = _newCargoPosition vectorAdd ( _cargoModelCenterGroundPosition vectorMultiply -1 ); 238 | 239 | _cargo setVectorDir _newCargoDir; 240 | _cargo setVectorUp _surfaceNormal; 241 | _cargo setPosWorld _newCargoPosition; 242 | 243 | _lastCargoHitchPosition = _newCargoHitchPosition; 244 | _maxDistanceToCargo = _vehicleHitchPosition distance _newCargoHitchPosition; 245 | _lastMovedCargoPosition = _cargoPosition; 246 | 247 | _massAdjustedMaxSpeed = _vehicle getVariable ["SA_Max_Tow_Speed",_maxVehicleSpeed]; 248 | if(speed _vehicle > (_massAdjustedMaxSpeed)+0.1) then { 249 | _vehicle setVelocity ((vectorNormalized (velocity _vehicle)) vectorMultiply (_massAdjustedMaxSpeed/3.6)); 250 | }; 251 | 252 | } else { 253 | 254 | if(_lastMovedCargoPosition distance _cargoPosition > 2) then { 255 | _lastCargoHitchPosition = _cargo modelToWorld _cargoHitchModelPos; 256 | _lastCargoVectorDir = vectorDir _cargo; 257 | }; 258 | 259 | }; 260 | 261 | // If vehicle isn't local to the client, switch client running towing simulation 262 | if(!local _vehicle) then { 263 | [_this,"SA_Simulate_Towing",_vehicle] call SA_RemoteExec; 264 | _doExit = true; 265 | }; 266 | 267 | // If the vehicle isn't towing anything, stop the towing simulation 268 | SA_Get_Cargo(_vehicle,_currentCargo); 269 | if(isNull _currentCargo) then { 270 | _doExit = true; 271 | }; 272 | 273 | sleep 0.01; 274 | 275 | }; 276 | }; 277 | 278 | SA_Get_Corner_Points = { 279 | params ["_vehicle"]; 280 | private ["_centerOfMass","_bbr","_p1","_p2","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2"]; 281 | private ["_maxWidth","_widthOffset","_maxLength","_lengthOffset","_widthFactor","_lengthFactor"]; 282 | 283 | // Correct width and length factor for air 284 | _widthFactor = 0.75; 285 | _lengthFactor = 0.75; 286 | if(_vehicle isKindOf "Air") then { 287 | _widthFactor = 0.3; 288 | }; 289 | if(_vehicle isKindOf "Helicopter") then { 290 | _widthFactor = 0.2; 291 | _lengthFactor = 0.45; 292 | }; 293 | 294 | _centerOfMass = getCenterOfMass _vehicle; 295 | _bbr = boundingBoxReal _vehicle; 296 | _p1 = _bbr select 0; 297 | _p2 = _bbr select 1; 298 | _maxWidth = abs ((_p2 select 0) - (_p1 select 0)); 299 | _widthOffset = ((_maxWidth / 2) - abs ( _centerOfMass select 0 )) * _widthFactor; 300 | _maxLength = abs ((_p2 select 1) - (_p1 select 1)); 301 | _lengthOffset = ((_maxLength / 2) - abs (_centerOfMass select 1 )) * _lengthFactor; 302 | _rearCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) - _lengthOffset, _centerOfMass select 2]; 303 | _rearCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) - _lengthOffset, _centerOfMass select 2]; 304 | _frontCorner = [(_centerOfMass select 0) + _widthOffset, (_centerOfMass select 1) + _lengthOffset, _centerOfMass select 2]; 305 | _frontCorner2 = [(_centerOfMass select 0) - _widthOffset, (_centerOfMass select 1) + _lengthOffset, _centerOfMass select 2]; 306 | 307 | if(missionNamespace getVariable ["SA_TOW_DEBUG_ENABLED", false]) then { 308 | if(isNil "sa_tow_debug_arrow_1") then { 309 | sa_tow_debug_arrow_1 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 310 | sa_tow_debug_arrow_2 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 311 | sa_tow_debug_arrow_3 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 312 | sa_tow_debug_arrow_4 = "Sign_Arrow_F" createVehicleLocal [0,0,0]; 313 | }; 314 | sa_tow_debug_arrow_1 setPosASL AGLtoASL (_vehicle modelToWorldVisual _rearCorner); 315 | sa_tow_debug_arrow_2 setPosASL AGLtoASL (_vehicle modelToWorldVisual _rearCorner2); 316 | sa_tow_debug_arrow_3 setPosASL AGLtoASL (_vehicle modelToWorldVisual _frontCorner); 317 | sa_tow_debug_arrow_4 setPosASL AGLtoASL (_vehicle modelToWorldVisual _frontCorner2); 318 | }; 319 | 320 | [_rearCorner,_rearCorner2,_frontCorner,_frontCorner2]; 321 | }; 322 | 323 | SA_Get_Hitch_Points = { 324 | params ["_vehicle"]; 325 | private ["_cornerPoints","_rearCorner","_rearCorner2","_frontCorner","_frontCorner2","_rearHitchPoint"]; 326 | private ["_frontHitchPoint","_sideLeftPoint","_sideRightPoint"]; 327 | _cornerPoints = [_vehicle] call SA_Get_Corner_Points; 328 | _rearCorner = _cornerPoints select 0; 329 | _rearCorner2 = _cornerPoints select 1; 330 | _frontCorner = _cornerPoints select 2; 331 | _frontCorner2 = _cornerPoints select 3; 332 | _rearHitchPoint = ((_rearCorner vectorDiff _rearCorner2) vectorMultiply 0.5) vectorAdd _rearCorner2; 333 | _frontHitchPoint = ((_frontCorner vectorDiff _frontCorner2) vectorMultiply 0.5) vectorAdd _frontCorner2; 334 | //_sideLeftPoint = ((_frontCorner vectorDiff _rearCorner) vectorMultiply 0.5) vectorAdd _frontCorner; 335 | //_sideRightPoint = ((_frontCorner2 vectorDiff _rearCorner2) vectorMultiply 0.5) vectorAdd _frontCorner2; 336 | [_frontHitchPoint,_rearHitchPoint]; 337 | }; 338 | 339 | SA_Attach_Tow_Ropes = { 340 | params ["_cargo","_player"]; 341 | _vehicle = _player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; 342 | if(!isNull _vehicle) then { 343 | if(local _vehicle) then { 344 | private ["_towRopes","_vehicleHitch","_cargoHitch","_objDistance","_ropeLength"]; 345 | _towRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; 346 | if(count _towRopes == 1) then { 347 | 348 | /* 349 | private ["_cargoHitchPoints","_distanceToFrontHitch","_distanceToRearHitch","_isRearCargoHitch"]; 350 | _cargoHitchPoints = [_cargo] call SA_Get_Hitch_Points; 351 | _distanceToFrontHitch = player distance (_cargo modelToWorld (_cargoHitchPoints select 0)); 352 | _distanceToRearHitch = player distance (_cargo modelToWorld (_cargoHitchPoints select 1)); 353 | if( _distanceToFrontHitch < _distanceToRearHitch ) then { 354 | _cargoHitch = _cargoHitchPoints select 0; 355 | _isRearCargoHitch = false; 356 | } else { 357 | _cargoHitch = _cargoHitchPoints select 1; 358 | _isRearCargoHitch = true; 359 | }; 360 | */ 361 | 362 | _cargoHitch = ([_cargo] call SA_Get_Hitch_Points) select 0; 363 | 364 | _vehicleHitch = ([_vehicle] call SA_Get_Hitch_Points) select 1; 365 | _ropeLength = (ropeLength (_towRopes select 0)); 366 | _objDistance = ((_vehicle modelToWorld _vehicleHitch) distance (_cargo modelToWorld _cargoHitch)); 367 | if( _objDistance > _ropeLength ) then { 368 | [["The tow ropes are too short. Move vehicle closer.", false],"SA_Hint",_player] call SA_RemoteExec; 369 | } else { 370 | [_vehicle,_player] call SA_Drop_Tow_Ropes; 371 | _helper = "Land_Can_V2_F" createVehicle position _cargo; 372 | _helper attachTo [_cargo, _cargoHitch]; 373 | _helper setVariable ["SA_Cargo",_cargo,true]; 374 | hideObject _helper; 375 | [[_helper],"SA_Hide_Object_Global"] call SA_RemoteExecServer; 376 | [_helper, [0,0,0], [0,0,-1]] ropeAttachTo (_towRopes select 0); 377 | [_vehicle,_vehicleHitch,_cargo,_cargoHitch,_ropeLength] spawn SA_Simulate_Towing; 378 | }; 379 | }; 380 | } else { 381 | [_this,"SA_Attach_Tow_Ropes",_vehicle,true] call SA_RemoteExec; 382 | }; 383 | }; 384 | }; 385 | 386 | SA_Take_Tow_Ropes = { 387 | params ["_vehicle","_player"]; 388 | if(local _vehicle) then { 389 | diag_log format ["Take Tow Ropes Called %1", _this]; 390 | private ["_existingTowRopes","_hitchPoint","_rope"]; 391 | _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; 392 | if(count _existingTowRopes == 0) then { 393 | _hitchPoint = [_vehicle] call SA_Get_Hitch_Points select 1; 394 | _rope = ropeCreate [_vehicle, _hitchPoint, 10]; 395 | _vehicle setVariable ["SA_Tow_Ropes",[_rope],true]; 396 | _this call SA_Pickup_Tow_Ropes; 397 | }; 398 | } else { 399 | [_this,"SA_Take_Tow_Ropes",_vehicle,true] call SA_RemoteExec; 400 | }; 401 | }; 402 | 403 | SA_Pickup_Tow_Ropes = { 404 | params ["_vehicle","_player"]; 405 | if(local _vehicle) then { 406 | private ["_attachedObj","_helper"]; 407 | { 408 | _attachedObj = _x; 409 | { 410 | _attachedObj ropeDetach _x; 411 | } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); 412 | deleteVehicle _attachedObj; 413 | } forEach ropeAttachedObjects _vehicle; 414 | _helper = "Land_Can_V2_F" createVehicle position _player; 415 | { 416 | [_helper, [0, 0, 0], [0,0,-1]] ropeAttachTo _x; 417 | _helper attachTo [_player, [-0.1, 0.1, 0.15], "Pelvis"]; 418 | } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); 419 | hideObject _helper; 420 | [[_helper],"SA_Hide_Object_Global"] call SA_RemoteExecServer; 421 | _player setVariable ["SA_Tow_Ropes_Vehicle", _vehicle,true]; 422 | _player setVariable ["SA_Tow_Ropes_Pick_Up_Helper", _helper,true]; 423 | } else { 424 | [_this,"SA_Pickup_Tow_Ropes",_vehicle,true] call SA_RemoteExec; 425 | }; 426 | }; 427 | 428 | SA_Drop_Tow_Ropes = { 429 | params ["_vehicle","_player"]; 430 | if(local _vehicle) then { 431 | private ["_helper"]; 432 | _helper = (_player getVariable ["SA_Tow_Ropes_Pick_Up_Helper", objNull]); 433 | if(!isNull _helper) then { 434 | { 435 | _helper ropeDetach _x; 436 | } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); 437 | detach _helper; 438 | deleteVehicle _helper; 439 | }; 440 | _player setVariable ["SA_Tow_Ropes_Vehicle", nil,true]; 441 | _player setVariable ["SA_Tow_Ropes_Pick_Up_Helper", nil,true]; 442 | } else { 443 | [_this,"SA_Drop_Tow_Ropes",_vehicle,true] call SA_RemoteExec; 444 | }; 445 | }; 446 | 447 | SA_Put_Away_Tow_Ropes = { 448 | params ["_vehicle","_player"]; 449 | if(local _vehicle) then { 450 | private ["_existingTowRopes","_hitchPoint","_rope"]; 451 | _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; 452 | if(count _existingTowRopes > 0) then { 453 | _this call SA_Pickup_Tow_Ropes; 454 | _this call SA_Drop_Tow_Ropes; 455 | { 456 | ropeDestroy _x; 457 | } forEach _existingTowRopes; 458 | _vehicle setVariable ["SA_Tow_Ropes",nil,true]; 459 | }; 460 | } else { 461 | [_this,"SA_Put_Away_Tow_Ropes",_vehicle,true] call SA_RemoteExec; 462 | }; 463 | }; 464 | 465 | SA_Attach_Tow_Ropes_Action = { 466 | private ["_vehicle","_cargo","_canBeTowed"]; 467 | _cargo = cursorTarget; 468 | _vehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; 469 | if([_vehicle,_cargo] call SA_Can_Attach_Tow_Ropes) then { 470 | 471 | _canBeTowed = true; 472 | 473 | if!(missionNamespace getVariable ["SA_TOW_LOCKED_VEHICLES_ENABLED",false]) then { 474 | if( locked _cargo > 1 ) then { 475 | ["Cannot attach tow ropes to locked vehicle",false] call SA_Hint; 476 | _canBeTowed = false; 477 | }; 478 | }; 479 | 480 | if!(missionNamespace getVariable ["SA_TOW_IN_EXILE_SAFEZONE_ENABLED",false]) then { 481 | if(!isNil "ExilePlayerInSafezone") then { 482 | if( ExilePlayerInSafezone ) then { 483 | ["Cannot attach tow ropes in safe zone",false] call SA_Hint; 484 | _canBeTowed = false; 485 | }; 486 | }; 487 | }; 488 | 489 | if(_canBeTowed) then { 490 | [_cargo,player] call SA_Attach_Tow_Ropes; 491 | }; 492 | 493 | }; 494 | }; 495 | 496 | SA_Attach_Tow_Ropes_Action_Check = { 497 | private ["_vehicle","_cargo"]; 498 | _vehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; 499 | _cargo = cursorTarget; 500 | [_vehicle,_cargo] call SA_Can_Attach_Tow_Ropes; 501 | }; 502 | 503 | SA_Can_Attach_Tow_Ropes = { 504 | params ["_vehicle","_cargo"]; 505 | if(!isNull _vehicle && !isNull _cargo) then { 506 | [_vehicle,_cargo] call SA_Is_Supported_Cargo && vehicle player == player && player distance _cargo < 10 && _vehicle != _cargo; 507 | } else { 508 | false; 509 | }; 510 | }; 511 | 512 | SA_Take_Tow_Ropes_Action = { 513 | private ["_vehicle","_canTakeTowRopes"]; 514 | _vehicle = cursorTarget; 515 | if([_vehicle] call SA_Can_Take_Tow_Ropes) then { 516 | 517 | _canTakeTowRopes = true; 518 | 519 | if!(missionNamespace getVariable ["SA_TOW_LOCKED_VEHICLES_ENABLED",false]) then { 520 | if( locked _vehicle > 1 ) then { 521 | ["Cannot take tow ropes from locked vehicle",false] call SA_Hint; 522 | _canTakeTowRopes = false; 523 | }; 524 | }; 525 | 526 | if!(missionNamespace getVariable ["SA_TOW_IN_EXILE_SAFEZONE_ENABLED",false]) then { 527 | if(!isNil "ExilePlayerInSafezone") then { 528 | if( ExilePlayerInSafezone ) then { 529 | ["Cannot take tow ropes in safe zone",false] call SA_Hint; 530 | _canTakeTowRopes = false; 531 | }; 532 | }; 533 | }; 534 | 535 | if(_canTakeTowRopes) then { 536 | [_vehicle,player] call SA_Take_Tow_Ropes; 537 | }; 538 | 539 | }; 540 | }; 541 | 542 | SA_Take_Tow_Ropes_Action_Check = { 543 | [cursorTarget] call SA_Can_Take_Tow_Ropes; 544 | }; 545 | 546 | SA_Can_Take_Tow_Ropes = { 547 | params ["_vehicle"]; 548 | if([_vehicle] call SA_Is_Supported_Vehicle) then { 549 | private ["_existingVehicle","_existingTowRopes"]; 550 | _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; 551 | _existingVehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; 552 | vehicle player == player && player distance _vehicle < 10 && (count _existingTowRopes) == 0 && isNull _existingVehicle; 553 | } else { 554 | false; 555 | }; 556 | }; 557 | 558 | SA_Put_Away_Tow_Ropes_Action = { 559 | private ["_vehicle","_canPutAwayTowRopes"]; 560 | _vehicle = cursorTarget; 561 | if([_vehicle] call SA_Can_Put_Away_Tow_Ropes) then { 562 | 563 | _canPutAwayTowRopes = true; 564 | 565 | if!(missionNamespace getVariable ["SA_TOW_LOCKED_VEHICLES_ENABLED",false]) then { 566 | if( locked _vehicle > 1 ) then { 567 | ["Cannot put away tow ropes in locked vehicle",false] call SA_Hint; 568 | _canPutAwayTowRopes = false; 569 | }; 570 | }; 571 | 572 | if!(missionNamespace getVariable ["SA_TOW_IN_EXILE_SAFEZONE_ENABLED",false]) then { 573 | if(!isNil "ExilePlayerInSafezone") then { 574 | if( ExilePlayerInSafezone ) then { 575 | ["Cannot put away tow ropes in safe zone",false] call SA_Hint; 576 | _canPutAwayTowRopes = false; 577 | }; 578 | }; 579 | }; 580 | 581 | if(_canPutAwayTowRopes) then { 582 | [_vehicle,player] call SA_Put_Away_Tow_Ropes; 583 | }; 584 | 585 | }; 586 | }; 587 | 588 | SA_Put_Away_Tow_Ropes_Action_Check = { 589 | [cursorTarget] call SA_Can_Put_Away_Tow_Ropes; 590 | }; 591 | 592 | SA_Can_Put_Away_Tow_Ropes = { 593 | params ["_vehicle"]; 594 | private ["_existingTowRopes"]; 595 | if([_vehicle] call SA_Is_Supported_Vehicle) then { 596 | _existingTowRopes = _vehicle getVariable ["SA_Tow_Ropes",[]]; 597 | vehicle player == player && player distance _vehicle < 10 && (count _existingTowRopes) > 0; 598 | } else { 599 | false; 600 | }; 601 | }; 602 | 603 | 604 | SA_Drop_Tow_Ropes_Action = { 605 | private ["_vehicle"]; 606 | _vehicle = player getVariable ["SA_Tow_Ropes_Vehicle", objNull]; 607 | if([] call SA_Can_Drop_Tow_Ropes) then { 608 | [_vehicle, player] call SA_Drop_Tow_Ropes; 609 | }; 610 | }; 611 | 612 | SA_Drop_Tow_Ropes_Action_Check = { 613 | [] call SA_Can_Drop_Tow_Ropes; 614 | }; 615 | 616 | SA_Can_Drop_Tow_Ropes = { 617 | !isNull (player getVariable ["SA_Tow_Ropes_Vehicle", objNull]) && vehicle player == player; 618 | }; 619 | 620 | 621 | 622 | SA_Pickup_Tow_Ropes_Action = { 623 | private ["_nearbyTowVehicles","_canPickupTowRopes","_vehicle"]; 624 | _nearbyTowVehicles = missionNamespace getVariable ["SA_Nearby_Tow_Vehicles",[]]; 625 | if([] call SA_Can_Pickup_Tow_Ropes) then { 626 | 627 | _vehicle = _nearbyTowVehicles select 0; 628 | _canPickupTowRopes = true; 629 | 630 | if!(missionNamespace getVariable ["SA_TOW_LOCKED_VEHICLES_ENABLED",false]) then { 631 | if( locked _vehicle > 1 ) then { 632 | ["Cannot pick up tow ropes from locked vehicle",false] call SA_Hint; 633 | _canPickupTowRopes = false; 634 | }; 635 | }; 636 | 637 | if!(missionNamespace getVariable ["SA_TOW_IN_EXILE_SAFEZONE_ENABLED",false]) then { 638 | if(!isNil "ExilePlayerInSafezone") then { 639 | if( ExilePlayerInSafezone ) then { 640 | ["Cannot pick up tow ropes in safe zone",false] call SA_Hint; 641 | _canPickupTowRopes = false; 642 | }; 643 | }; 644 | }; 645 | 646 | if(_canPickupTowRopes) then { 647 | [_nearbyTowVehicles select 0, player] call SA_Pickup_Tow_Ropes; 648 | }; 649 | 650 | }; 651 | }; 652 | 653 | SA_Pickup_Tow_Ropes_Action_Check = { 654 | [] call SA_Can_Pickup_Tow_Ropes; 655 | }; 656 | 657 | SA_Can_Pickup_Tow_Ropes = { 658 | isNull (player getVariable ["SA_Tow_Ropes_Vehicle", objNull]) && count (missionNamespace getVariable ["SA_Nearby_Tow_Vehicles",[]]) > 0 && vehicle player == player; 659 | }; 660 | 661 | SA_TOW_SUPPORTED_VEHICLES = [ 662 | "Tank", "Car", "Ship" 663 | ]; 664 | 665 | SA_Is_Supported_Vehicle = { 666 | params ["_vehicle","_isSupported"]; 667 | _isSupported = false; 668 | if(not isNull _vehicle) then { 669 | { 670 | if(_vehicle isKindOf _x) then { 671 | _isSupported = true; 672 | }; 673 | } forEach (missionNamespace getVariable ["SA_TOW_SUPPORTED_VEHICLES_OVERRIDE",SA_TOW_SUPPORTED_VEHICLES]); 674 | }; 675 | _isSupported; 676 | }; 677 | 678 | SA_TOW_RULES = [ 679 | ["Tank","CAN_TOW","Tank"], 680 | ["Tank","CAN_TOW","Car"], 681 | ["Tank","CAN_TOW","Ship"], 682 | ["Tank","CAN_TOW","Air"], 683 | ["Car","CAN_TOW","Tank"], 684 | ["Car","CAN_TOW","Car"], 685 | ["Car","CAN_TOW","Ship"], 686 | ["Car","CAN_TOW","Air"], 687 | ["Ship","CAN_TOW","Ship"] 688 | ]; 689 | 690 | SA_Is_Supported_Cargo = { 691 | params ["_vehicle","_cargo"]; 692 | private ["_canTow"]; 693 | _canTow = false; 694 | if(not isNull _vehicle && not isNull _cargo) then { 695 | { 696 | if(_vehicle isKindOf (_x select 0)) then { 697 | if(_cargo isKindOf (_x select 2)) then { 698 | if( (toUpper (_x select 1)) == "CAN_TOW" ) then { 699 | _canTow = true; 700 | } else { 701 | _canTow = false; 702 | }; 703 | }; 704 | }; 705 | } forEach (missionNamespace getVariable ["SA_TOW_RULES_OVERRIDE",SA_TOW_RULES]); 706 | }; 707 | _canTow; 708 | }; 709 | 710 | SA_Hint = { 711 | params ["_msg",["_isSuccess",true]]; 712 | if(!isNil "ExileClient_gui_notification_event_addNotification") then { 713 | if(_isSuccess) then { 714 | ["Success", [_msg]] call ExileClient_gui_notification_event_addNotification; 715 | } else { 716 | ["Whoops", [_msg]] call ExileClient_gui_notification_event_addNotification; 717 | }; 718 | } else { 719 | hint _msg; 720 | }; 721 | }; 722 | 723 | SA_Hide_Object_Global = { 724 | params ["_obj"]; 725 | if( _obj isKindOf "Land_Can_V2_F" ) then { 726 | hideObjectGlobal _obj; 727 | }; 728 | }; 729 | 730 | SA_Set_Owner = { 731 | params ["_obj","_client"]; 732 | _obj setOwner _client; 733 | }; 734 | 735 | SA_Add_Player_Tow_Actions = { 736 | 737 | player addAction ["Deploy Tow Ropes", { 738 | [] call SA_Take_Tow_Ropes_Action; 739 | }, nil, 0, false, true, "", "call SA_Take_Tow_Ropes_Action_Check"]; 740 | 741 | player addAction ["Put Away Tow Ropes", { 742 | [] call SA_Put_Away_Tow_Ropes_Action; 743 | }, nil, 0, false, true, "", "call SA_Put_Away_Tow_Ropes_Action_Check"]; 744 | 745 | player addAction ["Attach To Tow Ropes", { 746 | [] call SA_Attach_Tow_Ropes_Action; 747 | }, nil, 0, false, true, "", "call SA_Attach_Tow_Ropes_Action_Check"]; 748 | 749 | player addAction ["Drop Tow Ropes", { 750 | [] call SA_Drop_Tow_Ropes_Action; 751 | }, nil, 0, false, true, "", "call SA_Drop_Tow_Ropes_Action_Check"]; 752 | 753 | player addAction ["Pickup Tow Ropes", { 754 | [] call SA_Pickup_Tow_Ropes_Action; 755 | }, nil, 0, false, true, "", "call SA_Pickup_Tow_Ropes_Action_Check"]; 756 | 757 | player addEventHandler ["Respawn", { 758 | player setVariable ["SA_Tow_Actions_Loaded",false]; 759 | }]; 760 | 761 | }; 762 | 763 | SA_Find_Nearby_Tow_Vehicles = { 764 | private ["_nearVehicles","_nearVehiclesWithTowRopes","_vehicle","_ends","_end1","_end2"]; 765 | _nearVehicles = []; 766 | { 767 | _nearVehicles append (position player nearObjects [_x, 30]); 768 | } forEach (missionNamespace getVariable ["SA_TOW_SUPPORTED_VEHICLES_OVERRIDE",SA_TOW_SUPPORTED_VEHICLES]); 769 | _nearVehiclesWithTowRopes = []; 770 | { 771 | _vehicle = _x; 772 | { 773 | _ends = ropeEndPosition _x; 774 | if(count _ends == 2) then { 775 | _end1 = _ends select 0; 776 | _end2 = _ends select 1; 777 | if(((position player) distance _end1) < 5 || ((position player) distance _end2) < 5 ) then { 778 | _nearVehiclesWithTowRopes pushBack _vehicle; 779 | } 780 | }; 781 | } forEach (_vehicle getVariable ["SA_Tow_Ropes",[]]); 782 | } forEach _nearVehicles; 783 | _nearVehiclesWithTowRopes; 784 | }; 785 | 786 | if(!isDedicated) then { 787 | [] spawn { 788 | while {true} do { 789 | if(!isNull player && isPlayer player) then { 790 | if!( player getVariable ["SA_Tow_Actions_Loaded",false] ) then { 791 | [] call SA_Add_Player_Tow_Actions; 792 | player setVariable ["SA_Tow_Actions_Loaded",true]; 793 | }; 794 | }; 795 | missionNamespace setVariable ["SA_Nearby_Tow_Vehicles", (call SA_Find_Nearby_Tow_Vehicles)]; 796 | sleep 2; 797 | }; 798 | }; 799 | }; 800 | 801 | SA_RemoteExec = { 802 | params ["_params","_functionName","_target",["_isCall",false]]; 803 | if(!isNil "ExileClient_system_network_send") then { 804 | ["AdvancedTowingRemoteExecClient",[_params,_functionName,_target,_isCall]] call ExileClient_system_network_send; 805 | } else { 806 | if(_isCall) then { 807 | _params remoteExecCall [_functionName, _target]; 808 | } else { 809 | _params remoteExec [_functionName, _target]; 810 | }; 811 | }; 812 | }; 813 | 814 | SA_RemoteExecServer = { 815 | params ["_params","_functionName",["_isCall",false]]; 816 | if(!isNil "ExileClient_system_network_send") then { 817 | ["AdvancedTowingRemoteExecServer",[_params,_functionName,_isCall]] call ExileClient_system_network_send; 818 | } else { 819 | if(_isCall) then { 820 | _params remoteExecCall [_functionName, 2]; 821 | } else { 822 | _params remoteExec [_functionName, 2]; 823 | }; 824 | }; 825 | }; 826 | 827 | if(isServer) then { 828 | 829 | // Adds support for exile network calls (Only used when running exile) // 830 | 831 | SA_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS = ["SA_Set_Owner","SA_Hide_Object_Global"]; 832 | 833 | ExileServer_AdvancedTowing_network_AdvancedTowingRemoteExecServer = { 834 | params ["_sessionId", "_messageParameters",["_isCall",false]]; 835 | _messageParameters params ["_params","_functionName"]; 836 | if(_functionName in SA_SUPPORTED_REMOTEEXECSERVER_FUNCTIONS) then { 837 | if(_isCall) then { 838 | _params call (missionNamespace getVariable [_functionName,{}]); 839 | } else { 840 | _params spawn (missionNamespace getVariable [_functionName,{}]); 841 | }; 842 | }; 843 | }; 844 | 845 | SA_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS = ["SA_Simulate_Towing","SA_Attach_Tow_Ropes","SA_Take_Tow_Ropes","SA_Put_Away_Tow_Ropes","SA_Pickup_Tow_Ropes","SA_Drop_Tow_Ropes","SA_Hint"]; 846 | 847 | ExileServer_AdvancedTowing_network_AdvancedTowingRemoteExecClient = { 848 | params ["_sessionId", "_messageParameters"]; 849 | _messageParameters params ["_params","_functionName","_target",["_isCall",false]]; 850 | if(_functionName in SA_SUPPORTED_REMOTEEXECCLIENT_FUNCTIONS) then { 851 | if(_isCall) then { 852 | _params remoteExecCall [_functionName, _target]; 853 | } else { 854 | _params remoteExec [_functionName, _target]; 855 | }; 856 | }; 857 | }; 858 | 859 | // Install Advanced Towing on all clients (plus JIP) // 860 | 861 | publicVariable "SA_Advanced_Towing_Install"; 862 | remoteExecCall ["SA_Advanced_Towing_Install", -2,true]; 863 | 864 | }; 865 | 866 | diag_log "Advanced Towing Loaded"; 867 | 868 | }; 869 | 870 | if(isServer) then { 871 | [] call SA_Advanced_Towing_Install; 872 | }; 873 | -------------------------------------------------------------------------------- /keys/AdvancedTowing.bikey: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/keys/AdvancedTowing.bikey -------------------------------------------------------------------------------- /logo.paa: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/logo.paa -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/logo.png -------------------------------------------------------------------------------- /logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/logo.psd -------------------------------------------------------------------------------- /mod.cpp: -------------------------------------------------------------------------------- 1 | name = "Advanced Towing"; 2 | picture = "logo.paa"; 3 | description = "Advanced Towing"; 4 | logo = "logo.paa"; 5 | logoOver = "logo.paa"; 6 | tooltip = "Advanced Towing"; 7 | tooltipOwned = "Advanced Towing Owned"; 8 | overview = "Advanced Towing"; 9 | author = "[SA] Duda"; 10 | overviewPicture = "logo.paa"; 11 | overviewText = "Advanced Towing"; 12 | overviewFootnote = ""; -------------------------------------------------------------------------------- /steamLogo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/steamLogo.jpg -------------------------------------------------------------------------------- /steamLogo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sethduda/AdvancedTowing/5f6c52c72a110d6c97d84324d0dead3569c66057/steamLogo.psd --------------------------------------------------------------------------------